Skip to content

Commit

Permalink
fixed asset path when bundled as Mac os x App
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko van der Heijden authored and Heiko van der Heijden committed Dec 23, 2015
1 parent 2cd5b66 commit ecce8ff
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <iostream>

Application::Application(unsigned short width, unsigned short height){
this->path = path;
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
Expand Down Expand Up @@ -65,6 +66,8 @@ void Application::drawLoop(){
this->currentScene->draw(aspect);
}



void Application::keyDown(unsigned short keycode){
//just give the keys back without doing anything
this->currentScene->keyDown(keycode);
Expand Down
4 changes: 4 additions & 0 deletions Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#pragma once
#include "Scene.hpp"
#include <memory>
#include <string>
/*! This class Handles the different loops and scenes
* @author Heiko van der Heijden
*/
Expand All @@ -37,6 +38,7 @@ class Application{
* The current scene wrapped in a pointer
*/
std::unique_ptr<Scene> currentScene;
std::string path;
/*!
* The amount of time it took last time to update all gameobjects
*/
Expand All @@ -52,6 +54,8 @@ class Application{
*/
Application(unsigned short width,unsigned short height);

std::string getAppPath();

void quitApplication();

void loadScene(Scene* scene);
Expand Down
6 changes: 5 additions & 1 deletion AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include "PrimitiveCube.hpp"
#include "PrimitiveQuad.hpp"

AssetManager::AssetManager(){
AssetManager::AssetManager(std::string path){
this->uniqueNumber = 1;
this->path = path;
}

int AssetManager::loadCube(){
Expand Down Expand Up @@ -44,6 +45,7 @@ void AssetManager::renderPrimitive(int reference){
}

int AssetManager::loadTexture(std::string path){
path = this->path + "/" + path;
for(auto it : this->textures){
if(it->getPath() == path){
return it->getUniqueNumber();
Expand All @@ -57,6 +59,8 @@ int AssetManager::loadTexture(std::string path){
}

int AssetManager::loadProgram(std::string vertexShader, std::string fragmentShader){
vertexShader = path + "/" + vertexShader;
fragmentShader = path + "/" + fragmentShader;

//Check if program already exists
for(auto it : this->programs){
Expand Down
3 changes: 2 additions & 1 deletion AssetManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
class AssetManager{
private:
std::string path;

/*! All the shaders that are currently in use
*/
Expand Down Expand Up @@ -74,7 +75,7 @@ class AssetManager{
}

public:
AssetManager();
AssetManager(std::string path);

/*! Loads an default cube into memory
* @return an reference that can be used to use the cube
Expand Down
4 changes: 4 additions & 0 deletions MacApp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ -(void) dealloc{
[app stopMacApp];
}

std::string Application::getAppPath(){
return [[[NSBundle mainBundle]resourcePath]UTF8String];
}

int main(){

NSRect mainDisplayRect = [[NSScreen mainScreen] frame];
Expand Down
2 changes: 1 addition & 1 deletion MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "SnakeScene.hpp"
#include "KeyCodes.hpp"
MainMenu::MainMenu(Application* app){
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager());
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager(app->getAppPath()));
this->addGameObject(std::shared_ptr<Background>(new Background(this->assetManager)));
this->addGameObject(std::shared_ptr<SnakeBody>(new SnakeBody(this->assetManager, 3, Vector3f(0,0,-2))));
this->application = app;
Expand Down
2 changes: 1 addition & 1 deletion SnakeHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SnakeHead::SnakeHead(std::shared_ptr<AssetManager> assetManager, Vector3f startP
this->timer = std::chrono::steady_clock::now();
this->direction = Direction::Left;
this->scale = Vector3f(0.1f,0.1f,0.1f);
this->body = std::shared_ptr<SnakeBody>(new SnakeBody(this->assetManager, 3, Vector3f( position.x + 0.15f, position.y, position.z)));
this->body = std::shared_ptr<SnakeBody>(new SnakeBody(this->assetManager, 10, Vector3f( position.x + 0.15f, position.y, position.z)));
}

void SnakeHead::update(float tpf){
Expand Down
2 changes: 1 addition & 1 deletion SnakeScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

SnakeScene::SnakeScene(Application* application){
this->application = application;
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager());
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager(application->getAppPath()));
this->addGameObject(std::shared_ptr<Background>(new Background(this->assetManager)));
this->addGameObject(std::shared_ptr<SnakeHead>(new SnakeHead(this->assetManager, Vector3f(-1,0,-2))));
}
Expand Down

0 comments on commit ecce8ff

Please sign in to comment.