diff options
author | Aki <please@ignore.pl> | 2023-02-11 00:25:15 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-02-11 00:25:15 +0100 |
commit | d0629836f9aa002a872d59c7f9e465dca9f2cc02 (patch) | |
tree | 1c98f3c58e7199ae2de7a51b4e45560a53aed374 /kurator | |
parent | d6687be6a89ebd55fa9f3438d742bbf9cf4c9afa (diff) | |
download | kurator-d0629836f9aa002a872d59c7f9e465dca9f2cc02.zip kurator-d0629836f9aa002a872d59c7f9e465dca9f2cc02.tar.gz kurator-d0629836f9aa002a872d59c7f9e465dca9f2cc02.tar.bz2 |
Added Context to streamline system update call interface
Diffstat (limited to 'kurator')
-rw-r--r-- | kurator/src/Battle.cpp | 46 | ||||
-rw-r--r-- | kurator/src/Battle.h | 1 |
2 files changed, 25 insertions, 22 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index c7bbdc7..8ea3e11 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -10,6 +10,7 @@ #include <raylib.h> #include <imgui.h> +#include <kurator/engine/Context.h> #include <kurator/engine/Point.h> #include <kurator/campaign/scenarios.h> #include <kurator/sim/Battle.h> @@ -83,10 +84,10 @@ time_controls(const char* id, float& time_factor) } -static void progress_timers(entt::registry& registry, engine::Clock& clock); -static void move_ui_pops(entt::registry& registry, engine::Clock& clock); -static void blink_crosses(entt::registry& registry, engine::Clock& clock); -static void animate_lines(entt::registry& registry, engine::Clock& clock); +static void progress_timers(engine::Context& ctx); +static void move_ui_pops(engine::Context& ctx); +static void blink_crosses(engine::Context& ctx); +static void animate_lines(engine::Context& ctx); void @@ -102,11 +103,12 @@ Battle::update(const float) if (IsWindowResized()) camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); // won't work in frame auto& registry = battle->registry(); + engine::Context ctx {registry, battle->dispatcher(), clock}; battle->update(clock.dt()); - progress_timers(registry, clock); - move_ui_pops(registry, clock); - blink_crosses(registry, clock); - animate_lines(registry, clock); + progress_timers(ctx); + move_ui_pops(ctx); + blink_crosses(ctx); + animate_lines(ctx); balance.update(registry); ImGui::SetNextWindowPos({GetScreenWidth()/2.0f, GetScreenHeight()-100.0f}, ImGuiCond_Once, {0.5f, 0.5f}); ImGui::SetNextWindowSize({240.0f, 0.0f}, ImGuiCond_Once); @@ -117,26 +119,26 @@ Battle::update(const float) void -progress_timers(entt::registry& registry, engine::Clock& clock) +progress_timers(engine::Context& ctx) { - auto timers = registry.view<Timed>(); + auto timers = ctx.registry.view<Timed>(); for (auto&& [entity, timer] : timers.each()) { - timer.left -= timer.scaled ? clock.dt() : clock.ui(); + timer.left -= timer.scaled ? ctx.clock.dt() : ctx.clock.ui(); if (timer.left < 0.0) - registry.destroy(entity); + ctx.registry.destroy(entity); } } void -move_ui_pops(entt::registry& registry, engine::Clock& clock) +move_ui_pops(engine::Context& ctx) { - auto pops = registry.view<PopMove, UIOffset>(); + auto pops = ctx.registry.view<PopMove, UIOffset>(); for (auto&& [entity, pop, offset] : pops.each()) { - const auto speed = pop.speed.scale(clock.ui()); + const auto speed = pop.speed.scale(ctx.clock.ui()); offset.x += speed.x; offset.y += speed.y; - const auto damp = pop.speed.scale(pop.damp).scale(clock.ui()); + const auto damp = pop.speed.scale(pop.damp).scale(ctx.clock.ui()); pop.speed.x -= damp.x; pop.speed.y -= damp.y; } @@ -144,11 +146,11 @@ move_ui_pops(entt::registry& registry, engine::Clock& clock) void -blink_crosses(entt::registry& registry, engine::Clock& clock) +blink_crosses(engine::Context& ctx) { - auto crosses = registry.view<Cross>(); + auto crosses = ctx.registry.view<Cross>(); for (auto&& [entity, cross] : crosses.each()) { - cross.timer += clock.ui(); + cross.timer += ctx.clock.ui(); const auto dphase = cross.phase * 2; if (cross.timer > dphase) cross.timer -= dphase; @@ -157,11 +159,11 @@ blink_crosses(entt::registry& registry, engine::Clock& clock) void -animate_lines(entt::registry& registry, engine::Clock& clock) +animate_lines(engine::Context& ctx) { - auto lines = registry.view<Line>(); + auto lines = ctx.registry.view<Line>(); for (auto&& [entity, line] : lines.each()) - line.position += (1.0 + line.hlength) / line.duration * clock.dt(); + line.position += (1.0 + line.hlength) / line.duration * ctx.clock.dt(); } diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h index 8812164..b928855 100644 --- a/kurator/src/Battle.h +++ b/kurator/src/Battle.h @@ -6,6 +6,7 @@ #include <kurator/campaign/Scenario.h> #include <kurator/engine/Camera.h> #include <kurator/engine/Clock.h> +#include <kurator/engine/Context.h> #include <kurator/sim/Battle.h> #include <kurator/sim/events.h> #include <kurator/stats/EventLog.h> |