From f449eda43f6cbd3f90508029e94741f4c2de1f9b Mon Sep 17 00:00:00 2001 From: Alan Youngblood Date: Sat, 12 Aug 2023 13:52:04 -0400 Subject: [PATCH] Some paths to assets fixed with Boost::FS --- .DS_Store | Bin 8196 -> 8196 bytes src/ecs/SpriteComponent.h | 13 ++++++++-- src/ecs/TileMapComponent.h | 40 +++++++------------------------ src/game/Game.cpp | 12 ++++++---- src/game/Game.hpp | 4 ++-- src/game/Main.cpp | 48 ++++++++++++++++++++----------------- 6 files changed, 55 insertions(+), 62 deletions(-) diff --git a/.DS_Store b/.DS_Store index aaa2362907a2ca30f87c070236ca503703f9452e..c1f75e9b49ce2158d38487d466cba7bb29854385 100644 GIT binary patch delta 865 zcma)4&ubGw6n@hmX44;Ln{3(=L<^zCL(q+oROq2;5)4H!p&M#LTf=U4k}lnyS#~Fh zwUiv%n+n1T{sA7mD!J*oM^6Qzh~mkU2caN6y2)m#^&pMrhMh`#+1F&;Cb+@CmZFA7=y<+N`%|!7N8X6uMy%OL8+&H%_?a;Qw zWY)B^vbEVel_}K~pUcX+hTBzM$Wg*%jbN)U&{XV}Y(3P7O50i5B&yxlN?w8sa=|Je z+b`@V?<}Shb4f8J9wg@WQ%Nx~ms(6890a*&{PxmXbyqhCebyTW03i=ya)3TOcZS3B z9j(?H%z|F}vwZbu3670VOkNG~Q=xDu5)q=)GqclGKBCCA-GUykb3%IZzL*|0QK zGUb{^8XF8hW|H;|FtM$4Xd$bYBUix eBsf2WYfe5|>3)pfL*2mauMwvb&i}V2hkgTz`sqIa delta 655 zcmZp1XmOa}jIU^hRb_GBIbsn`-h1_lNe20ey!hD?T%+ p2^LfhjIx_IiG?ywEcmjSUE&*yS}KDpFrbTok(Gg}kbILr0syV|t1tin diff --git a/src/ecs/SpriteComponent.h b/src/ecs/SpriteComponent.h index 5d2e288..ecba3e3 100644 --- a/src/ecs/SpriteComponent.h +++ b/src/ecs/SpriteComponent.h @@ -66,10 +66,19 @@ public: spriteType = sType; if(sType == spriteAnimation) { - std::ifstream fin(json); + /*boost::filesystem::path p{argv[0]}; + p = absolute(p).parent_path(); + std::string configPath = "src/config/config.json"; + std::string bps = p.string(); + size_t charPos = bps.find("build"); + bps.erase(charPos,bps.length()); + std::string configurationPath = bps + json;*/ + std::cout << "Project Path: " << Game::projPath << std::endl; + std::string fullPath = Game::projPath + json; + std::ifstream fin(fullPath); if(fin.fail()){ - std::cerr<<"ERROR opening json file"<getStatus() == tson::ParseStatus::OK) { - printf("Map File Loaded!! \n"); + // printf("Map File Loaded!! \n"); tson::Tileset *tileset = map->getTileset(tsName); - std::cout << "tsName: " << tsName << std::endl; + //std::cout << "tsName: " << tsName << std::endl; std::string fullPath = tileset->getImage(); - std::cout << "fullPath: " << fullPath << std::endl; + //std::cout << "fullPath: " << fullPath << std::endl; //size_t charPos = fullPath.find("assets"); //fullPath.erase(0,charPos); std::string prependPath = std::string("assets/maps/"); std::string localPath = prependPath + fullPath; std::string wholePath = "/Users/ayoungblood/Projects/KaijuSaveEarth/" + localPath; - std::cout << "fullPath: " << wholePath << std::endl; + //std::cout << "fullPath: " << wholePath << std::endl; tson::Layer *tileLayer = map->getLayer(tileLayerName); //This is a Layer std::string texName = tileLayer->getName(); Game::assets->AddTexture(texName, wholePath.c_str()); setTex(texName); globalScale = gScale; - printf("Added texture for tilemap.\n"); + //printf("Added texture for tilemap.\n"); tson::Layer *collisionLayer = map->getLayer(collisionLayerName); tilesWide = map->getSize().x; @@ -95,7 +95,7 @@ public: tileSet[element] = srcRect; } } - printf("Tile Set Setup Completed.\n"); + //printf("Tile Set Setup Completed.\n"); if(tileLayer->getType() == tson::LayerType::TileLayer) { destRects.resize(tilesWide*tilesHigh); @@ -117,31 +117,7 @@ public: destRect.w = destRect.h = tileWidth * gScale; } - printf("Tilemap setup completed\n"); -// tson::Layer *myLayer = map->getLayer("Tile Layer 1"); -// for (int r = 0;rgetSize().y;r++){ -// // Next cycle through each column or tile in that row: -// for (int c = 0;cgetSize().x;c++){ -// int i = r*map->getSize().x+c; -// int elem = c+r*map->getSize().x; -// tson::Tile *myTile = myLayer->getTileData(c,r); -// int tid = myTile->getId()-1; -// //std::cout << myLayer->getTileData(1,1)->getId() << std::endl; -// // TextureManager::Draw(texture, tileSet[tid], destRects[elem], SDL_FLIP_NONE); -// //std::cout << "c,r: " << c << ", " << r << std::endl; -// if(!tid){ -// //printf("got nullptr\n"); -// // printf("found valid tid\n"); -// } else { -// //std::cout << "tid: " << tid << std::endl; -// } -// //std::cout << " elem: " << elem << std::endl; -// //std::cout << "i" << i << std::endl; -// } -// } - // tson::Tile *testTile = myLayer->getTileData(0,4); - // int myTid = testTile->getId()-1; - printf("Completed tilemap init\n"); + //printf("Tilemap setup completed\n"); //std::cout << "destRects.size " << destRects.size() << std::endl; } else { // printf("Failed to load Tileson map\n"); diff --git a/src/game/Game.cpp b/src/game/Game.cpp index ff9e4de..adb0cd3 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -77,6 +77,8 @@ bool Game::gravityOnPlayer = true; bool Game::playerIsGrounded = false; bool Game::playerIsJumping = false; +std::string Game::projPath = ""; + int gScale = 0; int last_time; int current_time; @@ -97,9 +99,9 @@ std::string Game::BoolToString(bool b) { return myString; } -Game::Game() { +Game::Game(std::string projectPath) { // TODO Auto-generated constructor stub - + Game::projPath = projectPath; } Game::~Game() { @@ -142,7 +144,9 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError()); } - assets->AddTexture("player", "assets/textures/actors/kaijuturtle.png"); + std::string kaijuTex = Game::projPath + "assets/textures/actors/kaijuturtle.png"; + + assets->AddTexture("player", kaijuTex.c_str()); assets->AddTexture("font", "assets/textures/ui/ui-font-lorez5.png"); assets->AddTexture("textBox", "assets/textures/ui/ui-element-bubble.png"); assets->AddTexture("collider","assets/textures/ColTex.png"); @@ -192,7 +196,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g playerPosition = Vector2D().Zero(); pVel = Vector2D().Zero(); - printf("Init Completed\n"); + // printf("Init Completed\n"); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError()); isRunning = false; diff --git a/src/game/Game.hpp b/src/game/Game.hpp index 412d0d9..7bf3a59 100644 --- a/src/game/Game.hpp +++ b/src/game/Game.hpp @@ -25,7 +25,7 @@ class AssetManager; class Game { public: - Game(); + Game(std::string projectPath); virtual ~Game(); void init(const char* title, int width, int height, bool fullscreen, int globalScale); void handleEvents(); @@ -42,7 +42,7 @@ public: // static std::vector colliders; // static tmxparser::TmxMap map; // gameScene; - + static std::string projPath; static bool debugMenu; static bool isRunning; static bool debugCollisionBoxes; diff --git a/src/game/Main.cpp b/src/game/Main.cpp index 5fabc83..cfcff07 100644 --- a/src/game/Main.cpp +++ b/src/game/Main.cpp @@ -11,7 +11,6 @@ #include #include #include -//#include #include Game *game = nullptr; @@ -27,41 +26,46 @@ int main(int argc, const char * argv[]) boost::filesystem::path p{argv[0]}; p = absolute(p).parent_path(); - std::cout << "boost path: " << p << std::endl; +// std::cout << "boost path: " << p << std::endl; // ============================= // Load cJSON config.json file // ============================= // Starting with Error Checking - //std::string configPath = "src/config/config.json"; - std::string configPath = "/Users/ayoungblood/Projects/KaijuSaveEarth/src/config/config.json"; + std::string configPath = "src/config/config.json"; + std::string bps = p.string(); + size_t charPos = bps.find("build"); + bps.erase(charPos,bps.length()); +// std::cout << "Trimmed Boost Path: " << bps << std::endl; + std::string configurationPath = bps + configPath; + //std::string configPath = "/Users/ayoungblood/Projects/KaijuSaveEarth/src/config/config.json"; // /Users/ayoungblood/Projects/KaijuSaveEarth // std::string fullPath = p.c_str() + "/" + configPath; - std::ifstream fin(configPath); + std::ifstream fin(configurationPath); // std::cout << "Attempting to load: " << configPath << std::endl; // std::cout << "Current working Dir: " << std::filesystem::current_path() << std::endl; if(!fin.is_open()){ std::cerr<<"ERROR: config.json not found or opened"<valueint; -// int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint; -// int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint; -// int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint; - int windowWidth = 64; + cJSON * windowSize = cJSON_GetObjectItem(myJSON, "WindowSize"); + int windowWidth = cJSON_GetObjectItem(windowSize, "w")->valueint; + int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint; + int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint; + int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint; +/* int windowWidth = 64; int windowHeight = 64; int windowFS = 0; - int globalScale = 10; + int globalScale = 10;*/ bool isWindowFS; - std::string windowName = "KaijuSaveEarth"; + //std::string windowName = "KaijuSaveEarth"; if (windowFS==0) { isWindowFS = false; @@ -71,11 +75,11 @@ int main(int argc, const char * argv[]) } windowWidth = windowWidth*globalScale; windowHeight = windowHeight*globalScale; - game = new Game(); -// game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale); - game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale); -// cJSON memory management -// cJSON_Delete(myJSON); + game = new Game(bps); + game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale); +// game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale); +// cJSON memory management + cJSON_Delete(myJSON); while (game->running()) { @@ -94,7 +98,7 @@ int main(int argc, const char * argv[]) } game->clean(); - // } + } if(fin.fail()){ std::cout<<"config.json load failed"<