From 4f2f2d329aeee7e45198cfc6e46f7648cedf1707 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 12 Feb 2023 14:03:45 +0100 Subject: Extracted marker setup from Battle scene constructor --- kurator/src/Battle.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 380cef1..683b0e6 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -40,6 +40,9 @@ Battle::Battle(std::shared_ptr _session) : } +static void attach_markers(engine::Context& ctx); + + Battle::Battle(std::shared_ptr _session, campaign::Scenario scenario, Battle::Callback _report) : session {std::move(_session)}, battle {sim::prepare(scenario)}, @@ -49,15 +52,23 @@ Battle::Battle(std::shared_ptr _session, campaign::Scenario scenario, B battle->dispatcher().sink().connect<&Battle::on_hit>(*this); battle->dispatcher().sink().connect<&Battle::on_destroyed>(*this); battle->dispatcher().sink().connect<&Battle::on_ship_left>(*this); + camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); auto& registry = battle->registry(); - auto ships = registry.view(); + engine::Context ctx {registry, battle->dispatcher(), clock, camera}; + attach_markers(ctx); + balance.update(registry); +} + + +void +attach_markers(engine::Context& ctx) +{ + auto ships = ctx.registry.view(); for (const auto& [entity, team, type, identifier] : ships.each()) { std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id); - registry.emplace(entity, 5.0, team_color(team.id), std::move(label)); - registry.emplace(entity); + ctx.registry.emplace(entity, 5.0, team_color(team.id), std::move(label)); + ctx.registry.emplace(entity); } - camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); - balance.update(registry); } -- cgit v1.1