summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-14 00:51:49 +0100
committerAki <please@ignore.pl>2023-02-14 00:51:49 +0100
commitdc0cc293b7b8efed67a0a550237dce38f33ff37d (patch)
tree83a6cf40ecd76b49f590dd669626b439cf34d64e /sim/src
parent632c367ae6885657e6c99b96b8bf7a96b61a2bb9 (diff)
downloadkurator-dc0cc293b7b8efed67a0a550237dce38f33ff37d.zip
kurator-dc0cc293b7b8efed67a0a550237dce38f33ff37d.tar.gz
kurator-dc0cc293b7b8efed67a0a550237dce38f33ff37d.tar.bz2
Replaced Context+Battle combo with State and arbitrary Systems
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp46
-rw-r--r--sim/src/BaseBattle.h32
-rw-r--r--sim/src/BaseSimulation.cpp5
-rw-r--r--sim/src/BaseSimulation.h3
-rw-r--r--sim/src/Battle.cpp24
-rw-r--r--sim/src/FloatingMovement.cpp4
-rw-r--r--sim/src/State.cpp25
-rw-r--r--sim/src/TeamManager.cpp8
-rw-r--r--sim/src/TeamManager.h6
-rw-r--r--sim/src/TurretControl.cpp4
-rw-r--r--sim/src/systems.cpp8
-rw-r--r--sim/src/systems.h8
12 files changed, 22 insertions, 151 deletions
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 <entt/entity/registry.hpp>
-#include <entt/signal/dispatcher.hpp>
-
-#include <kurator/engine/Context.h>
-#include <kurator/campaign/Scenario.h>
-#include <kurator/sim.h>
-
-
-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 <kurator/engine/Context.h>
-#include <kurator/campaign/Scenario.h>
-#include <kurator/sim/Battle.h>
-#include <kurator/sim/State.h>
-#include <kurator/sim/System.h>
-
-#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 <kurator/engine/Context.h>
#include <kurator/sim/State.h>
#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/TurretControl.h>
@@ -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 <kurator/engine/Context.h>
#include <kurator/sim/State.h>
#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 <kurator/sim/Battle.h>
-
-#include <memory>
-
-#include <kurator/campaign/Scenario.h>
-
-#include "BaseBattle.h"
-
-
-namespace kurator
-{
-namespace sim
-{
-
-
-std::unique_ptr<Battle>
-prepare(const campaign::Scenario& scenario)
-{
- return std::make_unique<BaseBattle>(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 <kurator/sim/FloatingMovement.h>
-#include <kurator/engine/Context.h>
#include <kurator/sim/components.h>
+#include <kurator/sim/State.h>
namespace kurator
@@ -11,7 +11,7 @@ namespace sim
void
-FloatingMovement::update(engine::Context& ctx)
+FloatingMovement::update(State& ctx)
{
auto view = ctx.registry.view<Transform, FloatingMovement, AIState>();
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 <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/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 <entt/entity/registry.hpp>
-#include <kurator/engine/Context.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
+#include <kurator/sim/State.h>
#include <kurator/universe/ShipType.h>
@@ -27,9 +27,9 @@ TeamManager::TeamManager() :
void
-TeamManager::extend(entt::registry& registry)
+TeamManager::extend(State& ctx)
{
- auto ships = registry.view<universe::ShipType, sim::Team>();
+ auto ships = ctx.registry.view<universe::ShipType, sim::Team>();
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 <entt/entity/registry.hpp>
-#include <kurator/engine/Context.h>
+#include <kurator/sim/State.h>
namespace kurator
@@ -19,10 +19,10 @@ class TeamManager
public:
using Team = std::vector<entt::entity>;
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<Team> 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 <kurator/sim/TurretControl.h>
-#include <kurator/engine/Context.h>
#include <kurator/sim/components.h>
#include <kurator/sim/HitPoints.h>
#include <kurator/sim/events.h>
+#include <kurator/sim/State.h>
#include <kurator/universe/TurretType.h>
@@ -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<TurretControl, universe::TurretType>();
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 <kurator/engine/Context.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
#include <kurator/sim/HitPoints.h>
+#include <kurator/sim/State.h>
#include <kurator/stats/events.h>
#include <kurator/universe/UniqueIdentifier.h>
@@ -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<Team, AIState>();
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<Transform, AIState>();
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<HitPoints>();
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 <kurator/engine/Context.h>
+#include <kurator/sim/State.h>
#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