From 6de979d7948c9cc053ca904f1d6839193a3c6e85 Mon Sep 17 00:00:00 2001 From: freezarite Date: Tue, 5 Nov 2024 12:45:26 +0100 Subject: [PATCH 1/3] so much happened idk what to write here :c --- .gitmodules | 3 +++ CMakeLists.txt | 2 ++ docs/doxygen-awesome-css | 1 + extern/magic_enum | 1 + include/AssetManager.h | 2 +- include/Map.h | 5 +++-- include/TileComponent.h | 22 +++++++++++++++++----- src/AssetManager.cpp | 4 ++-- src/Map.cpp | 8 +++++--- src/TileComponent.cpp | 8 ++++---- 10 files changed, 39 insertions(+), 17 deletions(-) create mode 160000 docs/doxygen-awesome-css create mode 160000 extern/magic_enum diff --git a/.gitmodules b/.gitmodules index bfa520c..3ae9513 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ path = extern/SDL_ttf url = https://github.com/libsdl-org/SDL_ttf.git branch = release-2.22.x +[submodule "extern/magic_enum"] + path = extern/magic_enum + url = https://github.com/Neargye/magic_enum.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5149005..24a3f77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ add_subdirectory(extern/SDL EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL) +add_subdirectory(extern/magic_enum EXCLUDE_FROM_ALL) file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp) add_library(${PROJECT_NAME} ${SOURCES}) @@ -33,6 +34,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL fu SDL2_image::SDL2_image-static SDL2_mixer::SDL2_mixer-static SDL2_ttf::SDL2_ttf-static + magic_enum::magic_enum ) if(CMAKE_BUILD_TYPE MATCHES "Debug") diff --git a/docs/doxygen-awesome-css b/docs/doxygen-awesome-css new file mode 160000 index 0000000..df88fe4 --- /dev/null +++ b/docs/doxygen-awesome-css @@ -0,0 +1 @@ +Subproject commit df88fe4fdd97714fadfd3ef17de0b4401f804052 diff --git a/extern/magic_enum b/extern/magic_enum new file mode 160000 index 0000000..a72a053 --- /dev/null +++ b/extern/magic_enum @@ -0,0 +1 @@ +Subproject commit a72a0536c716fdef4f029fb43e1fd7e7b3d9ac9b diff --git a/include/AssetManager.h b/include/AssetManager.h index ee4a447..ebec1bd 100644 --- a/include/AssetManager.h +++ b/include/AssetManager.h @@ -25,7 +25,7 @@ public: ~AssetManager(); void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, TexturesEnum textureEnum, Entity* owner); - void createPowerup(Vector2D pos, std::function pickupFunc, std::string texturePath); + void createPowerup(Vector2D pos, std::function pickupFunc, TexturesEnum texture); Vector2D calculateSpawnPosition(); PowerupType calculateType(); diff --git a/include/Map.h b/include/Map.h index 4c1bc3b..c18a121 100644 --- a/include/Map.h +++ b/include/Map.h @@ -2,6 +2,7 @@ #include #include +#include class GameInternal; class Map @@ -21,6 +22,6 @@ public: * \return Boolean for success * */ - static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map>* textureDict /* backreference */); - static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map>* textureDict); + static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map>* textureDict /* backreference */); + static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map>* textureDict); }; diff --git a/include/TileComponent.h b/include/TileComponent.h index 8844daa..7bb005e 100644 --- a/include/TileComponent.h +++ b/include/TileComponent.h @@ -3,8 +3,10 @@ #include #include #include +#include #include "Component.h" +#include "TextureEnumBase.h" class SpriteComponent; class TransformComponent; @@ -17,17 +19,27 @@ public: SDL_Rect tileRect; int tileID; - const char* path; + TexturesEnum texture; TileComponent() = default; - TileComponent(int x, int y, int w, int h, int id, const std::map>* textureDict); + TileComponent(int x, int y, int w, int h, int id, const std::map>* textureDict); ~TileComponent() = default; void init() override; - bool hasCollision(){return this->collision;} - std::string getName(){return this->tileName;} + bool hasCollision() { + return this->collision; + } + + std::string getName() { +#ifdef TEXTURE_ENUM_DEFINED + return std::string(magic_enum::enum_name(this->texture)); +#else + return "Undefined Enum"; +#endif + } + + private: bool collision; - std::string tileName; }; \ No newline at end of file diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index b2d960c..1c7622b 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -59,13 +59,13 @@ void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, projectile.addGroup((size_t)Entity::GroupLabel::PROJECTILE); } -void AssetManager::createPowerup(Vector2D pos, std::function pickupFunc, std::string texturePath) { +void AssetManager::createPowerup(Vector2D pos, std::function pickupFunc, TexturesEnum texture) { auto& powerups(man->addEntity()); powerups.addComponent(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects try { - powerups.addComponent(texturePath.c_str()); + powerups.addComponent(texture); } catch (std::runtime_error e) { std::cout << e.what() << std::endl; diff --git a/src/Map.cpp b/src/Map.cpp index 5689d9e..cb762bc 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -10,7 +10,7 @@ #include "SDL_error.h" #include "TileComponent.h" -void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map>* textureDict /* backreference */) +void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map>* textureDict /* backreference */) { std::string tileIDstr; char singleChar = 0; @@ -56,11 +56,13 @@ void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, co mapFile.close(); } -void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map>* textureDict) // tile entity +void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map>* textureDict) // tile entity { auto& tile(game->manager.addEntity()); tile.addComponent(x, y, TILE_SIZE, TILE_SIZE, id, textureDict); - if(tile.getComponent().hasCollision()) tile.addComponent(tile.getComponent().getName().data()); + if(tile.getComponent().hasCollision()) + tile.addComponent(tile.getComponent().getName().data()); + tile.addGroup((size_t)Entity::GroupLabel::MAPTILES); } \ No newline at end of file diff --git a/src/TileComponent.cpp b/src/TileComponent.cpp index 8658e93..2799dd6 100644 --- a/src/TileComponent.cpp +++ b/src/TileComponent.cpp @@ -9,7 +9,8 @@ #include "TextureEnumBase.h" -TileComponent::TileComponent(int x, int y, int w, int h, int id, const std::map>* textureDict) + +TileComponent::TileComponent(int x, int y, int w, int h, int id, const std::map>* textureDict) { this->tileRect.x = x; this->tileRect.y = y; @@ -24,8 +25,7 @@ TileComponent::TileComponent(int x, int y, int w, int h, int id, const std::map< } this->collision = it->second.second; - this->tileName = it->second.first; - this->path = it->second.first.data(); + this->texture = it->second.first; } void TileComponent::init() @@ -33,7 +33,7 @@ void TileComponent::init() this->entity->addComponent(this->tileRect.x, this->tileRect.y, this->tileRect.w, this->tileRect.h, 1); this->transform = &entity->getComponent(); - this->entity->addComponent(this->path); + this->entity->addComponent(this->texture); this->sprite = &entity->getComponent(); } From 6bedb08d9b767dcd2f464f5b605191f52d467355 Mon Sep 17 00:00:00 2001 From: freezarite Date: Tue, 5 Nov 2024 18:38:53 +0100 Subject: [PATCH 2/3] changes to make chickengame work with updated textureManager future changes regarding the removal of the character selection needed --- .gitignore | 2 ++ src/GameInternal.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 31d3def..50144ad 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ Makefile install_manifest.txt .cache/ build/ +cmake-build-debug/ +.idea/ # Compiled files *.suo diff --git a/src/GameInternal.cpp b/src/GameInternal.cpp index 29d1622..82aa16c 100644 --- a/src/GameInternal.cpp +++ b/src/GameInternal.cpp @@ -141,6 +141,8 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he // loading music // assets->addMusic("background_music", "assets/sound/background_music.mp3"); + + this->gameInstance = GameFactory::instance().create(this); this->gameInstance->init(); } From 549178fc7ccb35bfdd4bcfbb8ec1c41ec8cb93ce Mon Sep 17 00:00:00 2001 From: freezarite Date: Tue, 5 Nov 2024 18:45:34 +0100 Subject: [PATCH 3/3] removed doxigen (idk how it got in here) --- docs/doxygen-awesome-css | 1 - 1 file changed, 1 deletion(-) delete mode 160000 docs/doxygen-awesome-css diff --git a/docs/doxygen-awesome-css b/docs/doxygen-awesome-css deleted file mode 160000 index df88fe4..0000000 --- a/docs/doxygen-awesome-css +++ /dev/null @@ -1 +0,0 @@ -Subproject commit df88fe4fdd97714fadfd3ef17de0b4401f804052