summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-08 06:53:45 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-08 06:53:45 +0200
commitc84d0fc943ccb0340046a8bdb74006ef796b2756 (patch)
tree7ef5daa04c55f15089cb25f2ed0be91c786c5636
parent54af7f5b75ada6be57922f8ec7d85e4bfbd3e80a (diff)
now use Math::sqrt at compile time
-rw-r--r--src/critter.cpp14
-rw-r--r--src/path-search-dijkstra.cpp3
2 files changed, 7 insertions, 10 deletions
diff --git a/src/critter.cpp b/src/critter.cpp
index f8971710..a24c6fea 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -9,17 +9,13 @@
#include <cmath>
#include <utility>
#include <algorithm>
+#include <Magnum/Math/Functions.h>
namespace floormat {
namespace {
-constexpr auto vector_length(Vector2 vec)
-{
- return math::sqrt(Math::dot(vec, vec));
-}
-
-constexpr float framerate = 96 * 3, move_speed = vector_length(TILE_SIZE2) * 4.25f;
+constexpr float framerate = 96 * 3, move_speed = TILE_SIZE2.length() * 4.25f;
constexpr float frame_time = 1/framerate;
constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)
@@ -123,8 +119,8 @@ constexpr Vector2 move_vec(Vector2i vec)
{
const int left_right = vec[0], top_bottom = vec[1];
constexpr auto c = move_speed * frame_time;
- auto dir = Vector2((float)math::sgn(left_right), (float)math::sgn(top_bottom));
- auto inv_norm = 1.f/math::sqrt(Math::dot(dir, dir));
+ auto dir = Vector2((float)Math::sign(left_right), (float)Math::sign(top_bottom));
+ auto inv_norm = 1.f/dir.length();
return c * dir * inv_norm;
}
@@ -195,7 +191,7 @@ void critter::update(size_t i, float dt)
auto vec = move_vecs[j];
constexpr auto frac = 65535u;
constexpr auto inv_frac = 1.f / (float)frac;
- const auto sign_vec = Vector2(math::sgn(vec[0]), math::sgn(vec[1]));
+ const auto sign_vec = Vector2(Math::sign(vec[0]), Math::sign(vec[1]));
auto offset_ = vec + Vector2(offset_frac) * sign_vec * inv_frac;
offset_frac = Vector2us(Vector2(std::fabs(std::fmod(offset_[0], 1.f)), std::fabs(std::fmod(offset_[1], 1.f))) * frac);
auto off_i = Vector2i(offset_);
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp
index e88461dd..4a71ef8d 100644
--- a/src/path-search-dijkstra.cpp
+++ b/src/path-search-dijkstra.cpp
@@ -14,6 +14,7 @@ namespace {
constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
constexpr auto div_size = path_search::div_size;
constexpr auto min_size = path_search::min_size;
+constexpr auto goal_distance = div_size;
template<typename T>
requires std::is_arithmetic_v<T>
@@ -40,7 +41,7 @@ constexpr auto directions = [] constexpr
{
struct pair { Vector2i dir; uint32_t len; };
constexpr auto len1 = div_size;
- constexpr auto len2 = (uint32_t)(math::sqrt((float)len1.dot()) + 0.5f); // NOLINT
+ constexpr auto len2 = (uint32_t)(len1.length() + 0.5f); // NOLINT
std::array<pair, 8> array = {{
{ { -1, -1 }, len2 },
{ { 1, 1 }, len2 },