From fb9a775a83b3520e9e7f03ca6c82026429f1e1f4 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Sun, 1 Oct 2023 19:42:48 +0200 Subject: [PATCH 01/22] GAME-LOGIC: Modify screen size --- src/Client/SceneManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 5cfcbeba..5da432bc 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -14,8 +14,8 @@ #include "CustomTypes.hpp" -constexpr int screenWidth = 1920; -constexpr int screenHeight = 1080; +constexpr int screenWidth = 800; +constexpr int screenHeight = 600; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) bool SceneManager::_init = false; From 0bd76aaacea922ea4550db92e41bdcd46673ccca Mon Sep 17 00:00:00 2001 From: Tenshi Date: Sun, 1 Oct 2023 21:29:20 +0200 Subject: [PATCH 02/22] GAME-LOGIC: Add deathChecker func --- src/ECS/ECSCustomTypes.hpp | 8 +++++- src/ECS/Systems/Systems.cpp | 54 ++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 36383426..5a3fd832 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -7,7 +7,9 @@ #pragma once -// all values are in percentage of the screen +#include +#include +#include namespace Types { @@ -36,4 +38,8 @@ namespace Types { struct Player { }; + struct Dead { + std::optional> deathFunction; + }; + } // namespace Types diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index f1df3502..79cf950e 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -101,38 +101,50 @@ namespace Systems { } } + void deathChecker(std::size_t /*unused*/, std::size_t /*unused*/) + { + Registry::components arrHealth = + Registry::getInstance().getComponents(); + Registry::components arrDead = + Registry::getInstance().getComponents(); + + std::vector ids = arrHealth.getExistingsId(); + auto itIds = ids.begin(); + + while (itIds != ids.end()) { + if (arrHealth.exist(*itIds)) { + if (arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { + arrDead[*itIds].deathFunction + ? arrDead[*itIds].deathFunction.value()(*itIds) + : Registry::getInstance().removeEntity(*itIds); + } + } + itIds++; + } + } + const std::string musicPath = "assets/Audio/Musics/Title.mp3"; const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif"; const Types::Rect spriteRect = {2, 2, 48, 48}; - const Types::CollisionRect collisionRect = {46, 46}; + const Types::CollisionRect collisionRect = {25, 25}; const Raylib::Vector2 textPos = {20, 50}; constexpr int playerData = 10; + const Types::Position playerPos = {50, 50}; constexpr int playerDammage = 10; - constexpr int playerHealth = 1; + constexpr int playerHealth = 5; + constexpr int playerHealth2 = 4; constexpr float musicVolume = 0.02F; constexpr float soundVolume = 0.1F; constexpr float fontScale = 2.0F; - const float playerWidth = 50.0F; - const float playerHeight = 50.0F; + const float playerWidth = 25.0F; + const float playerHeight = 25.0F; void init(std::size_t managerId, std::size_t systemId) { std::size_t id = Registry::getInstance().addEntity(); Registry::getInstance().getComponents().insertBack( - {playerData, playerData}); - Registry::getInstance().getComponents().insertBack( - {playerPath, playerWidth, playerHeight, id}); - Registry::getInstance().getComponents().insertBack( - spriteRect); - Registry::getInstance() - .getComponents() - .insertBack(collisionRect); - Registry::getInstance().setToBackLayers(id); - - id = Registry::getInstance().addEntity(); - Registry::getInstance().getComponents().insertBack( - {playerData, playerData}); + playerPos); Registry::getInstance().getComponents().insertBack( {playerPath, playerWidth, playerHeight, id}); Registry::getInstance().getComponents().insertBack( @@ -143,6 +155,8 @@ namespace Systems { Registry::getInstance().getComponents().insertBack({}); Registry::getInstance().getComponents().insertBack( {playerHealth}); + Registry::getInstance().getComponents().insertBack( + {std::nullopt}); id = Registry::getInstance().addEntity(); Registry::getInstance().getComponents().insertBack( @@ -154,6 +168,8 @@ namespace Systems { Registry::getInstance() .getComponents() .insertBack(collisionRect); + Registry::getInstance().getComponents().insertBack( + {std::nullopt}); Registry::getInstance().setToFrontLayers(id); Registry::getInstance().getComponents().insertBack( @@ -169,7 +185,7 @@ namespace Systems { Registry::getInstance().getComponents().insertBack( {playerDammage}); Registry::getInstance().getComponents().insertBack( - {playerHealth}); + {playerHealth2}); SystemManagersDirector::getInstance() .getSystemManager(managerId) .removeSystem(systemId); @@ -177,6 +193,6 @@ namespace Systems { std::vector> getECSSystems() { - return {windowCollision, init, entitiesCollision}; + return {windowCollision, init, entitiesCollision, deathChecker}; } } // namespace Systems From 6c4a7f05fe800349c7030c15015e6eadc762585b Mon Sep 17 00:00:00 2001 From: tenshi Date: Mon, 2 Oct 2023 16:55:09 +0200 Subject: [PATCH 03/22] GAME-LOGIC: Add begin of client side system --- src/Client/Systems/Graphic/GraphicSystems.cpp | 37 ++++++++++++++++++- src/Client/Systems/Graphic/GraphicSystems.hpp | 3 +- src/ECS/Systems/Systems.cpp | 10 ++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index ea393845..fb109469 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -5,10 +5,16 @@ ** GraphicSystems */ +#include +#include +#include +#include +#include #include "GraphicSystems.hpp" #include "CustomTypes.hpp" #include "Raylib.hpp" #include "Registry.hpp" +#include "CustomTypes.hpp" namespace Systems { void @@ -239,6 +245,33 @@ namespace Systems { } } + std::function testFunc = [](std::size_t id) { + std::cout << "Entity " << id << " is dead" << std::endl; + }; + + // const std::unordered_map> + // deathFunctions = { + // {std::type_index(typeid(Types::Player)), testFunc}, + // }; + + void GraphicSystems::setEntityDeathFunction( + std::size_t /*unused*/, + std::size_t /*unused*/) + { + Registry::components arrDead = + Registry::getInstance().getComponents(); + + std::vector ids = arrDead.getExistingsId(); + auto itIds = ids.begin(); + + while (itIds != ids.end()) { + if (arrDead[*itIds].deathFunction == std::nullopt) { + arrDead[*itIds].deathFunction = testFunc; + } + itIds++; + } + } + std::vector> GraphicSystems::getGraphicsSystems() { @@ -248,6 +281,8 @@ namespace Systems { textRenderer, musicPlayer, soundEffectPlayer, - playSoundWithKey}; + playSoundWithKey, + setEntityDeathFunction, + }; } } // namespace Systems diff --git a/src/Client/Systems/Graphic/GraphicSystems.hpp b/src/Client/Systems/Graphic/GraphicSystems.hpp index 8e08dfad..96f03a47 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.hpp +++ b/src/Client/Systems/Graphic/GraphicSystems.hpp @@ -18,7 +18,8 @@ namespace Systems { void textRenderer(std::size_t /*unused*/, std::size_t /*unused*/); void soundEffectPlayer(std::size_t /*unused*/, std::size_t /*unused*/); void musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/); - void playSoundWithKey(std::size_t, std::size_t); + void playSoundWithKey(std::size_t /*unused*/, std::size_t /*unused*/); + void setEntityDeathFunction(std::size_t /*unused*/, std::size_t /*unused*/); std::vector> getGraphicsSystems(); } // namespace GraphicSystems diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 79cf950e..cb2a2727 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -112,12 +112,10 @@ namespace Systems { auto itIds = ids.begin(); while (itIds != ids.end()) { - if (arrHealth.exist(*itIds)) { - if (arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { - arrDead[*itIds].deathFunction - ? arrDead[*itIds].deathFunction.value()(*itIds) - : Registry::getInstance().removeEntity(*itIds); - } + if (arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { + arrDead[*itIds].deathFunction + ? arrDead[*itIds].deathFunction.value()(*itIds) + : Registry::getInstance().removeEntity(*itIds); } itIds++; } From 6f72625bbc43ae752969053f01ef6bbe26d16522 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Mon, 2 Oct 2023 19:59:50 +0200 Subject: [PATCH 04/22] GAME-LOGIC: Add v1 of setEntityDeathFunction Minor --- src/Client/Systems/Graphic/GraphicSystems.cpp | 42 ++++++++++++------- src/ECS/Systems/Systems.cpp | 4 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index fb109469..f080e873 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -5,16 +5,15 @@ ** GraphicSystems */ -#include -#include +#include "GraphicSystems.hpp" #include +#include #include #include -#include "GraphicSystems.hpp" +#include #include "CustomTypes.hpp" #include "Raylib.hpp" #include "Registry.hpp" -#include "CustomTypes.hpp" namespace Systems { void @@ -245,14 +244,29 @@ namespace Systems { } } - std::function testFunc = [](std::size_t id) { - std::cout << "Entity " << id << " is dead" << std::endl; + // REPLACE BY YOUR DEATH FUNCTION + + const std::function testFuncPlayer = [](std::size_t id) { + std::cout << "Player " << id << " is dead" << std::endl; + }; + + const std::unordered_map> + deathFunctions = { + {std::type_index(typeid(Types::Player)), testFuncPlayer}, }; - // const std::unordered_map> - // deathFunctions = { - // {std::type_index(typeid(Types::Player)), testFunc}, - // }; + static void addDeathFunction(Registry::components &arrDead, + Registry::components &arrPlayer, std::size_t id) + { + try { + if (arrPlayer.exist(id)) { + arrDead[id].deathFunction = deathFunctions.at( + std::type_index(typeid(Types::Player))); + } + } catch (std::out_of_range &) { + std::cerr << "No death function for this entity" << std::endl; + } + } void GraphicSystems::setEntityDeathFunction( std::size_t /*unused*/, @@ -260,15 +274,15 @@ namespace Systems { { Registry::components arrDead = Registry::getInstance().getComponents(); + Registry::components arrPlayer = + Registry::getInstance().getComponents(); std::vector ids = arrDead.getExistingsId(); - auto itIds = ids.begin(); - while (itIds != ids.end()) { + for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { if (arrDead[*itIds].deathFunction == std::nullopt) { - arrDead[*itIds].deathFunction = testFunc; + addDeathFunction(arrDead, arrPlayer, *itIds); } - itIds++; } } diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index cb2a2727..fb70cc0a 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -109,15 +109,13 @@ namespace Systems { Registry::getInstance().getComponents(); std::vector ids = arrHealth.getExistingsId(); - auto itIds = ids.begin(); - while (itIds != ids.end()) { + for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { if (arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { arrDead[*itIds].deathFunction ? arrDead[*itIds].deathFunction.value()(*itIds) : Registry::getInstance().removeEntity(*itIds); } - itIds++; } } From e5620104518a745c58e8e448d4d48452e428e5f3 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Mon, 2 Oct 2023 18:22:00 +0000 Subject: [PATCH 05/22] FORMAT-AUTO: automatic format on pull request #38 --- src/Client/Systems/Graphic/DeathSystems.cpp | 10 +++++--- src/Client/Systems/Graphic/DeathSystems.hpp | 9 ++++--- src/Client/Systems/Graphic/GraphicSystems.cpp | 25 +++++++++++++------ src/Client/Systems/Graphic/SpriteSystems.cpp | 1 - src/ECS/ECSCustomTypes.hpp | 2 +- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index f5ae18a0..36b898dc 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -26,13 +26,15 @@ namespace Systems { {std::type_index(typeid(Types::Player)), testFuncPlayer}, }; - static void addDeathFunction(Registry::components &arrDead, - Registry::components &arrPlayer, std::size_t id) + static void addDeathFunction( + Registry::components &arrDead, + Registry::components &arrPlayer, + std::size_t id) { try { if (arrPlayer.exist(id)) { - arrDead[id].deathFunction = deathFunctions.at( - std::type_index(typeid(Types::Player))); + arrDead[id].deathFunction = + deathFunctions.at(std::type_index(typeid(Types::Player))); } } catch (std::out_of_range &) { std::cerr << "No death function for this entity" << std::endl; diff --git a/src/Client/Systems/Graphic/DeathSystems.hpp b/src/Client/Systems/Graphic/DeathSystems.hpp index 3137d3d0..3d5b1f24 100644 --- a/src/Client/Systems/Graphic/DeathSystems.hpp +++ b/src/Client/Systems/Graphic/DeathSystems.hpp @@ -7,12 +7,15 @@ #pragma once -#include #include +#include namespace Systems { namespace DeathSystems { - std::vector> getDeathSystems(); - void setEntityDeathFunction(std::size_t /*unused*/, std::size_t /*unused*/); + std::vector> + getDeathSystems(); + void setEntityDeathFunction( + std::size_t /*unused*/, + std::size_t /*unused*/); } // namespace DeathSystems } // namespace Systems diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 7b152601..3cc29720 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -7,15 +7,16 @@ #include "GraphicSystems.hpp" #include "AudioSystems.hpp" +#include "DeathSystems.hpp" #include "SpriteSystems.hpp" #include "TextSystems.hpp" -#include "DeathSystems.hpp" namespace Systems { std::vector> GraphicSystems::getGraphicsSystems() { - std::vector> graphicSystems; + std::vector> + graphicSystems; std::vector> audioSystems = getAudioSystems(); @@ -23,16 +24,24 @@ namespace Systems { spriteSystems = getSpriteSystems(); std::vector> textSystems = getTextSystems(); - std::vector> deathSystems = - DeathSystems::getDeathSystems(); + std::vector> + deathSystems = DeathSystems::getDeathSystems(); - graphicSystems.insert(graphicSystems.end(), audioSystems.begin(), + graphicSystems.insert( + graphicSystems.end(), + audioSystems.begin(), audioSystems.end()); - graphicSystems.insert(graphicSystems.end(), spriteSystems.begin(), + graphicSystems.insert( + graphicSystems.end(), + spriteSystems.begin(), spriteSystems.end()); - graphicSystems.insert(graphicSystems.end(), textSystems.begin(), + graphicSystems.insert( + graphicSystems.end(), + textSystems.begin(), textSystems.end()); - graphicSystems.insert(graphicSystems.end(), deathSystems.begin(), + graphicSystems.insert( + graphicSystems.end(), + deathSystems.begin(), deathSystems.end()); return graphicSystems; } diff --git a/src/Client/Systems/Graphic/SpriteSystems.cpp b/src/Client/Systems/Graphic/SpriteSystems.cpp index c239396b..53b877ea 100644 --- a/src/Client/Systems/Graphic/SpriteSystems.cpp +++ b/src/Client/Systems/Graphic/SpriteSystems.cpp @@ -58,7 +58,6 @@ namespace Systems { registry.getComponents(); std::vector rectShapeIndexes = arrRect.getExistingsId(); - for (auto id : rectShapeIndexes) { if (!arrPosition.exist(id)) { continue; diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 5a3fd832..4ae649b7 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -7,9 +7,9 @@ #pragma once +#include #include #include -#include namespace Types { From 1d96a5b6c01ac0509568d39f75b4a5dace06bca0 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Mon, 2 Oct 2023 20:31:21 +0200 Subject: [PATCH 06/22] GAME-LOGIC: Add character run --- src/ECS/Systems/Systems.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index fb70cc0a..3d6bb774 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -148,6 +148,17 @@ namespace Systems { Registry::getInstance() .getComponents() .insertBack(collisionRect); + // NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + Registry::getInstance().getComponents().insertBack({ + spriteRect, + {spriteRect, + {2, 51, 46, 47}, + {101, 2, 48, 47}, + {152, 2, 46, 47}, + {201, 2, 46, 47}}, + }); + // NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + Registry::getInstance().setToBackLayers(id); Registry::getInstance().getComponents().insertBack({}); Registry::getInstance().getComponents().insertBack( {playerHealth}); From eb803977f35cc7a49dd9420c8fecda97e548f260 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Mon, 2 Oct 2023 20:36:43 +0200 Subject: [PATCH 07/22] GAME-LOGIC: Fix deathSystems return value PATCH --- src/Client/Systems/Graphic/GraphicSystems.cpp | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 3cc29720..b0f22b61 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -15,9 +15,6 @@ namespace Systems { std::vector> GraphicSystems::getGraphicsSystems() { - std::vector> - graphicSystems; - std::vector> audioSystems = getAudioSystems(); std::vector> @@ -27,22 +24,18 @@ namespace Systems { std::vector> deathSystems = DeathSystems::getDeathSystems(); - graphicSystems.insert( - graphicSystems.end(), - audioSystems.begin(), - audioSystems.end()); - graphicSystems.insert( - graphicSystems.end(), + audioSystems.insert( + audioSystems.end(), spriteSystems.begin(), spriteSystems.end()); - graphicSystems.insert( - graphicSystems.end(), + audioSystems.insert( + audioSystems.end(), textSystems.begin(), textSystems.end()); - graphicSystems.insert( - graphicSystems.end(), + audioSystems.insert( + audioSystems.end(), deathSystems.begin(), deathSystems.end()); - return graphicSystems; + return audioSystems; } } // namespace Systems From 30277f8bf182163dac318b196829094a68bc5f5d Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 3 Oct 2023 13:38:38 +0200 Subject: [PATCH 08/22] GAME-LOGIC: Fix ternary PATCH --- src/ECS/Systems/Systems.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index b89a3165..88f44995 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -107,12 +107,13 @@ namespace Systems { Registry::getInstance().getComponents(); std::vector ids = arrHealth.getExistingsId(); - for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { if (arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { - arrDead[*itIds].deathFunction - ? arrDead[*itIds].deathFunction.value()(*itIds) - : Registry::getInstance().removeEntity(*itIds); + if (arrDead[*itIds].deathFunction) { + arrDead[*itIds].deathFunction.value()(*itIds); + } else { + Registry::getInstance().removeEntity(*itIds); + } } } } From e80cd949d829f0bd2d79760343d38239366f15cb Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 3 Oct 2023 15:29:34 +0200 Subject: [PATCH 09/22] GAME-LOGIC: Add funcitonnal EntityDeathFunction MINOR --- src/Client/Systems/Graphic/DeathSystems.cpp | 44 +++++++++------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index 36b898dc..eb5c0880 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -6,7 +6,6 @@ */ #include "DeathSystems.hpp" -#include #include #include #include "CustomTypes.hpp" @@ -14,47 +13,40 @@ namespace Systems { - // REPLACE BY YOUR DEATH FUNCTION + const std::function setPlayerAnimRectToDeath = [](std::size_t id) { + Registry::components arrAnimRect = + Registry::getInstance().getComponents(); - const std::function testFuncPlayer = [](std::size_t id) { - std::cout << "Player " << id << " is dead" << std::endl; + if (arrAnimRect.exist(id)) { + Types::AnimRect &anim = arrAnimRect[id]; + if (anim.currentRectList != Types::RectListType::DEAD) { + anim.changeRectList(Types::RectListType::DEAD); + } + } }; - // MAP FOR DEATH FUNCTIONS + // MAP FOR DEATH FUNCTIONS FOR EACH ENTITY const std::unordered_map> deathFunctions = { - {std::type_index(typeid(Types::Player)), testFuncPlayer}, + {std::type_index(typeid(Types::Player)), setPlayerAnimRectToDeath}, }; - static void addDeathFunction( - Registry::components &arrDead, - Registry::components &arrPlayer, - std::size_t id) - { - try { - if (arrPlayer.exist(id)) { - arrDead[id].deathFunction = - deathFunctions.at(std::type_index(typeid(Types::Player))); - } - } catch (std::out_of_range &) { - std::cerr << "No death function for this entity" << std::endl; - } - } - void DeathSystems::setEntityDeathFunction( std::size_t /*unused*/, std::size_t /*unused*/) { Registry::components arrDead = Registry::getInstance().getComponents(); - Registry::components arrPlayer = - Registry::getInstance().getComponents(); std::vector ids = arrDead.getExistingsId(); - for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { - if (arrDead[*itIds].deathFunction == std::nullopt) { - addDeathFunction(arrDead, arrPlayer, *itIds); + for (const auto& [typeIndex, function] : deathFunctions) { + std::vector entities = + Registry::getInstance().getEntitiesByComponents({typeIndex}); + for (std::size_t id : entities) { + if (arrDead.exist(id) && arrDead[id].deathFunction == std::nullopt) { + arrDead[id].deathFunction = function; + } } } } From d58aad47c3b7d1f53248aa94e9b1c86433c009a4 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 3 Oct 2023 13:43:03 +0000 Subject: [PATCH 10/22] FORMAT-AUTO: automatic format on pull request #38 --- src/Client/Systems/Graphic/DeathSystems.cpp | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index eb5c0880..08dbfa30 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -13,17 +13,18 @@ namespace Systems { - const std::function setPlayerAnimRectToDeath = [](std::size_t id) { - Registry::components arrAnimRect = - Registry::getInstance().getComponents(); - - if (arrAnimRect.exist(id)) { - Types::AnimRect &anim = arrAnimRect[id]; - if (anim.currentRectList != Types::RectListType::DEAD) { - anim.changeRectList(Types::RectListType::DEAD); + const std::function setPlayerAnimRectToDeath = + [](std::size_t id) { + Registry::components arrAnimRect = + Registry::getInstance().getComponents(); + + if (arrAnimRect.exist(id)) { + Types::AnimRect& anim = arrAnimRect[id]; + if (anim.currentRectList != Types::RectListType::DEAD) { + anim.changeRectList(Types::RectListType::DEAD); + } } - } - }; + }; // MAP FOR DEATH FUNCTIONS FOR EACH ENTITY const std::unordered_map> @@ -44,7 +45,8 @@ namespace Systems { std::vector entities = Registry::getInstance().getEntitiesByComponents({typeIndex}); for (std::size_t id : entities) { - if (arrDead.exist(id) && arrDead[id].deathFunction == std::nullopt) { + if (arrDead.exist(id) + && arrDead[id].deathFunction == std::nullopt) { arrDead[id].deathFunction = function; } } From cf12c4646350bc76d7cdba9f4efd41ffd64b941b Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 3 Oct 2023 15:48:49 +0200 Subject: [PATCH 11/22] GAME-LOGIC: Add test --- src/Client/Systems/Graphic/DeathSystems.cpp | 9 +++++++-- src/ECS/ECSCustomTypes.hpp | 2 ++ src/ECS/Systems/Systems.cpp | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index eb5c0880..bc810fc1 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -13,7 +13,7 @@ namespace Systems { - const std::function setPlayerAnimRectToDeath = [](std::size_t id) { + const std::function setPlayerAnimRectDeath = [](std::size_t id) { Registry::components arrAnimRect = Registry::getInstance().getComponents(); @@ -24,11 +24,16 @@ namespace Systems { } } }; + + const std::function setEnemyDeathFunc = [](std::size_t id) { + Registry::getInstance().removeEntity(id); + }; // MAP FOR DEATH FUNCTIONS FOR EACH ENTITY const std::unordered_map> deathFunctions = { - {std::type_index(typeid(Types::Player)), setPlayerAnimRectToDeath}, + {std::type_index(typeid(Types::Player)), setPlayerAnimRectDeath}, + {std::type_index(typeid(Types::Enemy)), setEnemyDeathFunc}, }; void DeathSystems::setEntityDeathFunction( diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 4ae649b7..ec190d8d 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -38,6 +38,8 @@ namespace Types { struct Player { }; + struct Enemy { }; + struct Dead { std::optional> deathFunction; }; diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 88f44995..4b461775 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -150,11 +150,24 @@ namespace Systems { // NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) Registry::getInstance().getComponents().insertBack({ spriteRect, - {spriteRect, + {spriteRect, // move {2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47}}, + {201, 2, 46, 47} + }, + {spriteRect, // attack + {2, 51, 46, 47}, + {101, 2, 48, 47}, + {152, 2, 46, 47}, + {201, 2, 46, 47} + }, + {spriteRect, // dead x y with height + {180, 140, 18, 12}, + {211, 140, 18, 12}, + {230, 140, 18, 12}, + {250, 140, 18, 12} + } }); // NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) Registry::getInstance().setToBackLayers(id); @@ -165,6 +178,7 @@ namespace Systems { {std::nullopt}); id = Registry::getInstance().addEntity(); + Registry::getInstance().getComponents().insertBack({}); Registry::getInstance().getComponents().insertBack( {playerData, playerData + playerData + playerData}); Registry::getInstance().getComponents().insertBack( From b10872d3bcf75b2fab3fdf9d0c88f0804f87c5a8 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 3 Oct 2023 13:59:44 +0000 Subject: [PATCH 12/22] FORMAT-AUTO: automatic format on pull request #38 --- src/ECS/Systems/Systems.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 4b461775..c0fa9a79 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -151,23 +151,20 @@ namespace Systems { Registry::getInstance().getComponents().insertBack({ spriteRect, {spriteRect, // move - {2, 51, 46, 47}, + {2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47} - }, + {201, 2, 46, 47} }, {spriteRect, // attack - {2, 51, 46, 47}, + {2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47} - }, + {201, 2, 46, 47} }, {spriteRect, // dead x y with height - {180, 140, 18, 12}, + {180, 140, 18, 12}, {211, 140, 18, 12}, {230, 140, 18, 12}, - {250, 140, 18, 12} - } + {250, 140, 18, 12}} }); // NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) Registry::getInstance().setToBackLayers(id); From 10d5d6c87b7990b98646ce2d7b34072950143b43 Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 3 Oct 2023 16:29:49 +0200 Subject: [PATCH 13/22] GAME-LOGIC: Add enemy test --- src/ECS/ECSCustomTypes.hpp | 4 ++-- src/ECS/Systems/Systems.cpp | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index ec190d8d..1f118b70 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -32,8 +32,8 @@ namespace Types { int hp; }; - struct Dammage { - int dammage; + struct Damage { + int damage; }; struct Player { }; diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 4b461775..bc650960 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -44,15 +44,15 @@ namespace Systems { static void giveDamages(std::size_t firstEntity, std::size_t secondEntity) { - Registry::components arrDammage = - Registry::getInstance().getComponents(); + Registry::components arrDamage = + Registry::getInstance().getComponents(); Registry::components arrHealth = Registry::getInstance().getComponents(); - if (arrDammage.exist(firstEntity) - && arrDammage[firstEntity].dammage > 0) { + if (arrDamage.exist(firstEntity) + && arrDamage[firstEntity].damage > 0) { if (arrHealth.exist(secondEntity)) { - arrHealth[secondEntity].hp -= arrDammage[firstEntity].dammage; + arrHealth[secondEntity].hp -= arrDamage[firstEntity].damage; } } } @@ -126,9 +126,10 @@ namespace Systems { const Raylib::Vector2 textPos = {20, 50}; constexpr int playerData = 10; const Types::Position playerPos = {50, 50}; - constexpr int playerDammage = 10; + constexpr int playerDamage = 1; + constexpr int enemyDamage = 1; constexpr int playerHealth = 5; - constexpr int playerHealth2 = 4; + constexpr int playerHealth2 = 5; constexpr float musicVolume = 0.02F; constexpr float soundVolume = 0.1F; constexpr float fontScale = 2.0F; @@ -172,6 +173,8 @@ namespace Systems { // NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) Registry::getInstance().setToBackLayers(id); Registry::getInstance().getComponents().insertBack({}); + Registry::getInstance().getComponents().insertBack( + {playerDamage}); Registry::getInstance().getComponents().insertBack( {playerHealth}); Registry::getInstance().getComponents().insertBack( @@ -202,8 +205,8 @@ namespace Systems { textPos, fontScale, Raylib::DarkBlue}); - Registry::getInstance().getComponents().insertBack( - {playerDammage}); + Registry::getInstance().getComponents().insertBack( + {enemyDamage}); Registry::getInstance().getComponents().insertBack( {playerHealth2}); SystemManagersDirector::getInstance() From 67ad6271bb85443a022988688b47125c78c8d68e Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 3 Oct 2023 14:30:19 +0000 Subject: [PATCH 14/22] FORMAT-AUTO: automatic format on pull request #38 --- src/ECS/Systems/Systems.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 2e408bf2..69abfe29 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -49,8 +49,7 @@ namespace Systems { Registry::components arrHealth = Registry::getInstance().getComponents(); - if (arrDamage.exist(firstEntity) - && arrDamage[firstEntity].damage > 0) { + if (arrDamage.exist(firstEntity) && arrDamage[firstEntity].damage > 0) { if (arrHealth.exist(secondEntity)) { arrHealth[secondEntity].hp -= arrDamage[firstEntity].damage; } @@ -126,8 +125,8 @@ namespace Systems { const Raylib::Vector2 textPos = {20, 50}; constexpr int playerData = 10; const Types::Position playerPos = {50, 50}; - constexpr int playerDamage = 1; - constexpr int enemyDamage = 1; + constexpr int playerDamage = 1; + constexpr int enemyDamage = 1; constexpr int playerHealth = 5; constexpr int playerHealth2 = 5; constexpr float musicVolume = 0.02F; From cf6bf990c2187d1f50c9ea626d033633d671258e Mon Sep 17 00:00:00 2001 From: Tenshi Date: Tue, 3 Oct 2023 19:20:45 +0200 Subject: [PATCH 15/22] GAME-LOGIC: Add debug --- CMakeLists.txt | 20 +------- src/Client/Systems/Graphic/DeathSystems.cpp | 4 +- src/ECS/Systems/Systems.cpp | 51 +++++++++++++++++++-- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1b43b6d..906ba6cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,25 +56,7 @@ install(TARGETS ${PROJECT_NAME_SERVER} add_subdirectory(deps) -# Clang-Tidy - -find_program(CLANG_TIDY_EXE NAMES "clang-tidy") - -if(CLANG_TIDY_EXE) - if (MSVC) - set_target_properties(${PROJECT_NAME_CLIENT} PROPERTIES - VS_GLOBAL_RunCodeAnalysis true - VS_GLOBAL_EnableClangTidyCodeAnalysis true - ) - set_target_properties(${PROJECT_NAME_SERVER} PROPERTIES - VS_GLOBAL_RunCodeAnalysis true - VS_GLOBAL_EnableClangTidyCodeAnalysis true - ) - else() - set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors") - set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") - endif() -endif() + if(MSVC) target_compile_options( diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index 76fd212a..ca413563 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -34,8 +34,8 @@ namespace Systems { // MAP FOR DEATH FUNCTIONS FOR EACH ENTITY const std::unordered_map> deathFunctions = { - {std::type_index(typeid(Types::Player)), setPlayerAnimRectDeath}, - {std::type_index(typeid(Types::Enemy)), setEnemyDeathFunc }, + // {std::type_index(typeid(Types::Player)), setPlayerAnimRectDeath}, + // {std::type_index(typeid(Types::Enemy)), setEnemyDeathFunc }, }; void DeathSystems::setEntityDeathFunction( diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 69abfe29..5a714e69 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -12,6 +12,8 @@ #include "Registry.hpp" #include "SystemManagersDirector.hpp" +#include + namespace Systems { void windowCollision(std::size_t /*unused*/, std::size_t /*unused*/) { @@ -98,20 +100,59 @@ namespace Systems { } } + bool executeDeadFunc(std::size_t id, Registry::components &arrDead) + { + std::cout << "----------------------------------" << std::endl; + + // AVANT DE SUPPRIMER, JE REGARDE QUELLES ENTITES EXISTES + Registry::components arrHealth1 = + Registry::getInstance().getComponents(); + + std::vector ids1 = arrHealth1.getExistingsId(); + for (auto itIds1 = ids1.begin(); itIds1 != ids1.end(); itIds1++) { + std::cout << "There is an entity with id " << *itIds1 << std::endl; + } + + // JE SUPPRIME MON ENTITE + Registry::getInstance().removeEntity(id); + std::cout << "entity with id " << id << " removed" << std::endl; + + // JE GET LES COMPOSANTS DE HEAL POUR DEBUG + Registry::components arrHealth = + Registry::getInstance().getComponents(); + + // JE PRINT LES ENTITES QUI ONT UN COMPOSANT DE HEAL + std::vector ids = arrHealth.getExistingsId(); + for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { + std::cout << "There is an entity with id " << *itIds << std::endl; + } + + std::cout << "----------------------------------" << std::endl; + return true; + } + void deathChecker(std::size_t /*unused*/, std::size_t /*unused*/) { Registry::components arrHealth = Registry::getInstance().getComponents(); Registry::components arrDead = Registry::getInstance().getComponents(); + + bool isEntityRemoved = false; std::vector ids = arrHealth.getExistingsId(); for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { - if (arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { - if (arrDead[*itIds].deathFunction) { - arrDead[*itIds].deathFunction.value()(*itIds); - } else { - Registry::getInstance().removeEntity(*itIds); + if (arrHealth.exist(*itIds) && arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { + isEntityRemoved = executeDeadFunc(*itIds, arrDead); + if (isEntityRemoved) { + arrHealth = Registry::getInstance().getComponents(); + arrDead = Registry::getInstance().getComponents(); + ids = arrHealth.getExistingsId(); + itIds = ids.begin(); + //if empty, return + if (itIds == ids.end()) { + return; + } } } } From e883a936859659453f52f4f1181252b70407032c Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 3 Oct 2023 17:21:33 +0000 Subject: [PATCH 16/22] FORMAT-AUTO: automatic format on pull request #38 --- src/ECS/Systems/Systems.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 5a714e69..ce11910f 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -100,14 +100,15 @@ namespace Systems { } } - bool executeDeadFunc(std::size_t id, Registry::components &arrDead) + bool + executeDeadFunc(std::size_t id, Registry::components &arrDead) { std::cout << "----------------------------------" << std::endl; // AVANT DE SUPPRIMER, JE REGARDE QUELLES ENTITES EXISTES Registry::components arrHealth1 = Registry::getInstance().getComponents(); - + std::vector ids1 = arrHealth1.getExistingsId(); for (auto itIds1 = ids1.begin(); itIds1 != ids1.end(); itIds1++) { std::cout << "There is an entity with id " << *itIds1 << std::endl; @@ -137,19 +138,22 @@ namespace Systems { Registry::getInstance().getComponents(); Registry::components arrDead = Registry::getInstance().getComponents(); - + bool isEntityRemoved = false; std::vector ids = arrHealth.getExistingsId(); for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { - if (arrHealth.exist(*itIds) && arrHealth[*itIds].hp <= 0 && arrDead.exist(*itIds)) { + if (arrHealth.exist(*itIds) && arrHealth[*itIds].hp <= 0 + && arrDead.exist(*itIds)) { isEntityRemoved = executeDeadFunc(*itIds, arrDead); if (isEntityRemoved) { - arrHealth = Registry::getInstance().getComponents(); - arrDead = Registry::getInstance().getComponents(); - ids = arrHealth.getExistingsId(); + arrHealth = + Registry::getInstance().getComponents(); + arrDead = + Registry::getInstance().getComponents(); + ids = arrHealth.getExistingsId(); itIds = ids.begin(); - //if empty, return + // if empty, return if (itIds == ids.end()) { return; } From d751c6601314b37b44c5c3daedcfdaf6bf83192f Mon Sep 17 00:00:00 2001 From: Tenshi Date: Tue, 3 Oct 2023 20:58:01 +0200 Subject: [PATCH 17/22] CLIENT-GAME: Add tests for debug --- src/ECS/Systems/Systems.cpp | 67 +++++++++---------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index ce11910f..400c7573 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -100,66 +100,31 @@ namespace Systems { } } - bool - executeDeadFunc(std::size_t id, Registry::components &arrDead) + void deathChecker(std::size_t /*unused*/, std::size_t /*unused*/) { - std::cout << "----------------------------------" << std::endl; - - // AVANT DE SUPPRIMER, JE REGARDE QUELLES ENTITES EXISTES - Registry::components arrHealth1 = - Registry::getInstance().getComponents(); - - std::vector ids1 = arrHealth1.getExistingsId(); - for (auto itIds1 = ids1.begin(); itIds1 != ids1.end(); itIds1++) { - std::cout << "There is an entity with id " << *itIds1 << std::endl; - } - - // JE SUPPRIME MON ENTITE - Registry::getInstance().removeEntity(id); - std::cout << "entity with id " << id << " removed" << std::endl; - - // JE GET LES COMPOSANTS DE HEAL POUR DEBUG Registry::components arrHealth = Registry::getInstance().getComponents(); - // JE PRINT LES ENTITES QUI ONT UN COMPOSANT DE HEAL - std::vector ids = arrHealth.getExistingsId(); - for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { - std::cout << "There is an entity with id " << *itIds << std::endl; + auto ids = arrHealth.getExistingsId(); + + //je print les entites existantes = resultat 0 et 1 + for (auto id : ids) { + std::cout << "There is an entity with id : " << id << std::endl; } - std::cout << "----------------------------------" << std::endl; - return true; - } + //je supprime la premiere entite existante + Registry::getInstance().removeEntity(0); + std::cout << "-----------------------------------------------------" << std::endl; - void deathChecker(std::size_t /*unused*/, std::size_t /*unused*/) - { - Registry::components arrHealth = - Registry::getInstance().getComponents(); - Registry::components arrDead = - Registry::getInstance().getComponents(); + //je print les entites existantes = 0 car j en ai supprime une + auto ids2 = arrHealth.getExistingsId(); + for (auto id : ids2) { + std::cout << "There is an entity with id : " << id << std::endl; + } - bool isEntityRemoved = false; + Registry::getInstance().removeEntity(0); - std::vector ids = arrHealth.getExistingsId(); - for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { - if (arrHealth.exist(*itIds) && arrHealth[*itIds].hp <= 0 - && arrDead.exist(*itIds)) { - isEntityRemoved = executeDeadFunc(*itIds, arrDead); - if (isEntityRemoved) { - arrHealth = - Registry::getInstance().getComponents(); - arrDead = - Registry::getInstance().getComponents(); - ids = arrHealth.getExistingsId(); - itIds = ids.begin(); - // if empty, return - if (itIds == ids.end()) { - return; - } - } - } - } + exit(0); } const std::string musicPath = "assets/Audio/Musics/Title.mp3"; From 63fcc33f5606cc0a993b6f02a331edd4ddc2d435 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 3 Oct 2023 18:58:53 +0000 Subject: [PATCH 18/22] FORMAT-AUTO: automatic format on pull request #38 --- src/ECS/Systems/Systems.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 400c7573..1bf432d6 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -107,16 +107,17 @@ namespace Systems { auto ids = arrHealth.getExistingsId(); - //je print les entites existantes = resultat 0 et 1 + // je print les entites existantes = resultat 0 et 1 for (auto id : ids) { std::cout << "There is an entity with id : " << id << std::endl; } - //je supprime la premiere entite existante + // je supprime la premiere entite existante Registry::getInstance().removeEntity(0); - std::cout << "-----------------------------------------------------" << std::endl; + std::cout << "-----------------------------------------------------" + << std::endl; - //je print les entites existantes = 0 car j en ai supprime une + // je print les entites existantes = 0 car j en ai supprime une auto ids2 = arrHealth.getExistingsId(); for (auto id : ids2) { std::cout << "There is an entity with id : " << id << std::endl; From 225cfcb869bccfedf68b29f34219ef23373b78fe Mon Sep 17 00:00:00 2001 From: Tenshi Date: Tue, 3 Oct 2023 21:57:34 +0200 Subject: [PATCH 19/22] GAME-LOGIC: Fix sparse bug PATCH --- src/ECS/SparseArray.hpp | 2 +- src/ECS/Systems/Systems.cpp | 41 +++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/ECS/SparseArray.hpp b/src/ECS/SparseArray.hpp index 1a2fb90d..17baa3a2 100644 --- a/src/ECS/SparseArray.hpp +++ b/src/ECS/SparseArray.hpp @@ -112,7 +112,7 @@ class SparseArray { } } for (auto it2 = _sparse.begin(); it2 != _sparse.end(); it2++) { - if (*it2 > sparseValue) { + if (static_cast(*it2) > static_cast(sparseValue)) { (*it2)--; } } diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 1bf432d6..e28fa6f0 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -12,8 +12,6 @@ #include "Registry.hpp" #include "SystemManagersDirector.hpp" -#include - namespace Systems { void windowCollision(std::size_t /*unused*/, std::size_t /*unused*/) { @@ -100,32 +98,31 @@ namespace Systems { } } + static void executeDeathFunction( + std::size_t id, + Registry::components arrDead) + { + if (arrDead[id].deathFunction != std::nullopt) { + arrDead[id].deathFunction.value()(id); + } else { + Registry::getInstance().removeEntity(id); + } + } + void deathChecker(std::size_t /*unused*/, std::size_t /*unused*/) { Registry::components arrHealth = Registry::getInstance().getComponents(); + Registry::components arrDead = + Registry::getInstance().getComponents(); - auto ids = arrHealth.getExistingsId(); - - // je print les entites existantes = resultat 0 et 1 - for (auto id : ids) { - std::cout << "There is an entity with id : " << id << std::endl; - } - - // je supprime la premiere entite existante - Registry::getInstance().removeEntity(0); - std::cout << "-----------------------------------------------------" - << std::endl; - - // je print les entites existantes = 0 car j en ai supprime une - auto ids2 = arrHealth.getExistingsId(); - for (auto id : ids2) { - std::cout << "There is an entity with id : " << id << std::endl; + std::vector ids = arrHealth.getExistingsId(); + for (auto itIds = ids.begin(); itIds != ids.end(); itIds++) { + if (arrHealth.exist(*itIds) && arrHealth[*itIds].hp <= 0 + && arrDead.exist(*itIds)) { + executeDeathFunction(*itIds, arrDead); + } } - - Registry::getInstance().removeEntity(0); - - exit(0); } const std::string musicPath = "assets/Audio/Musics/Title.mp3"; From 67f2c43dc4e606cb41218b319a07e87b432c3c1b Mon Sep 17 00:00:00 2001 From: Tenshi Date: Tue, 3 Oct 2023 22:00:23 +0200 Subject: [PATCH 20/22] GAME-LOGIC: Fix merge requests --- CMakeLists.txt | 20 +++++++++++++++++++- src/Client/SceneManager.cpp | 4 ++-- src/Client/Systems/Graphic/DeathSystems.cpp | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 906ba6cf..d1b43b6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,25 @@ install(TARGETS ${PROJECT_NAME_SERVER} add_subdirectory(deps) - +# Clang-Tidy + +find_program(CLANG_TIDY_EXE NAMES "clang-tidy") + +if(CLANG_TIDY_EXE) + if (MSVC) + set_target_properties(${PROJECT_NAME_CLIENT} PROPERTIES + VS_GLOBAL_RunCodeAnalysis true + VS_GLOBAL_EnableClangTidyCodeAnalysis true + ) + set_target_properties(${PROJECT_NAME_SERVER} PROPERTIES + VS_GLOBAL_RunCodeAnalysis true + VS_GLOBAL_EnableClangTidyCodeAnalysis true + ) + else() + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors") + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + endif() +endif() if(MSVC) target_compile_options( diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 5da432bc..5cfcbeba 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -14,8 +14,8 @@ #include "CustomTypes.hpp" -constexpr int screenWidth = 800; -constexpr int screenHeight = 600; +constexpr int screenWidth = 1920; +constexpr int screenHeight = 1080; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) bool SceneManager::_init = false; diff --git a/src/Client/Systems/Graphic/DeathSystems.cpp b/src/Client/Systems/Graphic/DeathSystems.cpp index ca413563..76fd212a 100644 --- a/src/Client/Systems/Graphic/DeathSystems.cpp +++ b/src/Client/Systems/Graphic/DeathSystems.cpp @@ -34,8 +34,8 @@ namespace Systems { // MAP FOR DEATH FUNCTIONS FOR EACH ENTITY const std::unordered_map> deathFunctions = { - // {std::type_index(typeid(Types::Player)), setPlayerAnimRectDeath}, - // {std::type_index(typeid(Types::Enemy)), setEnemyDeathFunc }, + {std::type_index(typeid(Types::Player)), setPlayerAnimRectDeath}, + {std::type_index(typeid(Types::Enemy)), setEnemyDeathFunc }, }; void DeathSystems::setEntityDeathFunction( From 71c9419d8983224c0294f69b7bcb5c46c059c4d2 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Tue, 3 Oct 2023 22:49:12 +0200 Subject: [PATCH 21/22] GAME-LOGIC: Fix animation rect PATCH --- src/Client/Systems/Graphic/AudioSystems.cpp | 4 ---- src/ECS/Systems/Systems.cpp | 13 +++++-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Client/Systems/Graphic/AudioSystems.cpp b/src/Client/Systems/Graphic/AudioSystems.cpp index aa8330e4..38567e5f 100644 --- a/src/Client/Systems/Graphic/AudioSystems.cpp +++ b/src/Client/Systems/Graphic/AudioSystems.cpp @@ -44,10 +44,6 @@ namespace Systems { const std::string musicPath = "assets/Audio/Musics/Title.mp3"; const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; - const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif"; - const Types::Rect spriteRect = {2, 2, 48, 48}; - const Types::CollisionRect collisionRect = {46, 46}; - const Raylib::Vector2 textPos = {20, 50}; void GraphicSystems::playSoundWithKey( std::size_t /*unused*/, diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index e28fa6f0..633ac05e 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -158,18 +158,15 @@ namespace Systems { // NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) Registry::getInstance().getComponents().insertBack({ spriteRect, - {spriteRect, // move - {2, 51, 46, 47}, + {{2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47} }, - {spriteRect, // attack - {2, 51, 46, 47}, + {201, 2, 46, 47}}, + {{2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47} }, - {spriteRect, // dead x y with height - {180, 140, 18, 12}, + {201, 2, 46, 47}}, + {{180, 140, 18, 12}, {211, 140, 18, 12}, {230, 140, 18, 12}, {250, 140, 18, 12}} From eb01dd88cea10c66bfb07e7176e4d618ddd7e322 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 3 Oct 2023 20:49:54 +0000 Subject: [PATCH 22/22] FORMAT-AUTO: automatic format on pull request #38 --- src/Client/Systems/Graphic/AudioSystems.cpp | 4 ++-- src/ECS/Systems/Systems.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Client/Systems/Graphic/AudioSystems.cpp b/src/Client/Systems/Graphic/AudioSystems.cpp index 38567e5f..2c4b0cec 100644 --- a/src/Client/Systems/Graphic/AudioSystems.cpp +++ b/src/Client/Systems/Graphic/AudioSystems.cpp @@ -42,8 +42,8 @@ namespace Systems { } } - const std::string musicPath = "assets/Audio/Musics/Title.mp3"; - const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; + const std::string musicPath = "assets/Audio/Musics/Title.mp3"; + const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; void GraphicSystems::playSoundWithKey( std::size_t /*unused*/, diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 633ac05e..880f93eb 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -161,11 +161,11 @@ namespace Systems { {{2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47}}, + {201, 2, 46, 47} }, {{2, 51, 46, 47}, {101, 2, 48, 47}, {152, 2, 46, 47}, - {201, 2, 46, 47}}, + {201, 2, 46, 47} }, {{180, 140, 18, 12}, {211, 140, 18, 12}, {230, 140, 18, 12},