Skip to content

Commit ecce8ff

Browse files
Heiko van der HeijdenHeiko van der Heijden
authored andcommitted
fixed asset path when bundled as Mac os x App
1 parent 2cd5b66 commit ecce8ff

8 files changed

Lines changed: 21 additions & 5 deletions

File tree

Application.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <iostream>
77

88
Application::Application(unsigned short width, unsigned short height){
9+
this->path = path;
910
glEnable(GL_CULL_FACE);
1011
glEnable(GL_DEPTH_TEST);
1112
glDepthFunc(GL_LEQUAL);
@@ -65,6 +66,8 @@ void Application::drawLoop(){
6566
this->currentScene->draw(aspect);
6667
}
6768

69+
70+
6871
void Application::keyDown(unsigned short keycode){
6972
//just give the keys back without doing anything
7073
this->currentScene->keyDown(keycode);

Application.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#pragma once
2929
#include "Scene.hpp"
3030
#include <memory>
31+
#include <string>
3132
/*! This class Handles the different loops and scenes
3233
* @author Heiko van der Heijden
3334
*/
@@ -37,6 +38,7 @@ class Application{
3738
* The current scene wrapped in a pointer
3839
*/
3940
std::unique_ptr<Scene> currentScene;
41+
std::string path;
4042
/*!
4143
* The amount of time it took last time to update all gameobjects
4244
*/
@@ -52,6 +54,8 @@ class Application{
5254
*/
5355
Application(unsigned short width,unsigned short height);
5456

57+
std::string getAppPath();
58+
5559
void quitApplication();
5660

5761
void loadScene(Scene* scene);

AssetManager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include "PrimitiveCube.hpp"
55
#include "PrimitiveQuad.hpp"
66

7-
AssetManager::AssetManager(){
7+
AssetManager::AssetManager(std::string path){
88
this->uniqueNumber = 1;
9+
this->path = path;
910
}
1011

1112
int AssetManager::loadCube(){
@@ -44,6 +45,7 @@ void AssetManager::renderPrimitive(int reference){
4445
}
4546

4647
int AssetManager::loadTexture(std::string path){
48+
path = this->path + "/" + path;
4749
for(auto it : this->textures){
4850
if(it->getPath() == path){
4951
return it->getUniqueNumber();
@@ -57,6 +59,8 @@ int AssetManager::loadTexture(std::string path){
5759
}
5860

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

6165
//Check if program already exists
6266
for(auto it : this->programs){

AssetManager.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
class AssetManager{
4040
private:
41+
std::string path;
4142

4243
/*! All the shaders that are currently in use
4344
*/
@@ -74,7 +75,7 @@ class AssetManager{
7475
}
7576

7677
public:
77-
AssetManager();
78+
AssetManager(std::string path);
7879

7980
/*! Loads an default cube into memory
8081
* @return an reference that can be used to use the cube

MacApp.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ -(void) dealloc{
147147
[app stopMacApp];
148148
}
149149

150+
std::string Application::getAppPath(){
151+
return [[[NSBundle mainBundle]resourcePath]UTF8String];
152+
}
153+
150154
int main(){
151155

152156
NSRect mainDisplayRect = [[NSScreen mainScreen] frame];

MainMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "SnakeScene.hpp"
77
#include "KeyCodes.hpp"
88
MainMenu::MainMenu(Application* app){
9-
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager());
9+
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager(app->getAppPath()));
1010
this->addGameObject(std::shared_ptr<Background>(new Background(this->assetManager)));
1111
this->addGameObject(std::shared_ptr<SnakeBody>(new SnakeBody(this->assetManager, 3, Vector3f(0,0,-2))));
1212
this->application = app;

SnakeHead.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SnakeHead::SnakeHead(std::shared_ptr<AssetManager> assetManager, Vector3f startP
99
this->timer = std::chrono::steady_clock::now();
1010
this->direction = Direction::Left;
1111
this->scale = Vector3f(0.1f,0.1f,0.1f);
12-
this->body = std::shared_ptr<SnakeBody>(new SnakeBody(this->assetManager, 3, Vector3f( position.x + 0.15f, position.y, position.z)));
12+
this->body = std::shared_ptr<SnakeBody>(new SnakeBody(this->assetManager, 10, Vector3f( position.x + 0.15f, position.y, position.z)));
1313
}
1414

1515
void SnakeHead::update(float tpf){

SnakeScene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
SnakeScene::SnakeScene(Application* application){
1111
this->application = application;
12-
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager());
12+
this->assetManager = std::shared_ptr<AssetManager>(new AssetManager(application->getAppPath()));
1313
this->addGameObject(std::shared_ptr<Background>(new Background(this->assetManager)));
1414
this->addGameObject(std::shared_ptr<SnakeHead>(new SnakeHead(this->assetManager, Vector3f(-1,0,-2))));
1515
}

0 commit comments

Comments
 (0)