summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-11 17:26:49 +0100
committerAki <please@ignore.pl>2023-02-11 17:26:49 +0100
commita5266d3e5da1d9ee9f873124674c68843a407ac0 (patch)
tree18a91419c4bdf37e7333a17bfb804e53fb92764a /sim/src
parente66011756340e03fe941723f762119ed78ec2402 (diff)
downloadkurator-a5266d3e5da1d9ee9f873124674c68843a407ac0.zip
kurator-a5266d3e5da1d9ee9f873124674c68843a407ac0.tar.gz
kurator-a5266d3e5da1d9ee9f873124674c68843a407ac0.tar.bz2
Context is now used in sim systems
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp9
-rw-r--r--sim/src/BaseBattle.h8
-rw-r--r--sim/src/BaseBattle.inl.h19
-rw-r--r--sim/src/FloatingMovement.cpp14
-rw-r--r--sim/src/TurretControl.cpp26
5 files changed, 25 insertions, 51 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 3e3815c..e34af76 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -5,6 +5,7 @@
#include <entt/entity/registry.hpp>
#include <entt/signal/dispatcher.hpp>
+#include <kurator/engine/Context.h>
#include <kurator/campaign/Scenario.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
@@ -57,13 +58,13 @@ BaseBattle::dispatcher()
void
-BaseBattle::update(const float dt)
+BaseBattle::update(engine::Context& ctx)
{
- time += dt;
+ time = ctx.clock.game;
pick_random_targets();
keep_at_range();
- update<FloatingMovement>(dt);
- update<TurretControl>(dt);
+ FloatingMovement::update(ctx);
+ TurretControl::update(ctx);
kill_off_dead();
manager.clear(_registry); // registry supports on destructions events
manager.update(_dispatcher);
diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h
index b20b518..d67f33e 100644
--- a/sim/src/BaseBattle.h
+++ b/sim/src/BaseBattle.h
@@ -3,6 +3,7 @@
#include <entt/entity/registry.hpp>
#include <entt/signal/dispatcher.hpp>
+#include <kurator/engine/Context.h>
#include <kurator/campaign/Scenario.h>
#include <kurator/sim/Battle.h>
@@ -22,9 +23,8 @@ public:
BaseBattle(const campaign::Scenario& scenario);
entt::registry& registry() override;
entt::dispatcher& dispatcher() override;
- void update(float dt) override;
+ void update(engine::Context& ctx) override;
private:
- template <typename System> void update(float dt);
double time;
entt::registry _registry;
entt::dispatcher _dispatcher;
@@ -32,13 +32,9 @@ private:
TeamManager manager;
void pick_random_targets();
void keep_at_range();
- void turrets(float dt);
void kill_off_dead();
};
} // namespace sim
} // namespace kurator
-
-
-#include "BaseBattle.inl.h"
diff --git a/sim/src/BaseBattle.inl.h b/sim/src/BaseBattle.inl.h
deleted file mode 100644
index 8014cb3..0000000
--- a/sim/src/BaseBattle.inl.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-
-namespace kurator
-{
-namespace sim
-{
-
-
-template <typename System>
-void
-BaseBattle::update(const float dt)
-{
- System::update(_registry, _dispatcher, dt);
-}
-
-
-} // namespace sim
-} // namespace kurator
diff --git a/sim/src/FloatingMovement.cpp b/sim/src/FloatingMovement.cpp
index e1794d5..da6cd20 100644
--- a/sim/src/FloatingMovement.cpp
+++ b/sim/src/FloatingMovement.cpp
@@ -1,8 +1,6 @@
#include <kurator/sim/FloatingMovement.h>
-#include <entt/entity/registry.hpp>
-#include <entt/signal/dispatcher.hpp>
-
+#include <kurator/engine/Context.h>
#include <kurator/sim/components.h>
@@ -13,21 +11,21 @@ namespace sim
void
-FloatingMovement::update(entt::registry& registry, entt::dispatcher&, const float dt)
+FloatingMovement::update(engine::Context& ctx)
{
- auto view = registry.view<Transform, FloatingMovement, AIState>();
+ auto view = ctx.registry.view<Transform, FloatingMovement, AIState>();
for (auto&& [entity, transform, movement, ai] : view.each()) {
const auto offset = ai.destination - transform.position;
const auto at_destination = offset.magnitude() > movement.destination_boundary;
const auto acceleration =
at_destination ?
- offset.normalized().scale(movement.acceleration * dt) :
- offset.normalized().scale(-1 * movement.deceleration * dt);
+ offset.normalized().scale(movement.acceleration * ctx.clock.dt) :
+ offset.normalized().scale(-1 * movement.deceleration * ctx.clock.dt);
movement.speed.x += acceleration.x;
movement.speed.y += acceleration.y;
if (movement.speed.magnitude() > movement.max_speed)
movement.speed = movement.speed.normalized().scale(movement.max_speed);
- const auto speed = movement.speed.scale(dt);
+ const auto speed = movement.speed.scale(ctx.clock.dt);
transform.position.x += speed.x;
transform.position.y += speed.y;
transform.angle = speed.angle();
diff --git a/sim/src/TurretControl.cpp b/sim/src/TurretControl.cpp
index bfac27f..fa42bf5 100644
--- a/sim/src/TurretControl.cpp
+++ b/sim/src/TurretControl.cpp
@@ -1,8 +1,6 @@
#include <kurator/sim/TurretControl.h>
-#include <entt/entity/registry.hpp>
-#include <entt/signal/dispatcher.hpp>
-
+#include <kurator/engine/Context.h>
#include <kurator/sim/components.h>
#include <kurator/sim/HitPoints.h>
#include <kurator/sim/events.h>
@@ -19,33 +17,33 @@ bool consume(float& dt, double& target);
void
-TurretControl::update(entt::registry& registry, entt::dispatcher& dispatcher, const float dt)
+TurretControl::update(engine::Context& ctx)
{
- auto view = registry.view<TurretControl, universe::TurretType>();
+ auto view = ctx.registry.view<TurretControl, universe::TurretType>();
for (auto&& [entity, control, def] : view.each()) {
- if (!registry.valid(control.owner)) {
- registry.destroy(entity);
+ if (!ctx.registry.valid(control.owner)) {
+ ctx.registry.destroy(entity);
continue;
}
- if (!registry.all_of<AIState, Transform>(control.owner))
+ if (!ctx.registry.all_of<AIState, Transform>(control.owner))
continue;
- const auto& [state, transform] = registry.get<AIState, Transform>(control.owner);
- if (!registry.valid(state.target))
+ const auto& [state, transform] = ctx.registry.get<AIState, Transform>(control.owner);
+ if (!ctx.registry.valid(state.target))
continue;
- const auto& target = registry.get<Transform>(state.target);
+ const auto& target = ctx.registry.get<Transform>(state.target);
const auto distance = transform.position.distance(target.position);
if (distance > def.effective_range())
continue;
- auto remaining_dt = dt;
+ auto remaining_dt = ctx.clock.dt;
while (remaining_dt > 0.0) {
if (control.rounds < 1 && consume(remaining_dt, control.reload))
control.rounds = def.rounds;
if (control.rounds > 0 && consume(remaining_dt, control.delay)) {
- auto& target_points = registry.get<HitPoints>(state.target);
+ auto& target_points = ctx.registry.get<HitPoints>(state.target);
auto damage = def.effective_damage(distance);
if (damage > 0.0) {
damage = target_points.deal(damage);
- dispatcher.trigger(Hit{damage, control.owner, state.target});
+ ctx.dispatcher.trigger(Hit{damage, control.owner, state.target});
}
control.delay = def.rate_of_fire;
if (--control.rounds < 1)