From 9b453277059fd015703873172d0dc87b4a29cb55 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 3 Feb 2023 22:00:28 +0100 Subject: 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. --- sim/CMakeLists.txt | 2 +- sim/include/kurator/sim/FloatingMovement.h | 4 +- sim/include/kurator/sim/Point.h | 26 ----------- sim/include/kurator/sim/components.h | 6 +-- sim/src/BaseBattle.cpp | 2 +- sim/src/Builder.cpp | 5 ++- sim/src/Point.cpp | 72 ------------------------------ sim/src/RandomSpawner.cpp | 4 +- 8 files changed, 13 insertions(+), 108 deletions(-) delete mode 100644 sim/include/kurator/sim/Point.h delete mode 100644 sim/src/Point.cpp (limited to 'sim') 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 #include -#include "Point.h" +#include 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 -#include "Point.h" +#include 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(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 +#include #include #include #include -#include #include #include #include @@ -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 - -#include - - -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 +#include #include -#include 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), }; -- cgit v1.1