From cf6bf990c2187d1f50c9ea626d033633d671258e Mon Sep 17 00:00:00 2001 From: Tenshi Date: Tue, 3 Oct 2023 19:20:45 +0200 Subject: [PATCH] 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; + } } } }