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/src/BaseBattle.cpp | 2 +- sim/src/Builder.cpp | 5 +++- sim/src/Point.cpp | 72 ----------------------------------------------- sim/src/RandomSpawner.cpp | 4 +-- 4 files changed, 7 insertions(+), 76 deletions(-) delete mode 100644 sim/src/Point.cpp (limited to 'sim/src') 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