Skip to content

Commit

Permalink
Merge pull request #10 from KomodoPlatform/roman_dev
Browse files Browse the repository at this point in the history
feat(ecs): integrate timer usage
  • Loading branch information
Milerius authored Sep 13, 2019
2 parents de44002 + 4d1fa23 commit 37865f7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 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)
target_link_libraries(antara_ecs_shared_sources INTERFACE EnTT strong_type expected range-v3 antara::refl-cpp antara::default_settings antara::timer)
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 @@ -102,7 +102,9 @@ namespace antara::gaming::ecs::tests
CHECK(manager.enable_system<pre_concrete_system>());

CHECK(manager.disable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_EQ(manager.update(), 0ull);
CHECK(manager.enable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_GE(manager.update(), 1ull);
}

TEST_CASE("get single system")
Expand Down Expand Up @@ -133,6 +135,8 @@ namespace antara::gaming::ecs::tests
CHECK_FALSE(manager.has_systems<logic_concrete_system, pre_concrete_system>());
CHECK_FALSE(manager.enable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_FALSE(manager.disable_systems<logic_concrete_system, pre_concrete_system>());
CHECK_EQ(0ull, manager.update());
CHECK_EQ(0ull, manager.nb_systems());
}
}
}
18 changes: 17 additions & 1 deletion modules/ecs/antara/gaming/ecs/system.manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,26 @@ namespace antara::gaming::ecs

std::size_t system_manager::update() noexcept
{
if (!nb_systems())
return 0u;

size_t nb_systems_updated = 0u;
timestep_.start_frame();
nb_systems_updated += update_systems(system_type::pre_update);

//LCOV_EXCL_START
while (timestep_.is_update_required()) {
nb_systems_updated += update_systems(system_type::logic_update);
timestep_.perform_update();
}
//LCOV_EXCL_STOP

nb_systems_updated += update_systems(system_type::post_update);

if (need_to_sweep_systems_) {
sweep_systems_();
}
return 0;
return nb_systems_updated;
}

std::size_t system_manager::update_systems(system_type system_type_to_update) noexcept
Expand Down
10 changes: 8 additions & 2 deletions modules/ecs/antara/gaming/ecs/system.manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "antara/gaming/ecs/base.system.hpp"
#include "antara/gaming/ecs/system.hpp"
#include "antara/gaming/ecs/system.type.hpp"
#include "antara/gaming/timer/time.step.hpp"

namespace antara::gaming::ecs
{
Expand Down Expand Up @@ -203,6 +204,9 @@ namespace antara::gaming::ecs
[[nodiscard]] tl::expected<std::reference_wrapper<const TSystem>, std::error_code> get_system_() const noexcept;

//! Private data members
using clock = std::chrono::steady_clock;
clock::time_point start_{clock::now()};
timer::time_step timestep_;
[[maybe_unused]] entt::registry &entity_registry_;
[[maybe_unused]] entt::dispatcher &dispatcher_;
system_registry systems_{{}};
Expand All @@ -216,8 +220,9 @@ namespace antara::gaming::ecs
template<typename TSystem>
const TSystem &system_manager::get_system() const noexcept
{
const auto ret = get_system_<TSystem>().or_else([this](const std::error_code &ec) {
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);
});
return (*ret).get();
Expand All @@ -226,7 +231,8 @@ namespace antara::gaming::ecs
template<typename TSystem>
TSystem &system_manager::get_system() noexcept
{
auto ret = get_system_<TSystem>().or_else([this](const std::error_code &ec) {
auto ret = get_system_<TSystem>().or_else([](const std::error_code &ec) {
static_cast<void>(ec);
//this->dispatcher_.trigger<event::fatal_error_occured>(ec);
});
return (*ret).get();
Expand Down

0 comments on commit 37865f7

Please sign in to comment.