From dc0cc293b7b8efed67a0a550237dce38f33ff37d Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 14 Feb 2023 00:51:49 +0100 Subject: Replaced Context+Battle combo with State and arbitrary Systems --- sim/src/BaseBattle.cpp | 46 -------------------------------------------- sim/src/BaseBattle.h | 32 ------------------------------ sim/src/BaseSimulation.cpp | 5 ++--- sim/src/BaseSimulation.h | 3 +-- sim/src/Battle.cpp | 24 ----------------------- sim/src/FloatingMovement.cpp | 4 ++-- sim/src/State.cpp | 25 ------------------------ sim/src/TeamManager.cpp | 8 ++++---- sim/src/TeamManager.h | 6 +++--- sim/src/TurretControl.cpp | 4 ++-- sim/src/systems.cpp | 8 ++++---- sim/src/systems.h | 8 ++++---- 12 files changed, 22 insertions(+), 151 deletions(-) delete mode 100644 sim/src/BaseBattle.cpp delete mode 100644 sim/src/BaseBattle.h delete mode 100644 sim/src/Battle.cpp delete mode 100644 sim/src/State.cpp (limited to 'sim/src') diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp deleted file mode 100644 index ee09740..0000000 --- a/sim/src/BaseBattle.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "BaseBattle.h" - -#include -#include - -#include -#include -#include - - -namespace kurator -{ -namespace sim -{ - - -BaseBattle::BaseBattle(const campaign::Scenario& scenario) : - state {load_scenario(scenario)}, - base {base_simulation_systems(state)} -{ -} - - -engine::Context -BaseBattle::context() -{ - return state; -} - - -engine::ConstContext -BaseBattle::const_context() const -{ - return state; -} - - -void -BaseBattle::update(engine::Context& ctx) -{ - base(ctx); -} - - -} // namespace sim -} // namespace kurator diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h deleted file mode 100644 index 3e98658..0000000 --- a/sim/src/BaseBattle.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "TeamManager.h" - - -namespace kurator -{ -namespace sim -{ - - -class BaseBattle : public Battle -{ -public: - explicit BaseBattle(const campaign::Scenario& scenario); - engine::Context context() override; - engine::ConstContext const_context() const override; - void update(engine::Context& ctx) override; -private: - State state; - System base; -}; - - -} // namespace sim -} // namespace kurator diff --git a/sim/src/BaseSimulation.cpp b/sim/src/BaseSimulation.cpp index 05b224d..545e9ce 100644 --- a/sim/src/BaseSimulation.cpp +++ b/sim/src/BaseSimulation.cpp @@ -1,6 +1,5 @@ #include "BaseSimulation.h" -#include #include #include #include @@ -17,12 +16,12 @@ namespace sim BaseSimulation::BaseSimulation(State& ctx) { - manager.extend(ctx.registry); + manager.extend(ctx); } void -BaseSimulation::operator()(engine::Context& ctx) +BaseSimulation::operator()(State& ctx) { pick_random_targets(ctx, manager); keep_at_range(ctx); diff --git a/sim/src/BaseSimulation.h b/sim/src/BaseSimulation.h index 4d73382..bdbcd68 100644 --- a/sim/src/BaseSimulation.h +++ b/sim/src/BaseSimulation.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include "TeamManager.h" @@ -16,7 +15,7 @@ class BaseSimulation { public: explicit BaseSimulation(State& ctx); - void operator()(engine::Context& ctx); + void operator()(State& ctx); private: TeamManager manager; }; diff --git a/sim/src/Battle.cpp b/sim/src/Battle.cpp deleted file mode 100644 index 4bbfcb6..0000000 --- a/sim/src/Battle.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include - -#include - -#include - -#include "BaseBattle.h" - - -namespace kurator -{ -namespace sim -{ - - -std::unique_ptr -prepare(const campaign::Scenario& scenario) -{ - return std::make_unique(scenario); -} - - -} // namespace sim -} // namespace kurator diff --git a/sim/src/FloatingMovement.cpp b/sim/src/FloatingMovement.cpp index da6cd20..39ec17c 100644 --- a/sim/src/FloatingMovement.cpp +++ b/sim/src/FloatingMovement.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include namespace kurator @@ -11,7 +11,7 @@ namespace sim void -FloatingMovement::update(engine::Context& ctx) +FloatingMovement::update(State& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, transform, movement, ai] : view.each()) { diff --git a/sim/src/State.cpp b/sim/src/State.cpp deleted file mode 100644 index 3c8a709..0000000 --- a/sim/src/State.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include - - -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/TeamManager.cpp b/sim/src/TeamManager.cpp index 778cd18..7107b07 100644 --- a/sim/src/TeamManager.cpp +++ b/sim/src/TeamManager.cpp @@ -7,9 +7,9 @@ #include -#include #include #include +#include #include @@ -27,9 +27,9 @@ TeamManager::TeamManager() : void -TeamManager::extend(entt::registry& registry) +TeamManager::extend(State& ctx) { - auto ships = registry.view(); + auto ships = ctx.registry.view(); for (const auto& [entity, type, team] : ships.each()) add(team.id, entity); } @@ -62,7 +62,7 @@ TeamManager::random(const int exclude) void -TeamManager::update(engine::Context& ctx) +TeamManager::update(State& ctx) { for (auto& members : teams) { auto is_valid = [&](entt::entity entity){ return !ctx.registry.valid(entity); }; diff --git a/sim/src/TeamManager.h b/sim/src/TeamManager.h index 7f53510..d708745 100644 --- a/sim/src/TeamManager.h +++ b/sim/src/TeamManager.h @@ -5,7 +5,7 @@ #include -#include +#include namespace kurator @@ -19,10 +19,10 @@ class TeamManager public: using Team = std::vector; TeamManager(); - void extend(entt::registry& registry); + void extend(State& ctx); void add(int team, entt::entity entity); entt::entity random(int exclude); - void update(engine::Context& ctx); + void update(State& ctx); private: std::vector teams; std::mt19937 generator; diff --git a/sim/src/TurretControl.cpp b/sim/src/TurretControl.cpp index fa42bf5..ba54f3f 100644 --- a/sim/src/TurretControl.cpp +++ b/sim/src/TurretControl.cpp @@ -1,9 +1,9 @@ #include -#include #include #include #include +#include #include @@ -17,7 +17,7 @@ bool consume(float& dt, double& target); void -TurretControl::update(engine::Context& ctx) +TurretControl::update(State& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, control, def] : view.each()) { diff --git a/sim/src/systems.cpp b/sim/src/systems.cpp index 4dc1e71..c6f997a 100644 --- a/sim/src/systems.cpp +++ b/sim/src/systems.cpp @@ -1,9 +1,9 @@ #include "systems.h" -#include #include #include #include +#include #include #include @@ -15,7 +15,7 @@ namespace sim void -pick_random_targets(engine::Context& ctx, TeamManager& manager) +pick_random_targets(State& ctx, TeamManager& manager) { auto view = ctx.registry.view(); for (auto&& [entity, team, ai] : view.each()) { @@ -26,7 +26,7 @@ pick_random_targets(engine::Context& ctx, TeamManager& manager) void -keep_at_range(engine::Context& ctx) +keep_at_range(State& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, self, ai] : view.each()) { @@ -40,7 +40,7 @@ keep_at_range(engine::Context& ctx) void -kill_off_dead(engine::Context& ctx) +kill_off_dead(State& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, points] : view.each()) { diff --git a/sim/src/systems.h b/sim/src/systems.h index 4c8838b..396ebb2 100644 --- a/sim/src/systems.h +++ b/sim/src/systems.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "TeamManager.h" @@ -11,9 +11,9 @@ namespace sim { -void pick_random_targets(engine::Context& ctx, TeamManager& manager); -void keep_at_range(engine::Context& ctx); -void kill_off_dead(engine::Context& ctx); +void pick_random_targets(State& ctx, TeamManager& manager); +void keep_at_range(State& ctx); +void kill_off_dead(State& ctx); } // namespace sim -- cgit v1.1