Skip to content

Commit

Permalink
feat(ecs): get_systems send a fatal_error event for out of range systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Sep 13, 2019
1 parent 8d12225 commit a7d169a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion modules/ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
add_library(antara_ecs_shared_sources INTERFACE)
target_sources(antara_ecs_shared_sources INTERFACE antara/gaming/ecs/base.system.cpp antara/gaming/ecs/system.manager.cpp)
target_include_directories(antara_ecs_shared_sources INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_ecs_shared_sources INTERFACE EnTT strong_type expected range-v3 antara::refl-cpp antara::default_settings antara::timer)
target_link_libraries(antara_ecs_shared_sources INTERFACE EnTT strong_type expected range-v3 antara::refl-cpp antara::default_settings antara::timer antara::event)
add_library(antara::ecs_shared_sources ALIAS antara_ecs_shared_sources)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ namespace antara::gaming::ecs::tests
CHECK_FALSE(manager.disable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_EQ(0ull, manager.update());
CHECK_EQ(0ull, manager.nb_systems());
manager.get_systems<logic_concrete_system, pre_concrete_system>();
c_mgr.get_systems<logic_concrete_system, pre_concrete_system>();
}
}
}
38 changes: 18 additions & 20 deletions modules/ecs/antara/gaming/ecs/system.manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "antara/gaming/ecs/system.hpp"
#include "antara/gaming/ecs/system.type.hpp"
#include "antara/gaming/timer/time.step.hpp"
#include "antara/gaming/event/fatal.error.event.hpp"

namespace antara::gaming::ecs
{
Expand Down Expand Up @@ -113,7 +114,7 @@ namespace antara::gaming::ecs
* \tparam TSystem Represents the system that needs to be marked
* \return true if the system has been marked, false otherwise
*/
template <typename TSystem>
template<typename TSystem>
bool mark_system() noexcept;

/**
Expand All @@ -123,15 +124,15 @@ namespace antara::gaming::ecs
* \details This function recursively calls the mark_system function
* \see mark_system
*/
template <typename ... TSystems>
template<typename ... TSystems>
bool mark_systems() noexcept;

/**
* \note This function enable a system
* \tparam TSystem Represents the system that needs to be enabled.
* \return true if the system has been enabled, false otherwise
*/
template <typename TSystem>
template<typename TSystem>
bool enable_system() noexcept;

/**
Expand All @@ -141,7 +142,7 @@ namespace antara::gaming::ecs
* \details This function recursively calls the enable_system function
* \see enable_system
*/
template <typename ... TSystems>
template<typename ... TSystems>
bool enable_systems() noexcept;

/**
Expand All @@ -150,7 +151,7 @@ namespace antara::gaming::ecs
* \return true if the the system has been disabled, false otherwise
* \attention If you deactivate a system, it will not be destroyed but simply ignore during the game loop
*/
template <typename TSystem>
template<typename TSystem>
bool disable_system() noexcept;

/**
Expand All @@ -159,7 +160,7 @@ namespace antara::gaming::ecs
* \return true if the list of systems has been disabled, false otherwise
* \details This function recursively calls the disable_system function
*/
template <typename ... TSystems>
template<typename ... TSystems>
bool disable_systems() noexcept;

/**
Expand Down Expand Up @@ -208,7 +209,7 @@ namespace antara::gaming::ecs
clock::time_point start_{clock::now()};
timer::time_step timestep_;
[[maybe_unused]] entt::registry &entity_registry_;
[[maybe_unused]] entt::dispatcher &dispatcher_;
[[maybe_unused]] entt::dispatcher &dispatcher_;
system_registry systems_{{}};
bool need_to_sweep_systems_{false};
};
Expand All @@ -220,20 +221,17 @@ namespace antara::gaming::ecs
template<typename TSystem>
const TSystem &system_manager::get_system() const noexcept
{
const auto ret = get_system_<TSystem>().or_else([](const std::error_code &ec) {
//! TODO: error handling for get_system (const and non const)
static_cast<void>(ec);
//this->dispatcher_.trigger<event::fatal_error_occured>(ec);
const auto ret = get_system_<TSystem>().or_else([this](const std::error_code &ec) {
this->dispatcher_.trigger<event::fatal_error>(ec);
});
return (*ret).get();
}

template<typename TSystem>
TSystem &system_manager::get_system() noexcept
{
auto ret = get_system_<TSystem>().or_else([](const std::error_code &ec) {
static_cast<void>(ec);
//this->dispatcher_.trigger<event::fatal_error_occured>(ec);
auto ret = get_system_<TSystem>().or_else([this](const std::error_code &ec) {
this->dispatcher_.trigger<event::fatal_error>(ec);
});
return (*ret).get();
}
Expand Down Expand Up @@ -287,7 +285,7 @@ namespace antara::gaming::ecs
return (has_system<TSystems>() && ...);
}

template <typename TSystem>
template<typename TSystem>
bool system_manager::mark_system() noexcept
{
if (has_system<TSystem>()) {
Expand All @@ -299,13 +297,13 @@ namespace antara::gaming::ecs
return false;
}

template <typename... TSystems>
template<typename... TSystems>
bool system_manager::mark_systems() noexcept
{
return (mark_system<TSystems>() && ...);
}

template <typename TSystem>
template<typename TSystem>
bool system_manager::enable_system() noexcept
{
if (has_system<TSystem>()) {
Expand All @@ -315,13 +313,13 @@ namespace antara::gaming::ecs
return false;
}

template <typename... TSystems>
template<typename... TSystems>
bool system_manager::enable_systems() noexcept
{
return (enable_system<TSystems>() && ...);
}

template <typename TSystem>
template<typename TSystem>
bool system_manager::disable_system() noexcept
{
if (has_system<TSystem>()) {
Expand All @@ -331,7 +329,7 @@ namespace antara::gaming::ecs
return false;
}

template <typename... TSystems>
template<typename... TSystems>
bool system_manager::disable_systems() noexcept
{
return (disable_system<TSystems>() && ...);
Expand Down
2 changes: 1 addition & 1 deletion modules/event/antara/gaming/event/fatal.error.event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace antara::gaming::event
{
struct fatal_error
{
explicit fatal_error(std::error_code ec);
fatal_error(std::error_code ec);
std::error_code ec_;
};
}
2 changes: 1 addition & 1 deletion modules/event/antara/gaming/event/quit.game.event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace antara::gaming::event
{
struct quit_game
{
explicit quit_game(int return_value = 0) noexcept;
quit_game(int return_value = 0) noexcept;
int return_value_;
};
}

0 comments on commit a7d169a

Please sign in to comment.