diff options
Diffstat (limited to 'sim/src')
-rw-r--r-- | sim/src/BaseBattle.cpp | 44 | ||||
-rw-r--r-- | sim/src/BaseBattle.h | 11 | ||||
-rw-r--r-- | sim/src/State.cpp | 25 | ||||
-rw-r--r-- | sim/src/sim.cpp | 36 |
4 files changed, 77 insertions, 39 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); } } diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h index 77e1d10..6f59457 100644 --- a/sim/src/BaseBattle.h +++ b/sim/src/BaseBattle.h @@ -1,11 +1,9 @@ #pragma once -#include <entt/entity/registry.hpp> -#include <entt/signal/dispatcher.hpp> - #include <kurator/engine/Context.h> #include <kurator/campaign/Scenario.h> #include <kurator/sim/Battle.h> +#include <kurator/sim/State.h> #include "TeamManager.h" @@ -20,12 +18,11 @@ class BaseBattle : public Battle { public: BaseBattle(const campaign::Scenario& scenario); - entt::registry& registry() override; - entt::dispatcher& dispatcher() override; + engine::Context context() override; + engine::ConstContext const_context() const override; void update(engine::Context& ctx) override; private: - entt::registry _registry; - entt::dispatcher _dispatcher; + State state; TeamManager manager; void pick_random_targets(); }; diff --git a/sim/src/State.cpp b/sim/src/State.cpp new file mode 100644 index 0000000..3c8a709 --- /dev/null +++ b/sim/src/State.cpp @@ -0,0 +1,25 @@ +#include <kurator/sim/State.h> + +#include <kurator/engine/Context.h> + + +namespace kurator +{ +namespace sim +{ + + +State::operator engine::Context() +{ + return {registry, dispatcher, clock, camera}; +} + + +State::operator engine::ConstContext() const +{ + return {registry, dispatcher, clock, camera}; +} + + +} // namespace sim +} // namespace kurator diff --git a/sim/src/sim.cpp b/sim/src/sim.cpp new file mode 100644 index 0000000..f915d20 --- /dev/null +++ b/sim/src/sim.cpp @@ -0,0 +1,36 @@ +#include <kurator/sim.h> + +#include <kurator/campaign/Scenario.h> +#include <kurator/sim/components.h> +#include <kurator/sim/State.h> +#include <kurator/universe/UniqueIdentifier.h> + +#include "Builder.h" +#include "RandomSpawner.h" + + +namespace kurator +{ +namespace sim +{ + + +void +load_scenario(State& ctx, const campaign::Scenario& scenario) +{ + RandomSpawner spawner {scenario.last_team(), scenario.radius, 0.1}; + Builder build {ctx.registry, spawner}; + for (const auto& ship : scenario.ships) { + const auto entity = build(ship.loadout.type, ship.team); + ctx.registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier); + auto& state = ctx.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); + } + } +} + + +} // namespace sim +} // namespace kurator |