summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-11 16:50:09 +0100
committerAki <please@ignore.pl>2023-02-11 17:08:00 +0100
commite66011756340e03fe941723f762119ed78ec2402 (patch)
tree5d699632b0d7683c96f5db81ba440d81bbac338e /kurator
parentf9269a45b82f637173e30760e1f4febc7ccb2b3e (diff)
downloadkurator-e66011756340e03fe941723f762119ed78ec2402.zip
kurator-e66011756340e03fe941723f762119ed78ec2402.tar.gz
kurator-e66011756340e03fe941723f762119ed78ec2402.tar.bz2
Added ConstContext for drawing systems
This whole ongoing refactoring process is meant to better understand relationships between Battle, Simulation and Systems.
Diffstat (limited to 'kurator')
-rw-r--r--kurator/src/Battle.cpp65
1 files changed, 50 insertions, 15 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 7363661..b47c539 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -103,7 +103,7 @@ Battle::update()
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};
+ engine::Context ctx {registry, battle->dispatcher(), clock, camera};
battle->update(clock.dt);
progress_timers(ctx);
move_ui_pops(ctx);
@@ -167,17 +167,34 @@ animate_lines(engine::Context& ctx)
}
+static void draw_crosses(engine::ConstContext& ctx);
+static void draw_lines(engine::ConstContext& ctx);
+static void draw_markers(engine::ConstContext& ctx);
+static void draw_pops(engine::ConstContext& ctx);
+
+
void
Battle::draw() const
{
ClearBackground(BLACK);
Grid().draw(camera);
- auto& registry = battle->registry();
- auto crosses = registry.view<sim::Transform, Cross>();
+ engine::ConstContext ctx {battle->registry(), battle->dispatcher(), clock, camera};
+ draw_crosses(ctx);
+ draw_lines(ctx);
+ draw_markers(ctx);
+ draw_pops(ctx);
+ balance.draw();
+}
+
+
+void
+draw_crosses(engine::ConstContext& ctx)
+{
+ auto crosses = ctx.registry.view<sim::Transform, Cross>();
for (const auto& [entity, transform, cross] : crosses.each()) {
if (cross.timer > cross.phase)
continue;
- const auto pos = camera.to_screen(transform.position);
+ const auto pos = ctx.camera.to_screen(transform.position);
DrawLine(
pos.x - cross.hlength,
pos.y - cross.hlength,
@@ -191,23 +208,35 @@ Battle::draw() const
pos.y + cross.hlength,
cross.color);
}
- auto lines = registry.view<Line>();
+}
+
+
+void
+draw_lines(engine::ConstContext& ctx)
+{
+ auto lines = ctx.registry.view<Line>();
for (const auto& [entity, line] : lines.each()) {
const auto diff = line.end - line.start;
const auto fstart = line.position - line.hlength;
const auto fend = line.position + line.hlength;
- const auto start = camera.to_screen(line.start + diff.scale(fstart > 0.0 ? fstart : 0.0));
- const auto end = camera.to_screen(line.start + diff.scale(fend > 1.0 ? 1.0 : fend));
+ const auto start = ctx.camera.to_screen(line.start + diff.scale(fstart > 0.0 ? fstart : 0.0));
+ const auto end = ctx.camera.to_screen(line.start + diff.scale(fend > 1.0 ? 1.0 : fend));
DrawLine(start.x, start.y, end.x, end.y, line.color);
}
- auto view = registry.view<const Marker, const sim::Transform>();
+}
+
+
+void
+draw_markers(engine::ConstContext& ctx)
+{
+ auto view = ctx.registry.view<const Marker, const sim::Transform>();
for (auto [entity, marker, transform] : view.each()) {
- const auto pos = camera.to_screen(transform.position);
- if (registry.all_of<sim::FloatingMovement>(entity)) {
- const auto& movement = registry.get<sim::FloatingMovement>(entity);
+ const auto pos = ctx.camera.to_screen(transform.position);
+ if (ctx.registry.all_of<sim::FloatingMovement>(entity)) {
+ const auto& movement = ctx.registry.get<sim::FloatingMovement>(entity);
const auto& velocity = movement.speed;
const auto edge = pos + velocity.normalized().scale(marker.radius);
- const auto tip = edge + velocity.scale(2.0 * camera.scale);
+ const auto tip = edge + velocity.scale(2.0 * ctx.camera.scale);
DrawLine(edge.x, edge.y, tip.x, tip.y, DARKGRAY);
}
const engine::Point direction {std::cos(transform.angle), std::sin(transform.angle)};
@@ -216,12 +245,18 @@ Battle::draw() const
DrawLine(pos.x, pos.y, edge.x, edge.y, WHITE);
DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, GRAY);
}
- auto pops = registry.view<CenteredText, sim::Transform, UIOffset>();
+}
+
+
+void
+draw_pops(engine::ConstContext& ctx)
+{
+ auto pops = ctx.registry.view<CenteredText, sim::Transform, UIOffset>();
for (const auto& [entity, text, transform, offset] : pops.each()) {
- const auto pos = camera.to_screen(transform.position).subtract(text.width/2, text.font_size/2) + offset;
+ const auto screen = ctx.camera.to_screen(transform.position);
+ const auto pos = screen.subtract(text.width/2, text.font_size/2) + offset;
DrawText(text.text.c_str(), pos.x, pos.y, text.font_size, text.color);
}
- balance.draw();
}