summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/CMakeLists.txt1
-rw-r--r--sim/include/kurator/sim/FloatingMovement.h27
-rw-r--r--sim/include/kurator/sim/components.h10
-rw-r--r--sim/src/BaseBattle.cpp26
-rw-r--r--sim/src/BaseBattle.h1
-rw-r--r--sim/src/Builder.cpp4
-rw-r--r--sim/src/FloatingMovement.cpp39
7 files changed, 71 insertions, 37 deletions
diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt
index f3d5494..ff2621c 100644
--- a/sim/CMakeLists.txt
+++ b/sim/CMakeLists.txt
@@ -4,6 +4,7 @@ add_library(
src/BaseBattle.cpp
src/Battle.cpp
src/Builder.cpp
+ src/FloatingMovement.cpp
src/Point.cpp
src/RandomSpawner.cpp
src/TeamManager.cpp
diff --git a/sim/include/kurator/sim/FloatingMovement.h b/sim/include/kurator/sim/FloatingMovement.h
new file mode 100644
index 0000000..352377d
--- /dev/null
+++ b/sim/include/kurator/sim/FloatingMovement.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
+
+#include "Point.h"
+
+
+namespace kurator
+{
+namespace sim
+{
+
+
+struct FloatingMovement
+{
+ double max_speed;
+ double acceleration;
+ double deceleration;
+ double destination_boundary = 100.0;
+ Point speed = {0.0, 0.0};
+ static void update(entt::registry& registry, entt::dispatcher& dispatcher, float dt);
+};
+
+
+} // namespace sim
+} // namespace kurator
diff --git a/sim/include/kurator/sim/components.h b/sim/include/kurator/sim/components.h
index 6fbab55..47ff5b2 100644
--- a/sim/include/kurator/sim/components.h
+++ b/sim/include/kurator/sim/components.h
@@ -33,16 +33,6 @@ struct AIState
};
-struct FloatingMovement
-{
- double max_speed;
- double acceleration;
- double deceleration;
- double destination_boundary;
- Point speed = {0.0, 0.0};
-};
-
-
struct HitPoints
{
double health;
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 4b65139..99c1b99 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -7,6 +7,7 @@
#include <kurator/campaign/UniqueIdentifier.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
+#include <kurator/sim/FloatingMovement.h>
#include <kurator/stats/events.h>
#include <kurator/universe.h>
@@ -56,7 +57,7 @@ BaseBattle::update(const float dt)
time += dt;
pick_random_targets();
keep_at_range();
- floating_movement(dt);
+ FloatingMovement::update(_registry, _dispatcher, dt);
turrets(dt);
kill_off_dead();
manager.clear(_registry); // registry supports on destructions events
@@ -90,29 +91,6 @@ BaseBattle::keep_at_range()
void
-BaseBattle::floating_movement(const float dt)
-{
- auto view = _registry.view<Transform, FloatingMovement, AIState>();
- for (auto&& [entity, transform, movement, ai] : view.each()) {
- const auto offset = ai.destination - transform.position;
- const auto at_destination = offset.magnitude() > movement.destination_boundary;
- const auto acceleration =
- at_destination ?
- offset.normalized().scale(movement.acceleration * dt) :
- offset.normalized().scale(-1 * movement.deceleration * dt);
- movement.speed.x += acceleration.x;
- movement.speed.y += acceleration.y;
- if (movement.speed.magnitude() > movement.max_speed)
- movement.speed = movement.speed.normalized().scale(movement.max_speed);
- const auto speed = movement.speed.scale(dt);
- transform.position.x += speed.x;
- transform.position.y += speed.y;
- transform.angle = speed.angle();
- }
-}
-
-
-void
BaseBattle::turrets(const float dt)
{
auto view = _registry.view<TurretControl, universe::TurretType>();
diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h
index d2f7d19..3c19b9c 100644
--- a/sim/src/BaseBattle.h
+++ b/sim/src/BaseBattle.h
@@ -31,7 +31,6 @@ private:
TeamManager manager;
void pick_random_targets();
void keep_at_range();
- void floating_movement(float dt);
void turrets(float dt);
void kill_off_dead();
};
diff --git a/sim/src/Builder.cpp b/sim/src/Builder.cpp
index a5319fd..e0198a1 100644
--- a/sim/src/Builder.cpp
+++ b/sim/src/Builder.cpp
@@ -3,6 +3,7 @@
#include <entt/entity/registry.hpp>
#include <kurator/sim/components.h>
+#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/Point.h>
#include <kurator/universe/ShipType.h>
#include <kurator/universe/TurretType.h>
@@ -34,8 +35,7 @@ Builder::operator()(const universe::ShipType& ship_type, const int team) const
entity,
ship_type.max_speed,
ship_type.max_speed * 2.0,
- ship_type.max_speed * 3.0,
- 100.0);
+ ship_type.max_speed * 3.0);
registry.emplace<AIState>(entity, 6000.0, Point{0.0, 0.0});
registry.emplace<HitPoints>(entity, ship_type.base_health_points);
return entity;
diff --git a/sim/src/FloatingMovement.cpp b/sim/src/FloatingMovement.cpp
new file mode 100644
index 0000000..e1794d5
--- /dev/null
+++ b/sim/src/FloatingMovement.cpp
@@ -0,0 +1,39 @@
+#include <kurator/sim/FloatingMovement.h>
+
+#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
+
+#include <kurator/sim/components.h>
+
+
+namespace kurator
+{
+namespace sim
+{
+
+
+void
+FloatingMovement::update(entt::registry& registry, entt::dispatcher&, const float dt)
+{
+ auto view = registry.view<Transform, FloatingMovement, AIState>();
+ for (auto&& [entity, transform, movement, ai] : view.each()) {
+ const auto offset = ai.destination - transform.position;
+ const auto at_destination = offset.magnitude() > movement.destination_boundary;
+ const auto acceleration =
+ at_destination ?
+ offset.normalized().scale(movement.acceleration * dt) :
+ offset.normalized().scale(-1 * movement.deceleration * dt);
+ movement.speed.x += acceleration.x;
+ movement.speed.y += acceleration.y;
+ if (movement.speed.magnitude() > movement.max_speed)
+ movement.speed = movement.speed.normalized().scale(movement.max_speed);
+ const auto speed = movement.speed.scale(dt);
+ transform.position.x += speed.x;
+ transform.position.y += speed.y;
+ transform.angle = speed.angle();
+ }
+}
+
+
+} // namespace sim
+} // namespace kurator