From 1cbc8cbbc0b05449d976ddb0207f83369e525bff Mon Sep 17 00:00:00 2001 From: Alan Youngblood Date: Sat, 12 Aug 2023 14:44:08 -0400 Subject: [PATCH] All asset paths corrected to use Boost::FS --- .DS_Store | Bin 8196 -> 10244 bytes .gitignore | 3 +++ src/ecs/SpriteComponent.h | 13 ++++++++-- src/ecs/TileMapComponent.h | 40 +++++++------------------------ src/game/Game.cpp | 28 +++++++++++++--------- src/game/Game.hpp | 4 ++-- src/game/Main.cpp | 48 ++++++++++++++++++++----------------- 7 files changed, 67 insertions(+), 69 deletions(-) diff --git a/.DS_Store b/.DS_Store index aaa2362907a2ca30f87c070236ca503703f9452e..ce647ae49dc0144c9419d6ed7b8a1f37545f5e9a 100644 GIT binary patch delta 936 zcma)5%}*0S6o1o#Z27QDy9FdfYZ?*{ShpddhC@rK5@I5SZ4kmov)diYhTWOX?v{## z^Z+;XK-R>>s|T+VPR66*FCZ}?M&rqo2NMr^bhg_K;=y>B{C@L3esA8Jnf=^;aR2~N zzNTgXl8ka}dB}Gk%6*6F>nMFxd>2J&x0@ea{qdT4+8_;8(7-Whp`hqgVK(lpbo%Av z)XC&Uzxq$Vxsj17)G%2NgeJ}7Jzhn^^n6jQ*^bo|dI&NYfZem+I}N37o2_bZ6;s!2 zM-)GxP`IuAQU}+;b#bfG2CYku?9}YMY%P1c5~aEla9LT1w9X1`5d$o>Fnz6xg6ztqp@f_E+qQ;2l~o< zT#+lARm(fx6xFGf*K2sWYH6xu$`y@N7ajcAk+dhc%*Xx;oyY3hxv8{mHdv5wZfWXG zTNsn3;OzRkjh)3m_|l5aW;x?vV}`6#R$z zb{HmL8j66yfdhB}uiy=wz$tu!ukZ^Y)QRFKfv%!!NJJTw8b?__Hx%5{;Kd>+=MKj9 z`rAQ)8hhzFs9TanbV{l$4jsRY&4rNQeiMd{3yJrkBeT)o8}=2FT@3Ge-{(mF8Fr&X db3(}fRL#~{J<$tv&7o)RS}gk?CEP+H`x|WL?5F?$ delta 285 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8FDWo2aMAsJ$^@H$S8HWF7&j*b+gY3=4xE zLpnnyLrHGFi%U{YeiBI6*7z@{!<>&gqROY>l`qIJ3{K9^Edc6aV6uC#xmh5EaWbcn z)?_we@yVw}N;gM|`Y|!`OgetStatus() == 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..3f4dc24 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,15 +144,19 @@ 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"); - 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"); + std::string kaijuTex = Game::projPath + "assets/textures/actors/kaijuturtle.png"; + std::string fontTex = Game::projPath + "assets/textures/ui/ui-font-lorez5.png"; + std::string textBoxTex = Game::projPath + "assets/textures/ui/ui-element-bubble.png"; + std::string musicFile = Game::projPath + "assets/audio/music/sillypuppy.ogg"; + std::string sfxFile = Game::projPath + "assets/audio/sfx/bwoop.wav"; + + assets->AddTexture("player", kaijuTex.c_str()); + assets->AddTexture("font", fontTex.c_str()); + assets->AddTexture("textBox", textBoxTex.c_str()); - assets->AddMusicTrack("simonZ","assets/audio/music/sillypuppy.ogg"); - assets->AddMusicTrack("simonZ","assets/audio/music/victory.ogg"); + assets->AddMusicTrack("simonZ",musicFile.c_str()); - assets->AddSoundClip("bwoop","assets/audio/sfx/bwoop.wav"); + assets->AddSoundClip("bwoop",sfxFile.c_str()); std::string myText = "U to Start"; @@ -192,7 +198,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; @@ -241,7 +247,7 @@ void Game::update() if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME) { // std::cout << "Play Music Now" << std::endl; -// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); + Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1); } if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME) { 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"<