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/CMakeLists.txt | 3 -- sim/include/kurator/sim/Battle.h | 29 ------------------- sim/include/kurator/sim/FloatingMovement.h | 5 ++-- sim/include/kurator/sim/State.h | 3 -- sim/include/kurator/sim/System.h | 4 +-- sim/include/kurator/sim/TurretControl.h | 4 +-- 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 +++--- 18 files changed, 29 insertions(+), 192 deletions(-) delete mode 100644 sim/include/kurator/sim/Battle.h 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') diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt index a221d2f..a0a4d00 100644 --- a/sim/CMakeLists.txt +++ b/sim/CMakeLists.txt @@ -1,15 +1,12 @@ project(sim) add_library( ${PROJECT_NAME} STATIC - src/BaseBattle.cpp src/BaseSimulation.cpp - src/Battle.cpp src/Builder.cpp src/FloatingMovement.cpp src/HitPoints.cpp src/RandomSpawner.cpp src/sim.cpp - src/State.cpp src/systems.cpp src/TeamManager.cpp src/TurretControl.cpp diff --git a/sim/include/kurator/sim/Battle.h b/sim/include/kurator/sim/Battle.h deleted file mode 100644 index 1692c0c..0000000 --- a/sim/include/kurator/sim/Battle.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include -#include - - -namespace kurator -{ -namespace sim -{ - - -class Battle -{ -public: - virtual ~Battle() = default; - virtual engine::Context context() = 0; - virtual engine::ConstContext const_context() const = 0; - virtual void update(engine::Context& ctx) = 0; -}; - - -auto prepare(const campaign::Scenario& scenario) -> std::unique_ptr; - - -} // namespace sim -} // namespace kurator diff --git a/sim/include/kurator/sim/FloatingMovement.h b/sim/include/kurator/sim/FloatingMovement.h index 4239d99..ff40e23 100644 --- a/sim/include/kurator/sim/FloatingMovement.h +++ b/sim/include/kurator/sim/FloatingMovement.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "State.h" + namespace kurator { @@ -17,7 +18,7 @@ struct FloatingMovement double deceleration; double destination_boundary = 100.0; engine::Point speed = {0.0, 0.0}; - static void update(engine::Context& ctx); + static void update(State& ctx); }; diff --git a/sim/include/kurator/sim/State.h b/sim/include/kurator/sim/State.h index 8449ad2..fc7c54a 100644 --- a/sim/include/kurator/sim/State.h +++ b/sim/include/kurator/sim/State.h @@ -5,7 +5,6 @@ #include #include -#include namespace kurator @@ -20,8 +19,6 @@ struct State entt::dispatcher dispatcher; engine::Clock clock; engine::Camera camera; // does not fit in here really - operator engine::Context(); - operator engine::ConstContext() const; }; diff --git a/sim/include/kurator/sim/System.h b/sim/include/kurator/sim/System.h index 101812a..d4b744c 100644 --- a/sim/include/kurator/sim/System.h +++ b/sim/include/kurator/sim/System.h @@ -2,7 +2,7 @@ #include -#include +#include "State.h" namespace kurator @@ -11,7 +11,7 @@ namespace sim { -using System = std::function; +using System = std::function; } // namespace sim diff --git a/sim/include/kurator/sim/TurretControl.h b/sim/include/kurator/sim/TurretControl.h index 323b54b..731f30e 100644 --- a/sim/include/kurator/sim/TurretControl.h +++ b/sim/include/kurator/sim/TurretControl.h @@ -2,7 +2,7 @@ #include -#include +#include "State.h" namespace kurator @@ -17,7 +17,7 @@ struct TurretControl double reload; int rounds; entt::entity owner; - static void update(engine::Context& ctx); + static void update(State& ctx); }; 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