diff options
-rw-r--r-- | engine/include/kurator/engine/Clock.h | 8 | ||||
-rw-r--r-- | engine/src/Clock.cpp | 19 | ||||
-rw-r--r-- | kurator/src/Battle.cpp | 14 |
3 files changed, 19 insertions, 22 deletions
diff --git a/engine/include/kurator/engine/Clock.h b/engine/include/kurator/engine/Clock.h index 4e5e7b1..6b66ab3 100644 --- a/engine/include/kurator/engine/Clock.h +++ b/engine/include/kurator/engine/Clock.h @@ -9,10 +9,12 @@ namespace engine struct Clock { + Clock(); + void update(); + float dt; + float ui; + float game = 0.0f; float time_factor = 1.0f; - float dt() const; - float ui() const; - operator float() const; }; diff --git a/engine/src/Clock.cpp b/engine/src/Clock.cpp index 5261603..956f9c4 100644 --- a/engine/src/Clock.cpp +++ b/engine/src/Clock.cpp @@ -9,23 +9,18 @@ namespace engine { -float -Clock::dt() const +Clock::Clock() { - return GetFrameTime() * time_factor; + update(); } -float -Clock::ui() const +void +Clock::update() { - return GetFrameTime(); -} - - -Clock::operator float() const -{ - return dt(); + ui = GetFrameTime(); + dt = ui * time_factor; + game += dt; } diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index da4cbde..7363661 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -43,7 +43,6 @@ Battle::Battle(std::shared_ptr<Session> _session) : Battle::Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario, Battle::Callback _report) : session {std::move(_session)}, battle {sim::prepare(scenario)}, - clock {}, report {std::move(_report)} { battle->dispatcher().sink<sim::End>().connect<&Battle::on_end>(*this); @@ -103,8 +102,9 @@ Battle::update() if (IsWindowResized()) camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); // won't work in frame auto& registry = battle->registry(); + clock.update(); engine::Context ctx {registry, battle->dispatcher(), clock}; - battle->update(clock.dt()); + battle->update(clock.dt); progress_timers(ctx); move_ui_pops(ctx); blink_crosses(ctx); @@ -123,7 +123,7 @@ progress_timers(engine::Context& ctx) { auto timers = ctx.registry.view<Timed>(); for (auto&& [entity, timer] : timers.each()) { - timer.left -= timer.scaled ? ctx.clock.dt() : ctx.clock.ui(); + timer.left -= timer.scaled ? ctx.clock.dt : ctx.clock.ui; if (timer.left < 0.0) ctx.registry.destroy(entity); } @@ -135,10 +135,10 @@ move_ui_pops(engine::Context& ctx) { auto pops = ctx.registry.view<PopMove, UIOffset>(); for (auto&& [entity, pop, offset] : pops.each()) { - const auto speed = pop.speed.scale(ctx.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(ctx.clock.ui()); + const auto damp = pop.speed.scale(pop.damp).scale(ctx.clock.ui); pop.speed.x -= damp.x; pop.speed.y -= damp.y; } @@ -150,7 +150,7 @@ blink_crosses(engine::Context& ctx) { auto crosses = ctx.registry.view<Cross>(); for (auto&& [entity, cross] : crosses.each()) { - cross.timer += ctx.clock.ui(); + cross.timer += ctx.clock.ui; const auto dphase = cross.phase * 2; if (cross.timer > dphase) cross.timer -= dphase; @@ -163,7 +163,7 @@ animate_lines(engine::Context& ctx) { auto lines = ctx.registry.view<Line>(); for (auto&& [entity, line] : lines.each()) - line.position += (1.0 + line.hlength) / line.duration * ctx.clock.dt(); + line.position += (1.0 + line.hlength) / line.duration * ctx.clock.dt; } |