summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-23 08:34:55 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-23 08:34:55 +0100
commit9574e97c4b9b5d607cd95ab81e7d5e8d10487702 (patch)
treeb1cf8c3225b653a201f9c36ad06664e8cc7d1a15 /src
parente1256c030540d1208349531f8547b1802668f631 (diff)
a
Diffstat (limited to 'src')
-rw-r--r--src/critter.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/critter.cpp b/src/critter.cpp
index 5130f09e..e335747b 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -1,4 +1,5 @@
#include "critter.hpp"
+#include "compat/limits.hpp"
#include "tile-constants.hpp"
#include "src/anim-atlas.hpp"
#include "loader/loader.hpp"
@@ -173,8 +174,8 @@ void critter::update_movement(size_t i, const Ns& dt, rotation new_r)
fm_assert(new_r < rotation_COUNT);
fm_assert(is_dynamic());
- const auto hz = atlas->info().fps;
- const auto nframes = alloc_frame_time(dt, delta, hz, speed);
+ const auto& info = atlas->info();
+ const auto nframes = alloc_frame_time(dt, delta, info.fps, speed);
if (nframes == 0)
return;
@@ -192,26 +193,27 @@ void critter::update_movement(size_t i, const Ns& dt, rotation new_r)
for (unsigned j = 0; j < nvecs; j++)
{
const auto vec = rotation_to_vec(rotations[j]);
- constexpr auto frac = 65535u;
- constexpr auto inv_frac = 1.f / (float)frac;
+ using Frac = decltype(critter::offset_frac)::Type;
+ constexpr auto frac = float{limits<Frac>::max};
+ constexpr auto inv_frac = 1 / frac;
const auto sign_vec = Math::sign(vec);
auto offset_ = vec + Vector2(offset_frac) * sign_vec * inv_frac;
auto off_i = Vector2i(offset_);
if (!off_i.isZero())
{
- offset_frac = Vector2us(Math::abs(Math::fmod(offset_, 1.f)) * frac);
+ offset_frac = Math::Vector2<Frac>(Math::abs(Math::fmod(offset_, 1.f)) * frac);
if (can_move_to(off_i))
{
can_move = true;
move_to(i, off_i, new_r);
- ++frame %= atlas->info().nframes;
+ ++frame %= info.nframes;
break;
}
}
else
{
can_move = true;
- offset_frac = Vector2us(Math::min({1.f,1.f}, Math::abs(offset_)) * frac);
+ offset_frac = Math::Vector2<Frac>(Math::min({1.f,1.f}, Math::abs(offset_)) * frac);
break;
}
}