Skip to content

Commit

Permalink
GAME-LOGIC: Add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Oct 3, 2023
1 parent 67ad627 commit cf6bf99
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
20 changes: 1 addition & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Systems/Graphic/DeathSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace Systems {
// MAP FOR DEATH FUNCTIONS FOR EACH ENTITY
const std::unordered_map<std::type_index, std::function<void(std::size_t)>>
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(
Expand Down
51 changes: 46 additions & 5 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "Registry.hpp"
#include "SystemManagersDirector.hpp"

#include <iostream>

namespace Systems {
void windowCollision(std::size_t /*unused*/, std::size_t /*unused*/)
{
Expand Down Expand Up @@ -98,20 +100,59 @@ namespace Systems {
}
}

bool executeDeadFunc(std::size_t id, Registry::components<Types::Dead> &arrDead)
{
std::cout << "----------------------------------" << std::endl;

// AVANT DE SUPPRIMER, JE REGARDE QUELLES ENTITES EXISTES
Registry::components<Types::Health> arrHealth1 =
Registry::getInstance().getComponents<Types::Health>();

std::vector<std::size_t> 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<Types::Health> arrHealth =
Registry::getInstance().getComponents<Types::Health>();

// JE PRINT LES ENTITES QUI ONT UN COMPOSANT DE HEAL
std::vector<std::size_t> 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<Types::Health> arrHealth =
Registry::getInstance().getComponents<Types::Health>();
Registry::components<Types::Dead> arrDead =
Registry::getInstance().getComponents<Types::Dead>();

bool isEntityRemoved = false;

std::vector<std::size_t> 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<Types::Health>();
arrDead = Registry::getInstance().getComponents<Types::Dead>();
ids = arrHealth.getExistingsId();
itIds = ids.begin();
//if empty, return
if (itIds == ids.end()) {
return;
}
}
}
}
Expand Down

0 comments on commit cf6bf99

Please sign in to comment.