summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/CMakeLists.txt1
-rw-r--r--engine/include/kurator/engine/Context.h25
-rw-r--r--engine/src/Context.cpp24
-rw-r--r--kurator/src/Battle.cpp46
-rw-r--r--kurator/src/Battle.h1
5 files changed, 75 insertions, 22 deletions
diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt
index 7cb7f20..43c09a5 100644
--- a/engine/CMakeLists.txt
+++ b/engine/CMakeLists.txt
@@ -3,6 +3,7 @@ add_library(
${PROJECT_NAME} STATIC
src/Camera.cpp
src/Clock.cpp
+ src/Context.cpp
src/Point.cpp
)
target_include_directories(
diff --git a/engine/include/kurator/engine/Context.h b/engine/include/kurator/engine/Context.h
new file mode 100644
index 0000000..c2c7cca
--- /dev/null
+++ b/engine/include/kurator/engine/Context.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
+
+#include "Clock.h"
+
+
+namespace kurator
+{
+namespace engine
+{
+
+
+struct Context
+{
+ Context(entt::registry& registry_, entt::dispatcher& dispatcher_, Clock& clock_);
+ entt::registry& registry;
+ entt::dispatcher& dispatcher;
+ Clock& clock;
+};
+
+
+} // namespace engine
+} // namespace kurator
diff --git a/engine/src/Context.cpp b/engine/src/Context.cpp
new file mode 100644
index 0000000..eeec938
--- /dev/null
+++ b/engine/src/Context.cpp
@@ -0,0 +1,24 @@
+#include <kurator/engine/Context.h>
+
+#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
+
+#include <kurator/engine/Clock.h>
+
+
+namespace kurator
+{
+namespace engine
+{
+
+
+Context::Context(entt::registry& registry_, entt::dispatcher& dispatcher_, Clock& clock_) :
+ registry {registry_},
+ dispatcher {dispatcher_},
+ clock {clock_}
+{
+}
+
+
+} // namespace engine
+} // namespace kurator
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>