diff options
-rw-r--r-- | kurator/src/Battle.cpp | 2 | ||||
-rw-r--r-- | sim/include/kurator/sim/Battle.h | 3 | ||||
-rw-r--r-- | sim/include/kurator/sim/FloatingMovement.h | 6 | ||||
-rw-r--r-- | sim/include/kurator/sim/TurretControl.h | 5 | ||||
-rw-r--r-- | sim/src/BaseBattle.cpp | 9 | ||||
-rw-r--r-- | sim/src/BaseBattle.h | 8 | ||||
-rw-r--r-- | sim/src/BaseBattle.inl.h | 19 | ||||
-rw-r--r-- | sim/src/FloatingMovement.cpp | 14 | ||||
-rw-r--r-- | sim/src/TurretControl.cpp | 26 |
9 files changed, 33 insertions, 59 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index b47c539..66a17bd 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -104,7 +104,7 @@ Battle::update() auto& registry = battle->registry(); clock.update(); engine::Context ctx {registry, battle->dispatcher(), clock, camera}; - battle->update(clock.dt); + battle->update(ctx); progress_timers(ctx); move_ui_pops(ctx); blink_crosses(ctx); diff --git a/sim/include/kurator/sim/Battle.h b/sim/include/kurator/sim/Battle.h index 0b20ce8..6874b39 100644 --- a/sim/include/kurator/sim/Battle.h +++ b/sim/include/kurator/sim/Battle.h @@ -5,6 +5,7 @@ #include <entt/entity/registry.hpp> #include <entt/signal/dispatcher.hpp> +#include <kurator/engine/Context.h> #include <kurator/campaign/Scenario.h> @@ -20,7 +21,7 @@ public: virtual ~Battle() = default; virtual entt::registry& registry() = 0; virtual entt::dispatcher& dispatcher() = 0; - virtual void update(float dt) = 0; + virtual void update(engine::Context& ctx) = 0; }; diff --git a/sim/include/kurator/sim/FloatingMovement.h b/sim/include/kurator/sim/FloatingMovement.h index d7e8479..4239d99 100644 --- a/sim/include/kurator/sim/FloatingMovement.h +++ b/sim/include/kurator/sim/FloatingMovement.h @@ -1,8 +1,6 @@ #pragma once -#include <entt/entity/registry.hpp> -#include <entt/signal/dispatcher.hpp> - +#include <kurator/engine/Context.h> #include <kurator/engine/Point.h> @@ -19,7 +17,7 @@ struct FloatingMovement double deceleration; double destination_boundary = 100.0; engine::Point speed = {0.0, 0.0}; - static void update(entt::registry& registry, entt::dispatcher& dispatcher, float dt); + static void update(engine::Context& ctx); }; diff --git a/sim/include/kurator/sim/TurretControl.h b/sim/include/kurator/sim/TurretControl.h index f6dc13a..323b54b 100644 --- a/sim/include/kurator/sim/TurretControl.h +++ b/sim/include/kurator/sim/TurretControl.h @@ -1,7 +1,8 @@ #pragma once #include <entt/entity/entity.hpp> -#include <entt/signal/dispatcher.hpp> + +#include <kurator/engine/Context.h> namespace kurator @@ -16,7 +17,7 @@ struct TurretControl double reload; int rounds; entt::entity owner; - static void update(entt::registry& registry, entt::dispatcher& dispatcher, float dt); + static void update(engine::Context& ctx); }; 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) |