summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/CMakeLists.txt3
-rw-r--r--sim/include/kurator/sim/Battle.h29
-rw-r--r--sim/include/kurator/sim/FloatingMovement.h5
-rw-r--r--sim/include/kurator/sim/State.h3
-rw-r--r--sim/include/kurator/sim/System.h4
-rw-r--r--sim/include/kurator/sim/TurretControl.h4
-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
18 files changed, 29 insertions, 192 deletions
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 <memory>
-
-#include <kurator/engine/Context.h>
-#include <kurator/campaign/Scenario.h>
-
-
-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<Battle>;
-
-
-} // 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 <kurator/engine/Context.h>
#include <kurator/engine/Point.h>
+#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 <kurator/engine/Camera.h>
#include <kurator/engine/Clock.h>
-#include <kurator/engine/Context.h>
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 <functional>
-#include <kurator/engine/Context.h>
+#include "State.h"
namespace kurator
@@ -11,7 +11,7 @@ namespace sim
{
-using System = std::function<void(engine::Context&)>;
+using System = std::function<void(State&)>;
} // 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 <entt/entity/entity.hpp>
-#include <kurator/engine/Context.h>
+#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 <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