summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-15 00:49:04 +0100
committerAki <please@ignore.pl>2023-02-15 00:49:04 +0100
commitb9ea79639c2f3e4515b6d590d85ed586765cd5b3 (patch)
tree6fa280ea728dd4b0b20c81e5257558a9ec2a55b7 /kurator
parentb3a579d8e2d8bee77cf43b4e9f993e10576af61f (diff)
downloadkurator-b9ea79639c2f3e4515b6d590d85ed586765cd5b3.zip
kurator-b9ea79639c2f3e4515b6d590d85ed586765cd5b3.tar.gz
kurator-b9ea79639c2f3e4515b6d590d85ed586765cd5b3.tar.bz2
Extracted markers to own header and compilation unit
Diffstat (limited to 'kurator')
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp44
-rw-r--r--kurator/src/components.h8
-rw-r--r--kurator/src/markers.cpp58
-rw-r--r--kurator/src/markers.h26
5 files changed, 86 insertions, 51 deletions
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 <raylib.h>
#include <imgui.h>
-#include <kurator/engine/Point.h>
#include <kurator/campaign/scenarios.h>
#include <kurator/sim.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
-#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/State.h>
#include <kurator/stats/events.h>
-#include <kurator/universe/ShipType.h>
-#include <kurator/universe/UniqueIdentifier.h>
-#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> _session) :
}
-static void attach_markers(sim::State& ctx);
-
-
Battle::Battle(std::shared_ptr<Session> _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> _session, campaign::Scenario scenario, B
}
-void
-attach_markers(sim::State& ctx)
-{
- auto ships = ctx.registry.view<sim::Team, universe::ShipType, universe::UniqueIdentifier>();
- for (const auto& [entity, team, type, identifier] : ships.each()) {
- std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id);
- ctx.registry.emplace<Marker>(entity, 5.0, team_color(team.id), std::move(label));
- ctx.registry.emplace<PopupEmitter>(entity);
- }
-}
-
-
Battle::~Battle()
{
ctx.dispatcher.sink<sim::End>().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<const Marker, const sim::Transform>();
- for (auto [entity, marker, transform] : view.each()) {
- 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 * 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<CenteredText, sim::Transform, UIOffset>();
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 <cmath>
+#include <string>
+#include <utility>
+
+#include <raylib.h>
+
+#include <kurator/engine/Point.h>
+#include <kurator/sim/components.h>
+#include <kurator/sim/FloatingMovement.h>
+#include <kurator/sim/State.h>
+#include <kurator/universe/ShipType.h>
+#include <kurator/universe/UniqueIdentifier.h>
+
+#include "colors.h"
+#include "PopupEmitter.h"
+
+
+namespace kurator
+{
+
+
+void
+attach_markers(sim::State& ctx)
+{
+ auto ships = ctx.registry.view<sim::Team, universe::ShipType, universe::UniqueIdentifier>();
+ for (const auto& [entity, team, type, identifier] : ships.each()) {
+ std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id);
+ ctx.registry.emplace<Marker>(entity, 5.0, team_color(team.id), std::move(label));
+ ctx.registry.emplace<PopupEmitter>(entity);
+ }
+}
+
+
+void
+draw_markers(const sim::State& ctx)
+{
+ auto view = ctx.registry.view<Marker, sim::Transform>();
+ for (const auto& [entity, marker, transform] : view.each()) {
+ 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 * 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 <string>
+
+#include <raylib.h>
+
+#include <kurator/sim/State.h>
+
+
+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