diff options
author | Aki <please@ignore.pl> | 2023-02-13 22:52:18 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-02-13 22:52:42 +0100 |
commit | 2a9f378c66b28cef1c5ee063cf4d7e4e2889076e (patch) | |
tree | d678fce067c527052462adf91909f23664ca0544 /sim/src/BaseBattle.cpp | |
parent | 03bb1614c25a56ef6225db09c4c59b7a5f8fa808 (diff) | |
download | kurator-2a9f378c66b28cef1c5ee063cf4d7e4e2889076e.zip kurator-2a9f378c66b28cef1c5ee063cf4d7e4e2889076e.tar.gz kurator-2a9f378c66b28cef1c5ee063cf4d7e4e2889076e.tar.bz2 |
Created sim::State object to hold overall state of simulation
This is seems like it creats even more chaotic binding between the
components but it is a very nice and testable intermediate step
before moving everything to standalone systems and shoving state into
the... well, State.
Diffstat (limited to 'sim/src/BaseBattle.cpp')
-rw-r--r-- | sim/src/BaseBattle.cpp | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 888379e..916a9f8 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -7,6 +7,7 @@ #include <kurator/engine/Context.h> #include <kurator/campaign/Scenario.h> +#include <kurator/sim.h> #include <kurator/sim/components.h> #include <kurator/sim/FloatingMovement.h> #include <kurator/sim/systems.h> @@ -23,45 +24,24 @@ namespace sim { -static void setup_scenario(entt::registry& registry, const campaign::Scenario& scenario); - - -BaseBattle::BaseBattle(const campaign::Scenario& scenario) : - _registry {} -{ - setup_scenario(_registry, scenario); - manager.extend(_registry); -} - - -void -setup_scenario(entt::registry& registry, const campaign::Scenario& scenario) +BaseBattle::BaseBattle(const campaign::Scenario& scenario) { - RandomSpawner spawner {scenario.last_team(), scenario.radius, 0.1}; - Builder build {registry, spawner}; - for (const auto& ship : scenario.ships) { - const auto entity = build(ship.loadout.type, ship.team); - registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier); - auto& state = registry.get<AIState>(entity); - for (const auto& turret_type : ship.loadout.turrets) { - build(turret_type, entity); - state.keep_at_range = std::min(state.keep_at_range, turret_type.optimal_range); - } - } + load_scenario(state, scenario); + manager.extend(state.registry); } -entt::registry& -BaseBattle::registry() +engine::Context +BaseBattle::context() { - return _registry; + return state; } -entt::dispatcher& -BaseBattle::dispatcher() +engine::ConstContext +BaseBattle::const_context() const { - return _dispatcher; + return state; } @@ -80,9 +60,9 @@ BaseBattle::update(engine::Context& ctx) void BaseBattle::pick_random_targets() { - auto view = _registry.view<Team, AIState>(); + auto view = state.registry.view<Team, AIState>(); for (auto&& [entity, team, ai] : view.each()) { - if (!_registry.valid(ai.target)) + if (!state.registry.valid(ai.target)) ai.target = manager.random(team.id); } } |