summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-13 01:06:31 +0100
committerAki <please@ignore.pl>2023-02-13 01:06:31 +0100
commit03bb1614c25a56ef6225db09c4c59b7a5f8fa808 (patch)
tree11216b0104103d07ebbe7a707c967c42ccc93c3e /sim/src
parent6f8db05c02f941ce75da34e3c50c987d03c23e54 (diff)
downloadkurator-03bb1614c25a56ef6225db09c4c59b7a5f8fa808.zip
kurator-03bb1614c25a56ef6225db09c4c59b7a5f8fa808.tar.gz
kurator-03bb1614c25a56ef6225db09c4c59b7a5f8fa808.tar.bz2
Externalized part of simulation systems
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp39
-rw-r--r--sim/src/systems.cpp49
2 files changed, 50 insertions, 38 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 0c23065..888379e 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -8,11 +8,9 @@
#include <kurator/engine/Context.h>
#include <kurator/campaign/Scenario.h>
#include <kurator/sim/components.h>
-#include <kurator/sim/events.h>
#include <kurator/sim/FloatingMovement.h>
-#include <kurator/sim/HitPoints.h>
+#include <kurator/sim/systems.h>
#include <kurator/sim/TurretControl.h>
-#include <kurator/stats/events.h>
#include <kurator/universe/UniqueIdentifier.h>
#include "Builder.h"
@@ -67,10 +65,6 @@ BaseBattle::dispatcher()
}
-static void keep_at_range(engine::Context& ctx);
-static void kill_off_dead(engine::Context& ctx);
-
-
void
BaseBattle::update(engine::Context& ctx)
{
@@ -94,36 +88,5 @@ BaseBattle::pick_random_targets()
}
-void
-keep_at_range(engine::Context& ctx)
-{
- auto view = ctx.registry.view<Transform, AIState>();
- for (auto&& [entity, self, ai] : view.each()) {
- if (!ctx.registry.valid(ai.target))
- continue;
- const auto target = ctx.registry.get<Transform>(ai.target);
- const auto offset = target.position - self.position;
- ai.destination = target.position - offset.normalized().scale(ai.keep_at_range);
- }
-}
-
-
-void
-kill_off_dead(engine::Context& ctx)
-{
- auto view = ctx.registry.view<HitPoints>();
- for (auto&& [entity, points] : view.each()) {
- if (points.is_alive())
- continue;
- if (ctx.registry.all_of<universe::UniqueIdentifier, Team>(entity)) {
- const auto& [identifier, team] = ctx.registry.get<universe::UniqueIdentifier, Team>(entity);
- ctx.dispatcher.trigger(stats::ShipLeft{ctx.clock.game, identifier, team.id, true});
- ctx.dispatcher.trigger(Destroyed{entity});
- }
- ctx.registry.destroy(entity);
- }
-}
-
-
} // namespace sim
} // namespace kurator
diff --git a/sim/src/systems.cpp b/sim/src/systems.cpp
new file mode 100644
index 0000000..114ed2f
--- /dev/null
+++ b/sim/src/systems.cpp
@@ -0,0 +1,49 @@
+#include <kurator/sim/systems.h>
+
+#include <kurator/engine/Context.h>
+#include <kurator/sim/components.h>
+#include <kurator/sim/events.h>
+#include <kurator/sim/HitPoints.h>
+#include <kurator/stats/events.h>
+#include <kurator/universe/UniqueIdentifier.h>
+
+
+namespace kurator
+{
+namespace sim
+{
+
+
+void
+keep_at_range(engine::Context& ctx)
+{
+ auto view = ctx.registry.view<Transform, AIState>();
+ for (auto&& [entity, self, ai] : view.each()) {
+ if (!ctx.registry.valid(ai.target))
+ continue;
+ const auto target = ctx.registry.get<Transform>(ai.target);
+ const auto offset = target.position - self.position;
+ ai.destination = target.position - offset.normalized().scale(ai.keep_at_range);
+ }
+}
+
+
+void
+kill_off_dead(engine::Context& ctx)
+{
+ auto view = ctx.registry.view<HitPoints>();
+ for (auto&& [entity, points] : view.each()) {
+ if (points.is_alive())
+ continue;
+ if (ctx.registry.all_of<universe::UniqueIdentifier, Team>(entity)) {
+ const auto& [identifier, team] = ctx.registry.get<universe::UniqueIdentifier, Team>(entity);
+ ctx.dispatcher.trigger(stats::ShipLeft{ctx.clock.game, identifier, team.id, true});
+ ctx.dispatcher.trigger(Destroyed{entity});
+ }
+ ctx.registry.destroy(entity);
+ }
+}
+
+
+} // namespace sim
+} // namespace kurator