summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-03 22:00:28 +0100
committerAki <please@ignore.pl>2023-02-03 22:00:28 +0100
commit9b453277059fd015703873172d0dc87b4a29cb55 (patch)
tree3df0415c5b8160f9d97dae12f0c7adb55c4a23db /sim
parentb5a71a9c776386805a12a722be23bf8d7b7e25fe (diff)
downloadkurator-9b453277059fd015703873172d0dc87b4a29cb55.zip
kurator-9b453277059fd015703873172d0dc87b4a29cb55.tar.gz
kurator-9b453277059fd015703873172d0dc87b4a29cb55.tar.bz2
Created engine module right now containing only Point
This might be a bit too generic of a name, but the intent is to get the main shared abstracts for gameplay loop and/or simulation outside of the game executable implementation to redirect dependencies.
Diffstat (limited to 'sim')
-rw-r--r--sim/CMakeLists.txt2
-rw-r--r--sim/include/kurator/sim/FloatingMovement.h4
-rw-r--r--sim/include/kurator/sim/Point.h26
-rw-r--r--sim/include/kurator/sim/components.h6
-rw-r--r--sim/src/BaseBattle.cpp2
-rw-r--r--sim/src/Builder.cpp5
-rw-r--r--sim/src/Point.cpp72
-rw-r--r--sim/src/RandomSpawner.cpp4
8 files changed, 13 insertions, 108 deletions
diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt
index 1cae7b0..ef80c77 100644
--- a/sim/CMakeLists.txt
+++ b/sim/CMakeLists.txt
@@ -6,7 +6,6 @@ add_library(
src/Builder.cpp
src/FloatingMovement.cpp
src/HitPoints.cpp
- src/Point.cpp
src/RandomSpawner.cpp
src/TeamManager.cpp
src/TurretControl.cpp
@@ -19,6 +18,7 @@ target_link_libraries(
${PROJECT_NAME}
PUBLIC EnTT::EnTT
PUBLIC campaign
+ PUBLIC engine
PRIVATE stats
PUBLIC universe
)
diff --git a/sim/include/kurator/sim/FloatingMovement.h b/sim/include/kurator/sim/FloatingMovement.h
index 352377d..d7e8479 100644
--- a/sim/include/kurator/sim/FloatingMovement.h
+++ b/sim/include/kurator/sim/FloatingMovement.h
@@ -3,7 +3,7 @@
#include <entt/entity/registry.hpp>
#include <entt/signal/dispatcher.hpp>
-#include "Point.h"
+#include <kurator/engine/Point.h>
namespace kurator
@@ -18,7 +18,7 @@ struct FloatingMovement
double acceleration;
double deceleration;
double destination_boundary = 100.0;
- Point speed = {0.0, 0.0};
+ engine::Point speed = {0.0, 0.0};
static void update(entt::registry& registry, entt::dispatcher& dispatcher, float dt);
};
diff --git a/sim/include/kurator/sim/Point.h b/sim/include/kurator/sim/Point.h
deleted file mode 100644
index afd30ba..0000000
--- a/sim/include/kurator/sim/Point.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-
-namespace kurator
-{
-namespace sim
-{
-
-
-struct Point
-{
- double x;
- double y;
- double magnitude() const;
- double distance(const Point& other) const;
- double angle() const;
- Point rotate(double angle) const;
- Point scale(double _scale) const;
- Point normalized() const;
- Point operator-(const Point& other) const;
- Point operator+(const Point& other) const;
-};
-
-
-} // namespace sim
-} // namespace kurator
diff --git a/sim/include/kurator/sim/components.h b/sim/include/kurator/sim/components.h
index f4f1799..e8b2591 100644
--- a/sim/include/kurator/sim/components.h
+++ b/sim/include/kurator/sim/components.h
@@ -2,7 +2,7 @@
#include <entt/entity/entity.hpp>
-#include "Point.h"
+#include <kurator/engine/Point.h>
namespace kurator
@@ -13,7 +13,7 @@ namespace sim
struct Transform
{
- Point position;
+ engine::Point position;
double angle;
entt::entity reference_frame = entt::null;
};
@@ -28,7 +28,7 @@ struct Team
struct AIState
{
double keep_at_range;
- Point destination;
+ engine::Point destination;
entt::entity target = entt::null;
};
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 99a0199..3e3815c 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -89,7 +89,7 @@ BaseBattle::keep_at_range()
if (!_registry.valid(ai.target))
continue;
const auto target = _registry.get<Transform>(ai.target);
- const Point offset = target.position - self.position;
+ const auto offset = target.position - self.position;
ai.destination = target.position - offset.normalized().scale(ai.keep_at_range);
}
}
diff --git a/sim/src/Builder.cpp b/sim/src/Builder.cpp
index b5762b3..279cd8b 100644
--- a/sim/src/Builder.cpp
+++ b/sim/src/Builder.cpp
@@ -2,10 +2,10 @@
#include <entt/entity/registry.hpp>
+#include <kurator/engine/Point.h>
#include <kurator/sim/components.h>
#include <kurator/sim/FloatingMovement.h>
#include <kurator/sim/HitPoints.h>
-#include <kurator/sim/Point.h>
#include <kurator/sim/TurretControl.h>
#include <kurator/universe/ShipType.h>
#include <kurator/universe/TurretType.h>
@@ -19,6 +19,9 @@ namespace sim
{
+using engine::Point;
+
+
Builder::Builder(entt::registry& _registry, Spawner& _spawner) :
registry {_registry},
spawner {_spawner}
diff --git a/sim/src/Point.cpp b/sim/src/Point.cpp
deleted file mode 100644
index 1f49774..0000000
--- a/sim/src/Point.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-#include <kurator/sim/Point.h>
-
-#include <cmath>
-
-
-namespace kurator
-{
-namespace sim
-{
-
-
-double
-Point::magnitude() const
-{
- return std::sqrt(std::pow(x, 2) + std::pow(y, 2));
-}
-
-
-double
-Point::distance(const Point& other) const
-{
- return std::sqrt(std::pow(other.x - x, 2) + std::pow(other.y - y, 2));
-}
-
-
-double
-Point::angle() const
-{
- return std::atan2(y, x); // (+x, _) is 0
-}
-
-
-Point
-Point::rotate(const double angle) const
-{
- return {
- x * std::cos(angle) - y * std::sin(angle),
- x * std::sin(angle) + y * std::cos(angle),
- };
-}
-
-
-Point
-Point::scale(const double _scale) const
-{
- return {x * _scale, y * _scale};
-}
-
-
-Point
-Point::normalized() const
-{
- return scale(1.0 / magnitude());
-}
-
-
-Point
-Point::operator-(const Point& other) const
-{
- return {x - other.x, y - other.y};
-}
-
-
-Point
-Point::operator+(const Point& other) const
-{
- return {x + other.x, y + other.y};
-}
-
-
-} // namespace sim
-} // namespace kurator
diff --git a/sim/src/RandomSpawner.cpp b/sim/src/RandomSpawner.cpp
index 7b85f21..a0b0f78 100644
--- a/sim/src/RandomSpawner.cpp
+++ b/sim/src/RandomSpawner.cpp
@@ -2,8 +2,8 @@
#include <cmath>
+#include <kurator/engine/Point.h>
#include <kurator/sim/components.h>
-#include <kurator/sim/Point.h>
namespace kurator
@@ -30,7 +30,7 @@ RandomSpawner::get(const int team)
double facing = clean_angle + M_PI;
if (facing > 2 * M_PI)
facing -= 2 * M_PI;
- const Point position {
+ const engine::Point position {
distance * std::cos(angle),
distance * std::sin(angle),
};