From b9ea79639c2f3e4515b6d590d85ed586765cd5b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 15 Feb 2023 00:49:04 +0100 Subject: Extracted markers to own header and compilation unit --- kurator/CMakeLists.txt | 1 + kurator/src/Battle.cpp | 44 +----------------------------------- kurator/src/components.h | 8 ------- kurator/src/markers.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ kurator/src/markers.h | 26 ++++++++++++++++++++++ 5 files changed, 86 insertions(+), 51 deletions(-) create mode 100644 kurator/src/markers.cpp create mode 100644 kurator/src/markers.h diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 283d84e..17d3939 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable( src/ForceBalance.cpp src/Grid.cpp src/main.cpp + src/markers.cpp src/Pause.cpp src/PopupEmitter.cpp src/ScenarioEditor.cpp diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 73a0136..68879c6 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -10,20 +10,16 @@ #include #include -#include #include #include #include #include -#include #include #include -#include -#include -#include "colors.h" #include "components.h" #include "Grid.h" +#include "markers.h" #include "Pause.h" #include "PopupEmitter.h" #include "Session.h" @@ -40,9 +36,6 @@ Battle::Battle(std::shared_ptr _session) : } -static void attach_markers(sim::State& ctx); - - Battle::Battle(std::shared_ptr _session, campaign::Scenario scenario, Battle::Callback _report) : session {std::move(_session)}, ctx {sim::load_scenario(scenario)}, @@ -59,18 +52,6 @@ Battle::Battle(std::shared_ptr _session, campaign::Scenario scenario, B } -void -attach_markers(sim::State& 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); - ctx.registry.emplace(entity, 5.0, team_color(team.id), std::move(label)); - ctx.registry.emplace(entity); - } -} - - Battle::~Battle() { ctx.dispatcher.sink().disconnect(*this); @@ -178,7 +159,6 @@ animate_lines(sim::State& ctx) static void draw_crosses(const sim::State& ctx); static void draw_lines(const sim::State& ctx); -static void draw_markers(const sim::State& ctx); static void draw_pops(const sim::State& ctx); @@ -235,28 +215,6 @@ draw_lines(const sim::State& ctx) void -draw_markers(const sim::State& ctx) -{ - auto view = ctx.registry.view(); - for (auto [entity, marker, transform] : view.each()) { - const auto pos = ctx.camera.to_screen(transform.position); - if (ctx.registry.all_of(entity)) { - const auto& movement = ctx.registry.get(entity); - const auto& velocity = movement.speed; - const auto edge = pos + velocity.normalized().scale(marker.radius); - const auto tip = edge + velocity.scale(2.0 * ctx.camera.scale); - DrawLine(edge.x, edge.y, tip.x, tip.y, DARKGREEN); - } - const engine::Point direction {std::cos(transform.angle), std::sin(transform.angle)}; - const auto edge = pos + direction.scale(marker.radius); - DrawCircle(pos.x, pos.y, marker.radius, marker.color); - DrawLine(pos.x, pos.y, edge.x, edge.y, WHITE); - DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, GRAY); - } -} - - -void draw_pops(const sim::State& ctx) { auto pops = ctx.registry.view(); diff --git a/kurator/src/components.h b/kurator/src/components.h index ff52bfe..41f0c67 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -39,14 +39,6 @@ struct PopMove }; -struct Marker -{ - double radius; - Color color; - std::string name; -}; - - struct Line { Color color; diff --git a/kurator/src/markers.cpp b/kurator/src/markers.cpp new file mode 100644 index 0000000..a4ed417 --- /dev/null +++ b/kurator/src/markers.cpp @@ -0,0 +1,58 @@ +#include "markers.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "colors.h" +#include "PopupEmitter.h" + + +namespace kurator +{ + + +void +attach_markers(sim::State& 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); + ctx.registry.emplace(entity, 5.0, team_color(team.id), std::move(label)); + ctx.registry.emplace(entity); + } +} + + +void +draw_markers(const sim::State& ctx) +{ + auto view = ctx.registry.view(); + for (const auto& [entity, marker, transform] : view.each()) { + const auto pos = ctx.camera.to_screen(transform.position); + if (ctx.registry.all_of(entity)) { + const auto& movement = ctx.registry.get(entity); + const auto& velocity = movement.speed; + const auto edge = pos + velocity.normalized().scale(marker.radius); + const auto tip = edge + velocity.scale(2.0 * ctx.camera.scale); + DrawLine(edge.x, edge.y, tip.x, tip.y, DARKGREEN); + } + const engine::Point direction {std::cos(transform.angle), std::sin(transform.angle)}; + const auto edge = pos + direction.scale(marker.radius); + DrawCircle(pos.x, pos.y, marker.radius, marker.color); + DrawLine(pos.x, pos.y, edge.x, edge.y, WHITE); + DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, GRAY); + } +} + + +} // namespace kurator diff --git a/kurator/src/markers.h b/kurator/src/markers.h new file mode 100644 index 0000000..c6522cf --- /dev/null +++ b/kurator/src/markers.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include + +#include + + +namespace kurator +{ + + +struct Marker +{ + double radius; + Color color; + std::string name; +}; + + +void attach_markers(sim::State& ctx); +void draw_markers(const sim::State& ctx); + + +} // namespace kurator -- cgit v1.1