summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/critter.cpp8
-rw-r--r--test/critter.cpp6
2 files changed, 12 insertions, 2 deletions
diff --git a/src/critter.cpp b/src/critter.cpp
index 4ec00059..f9de8638 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -172,6 +172,7 @@ void critter::update_movement(size_t i, Ns dt, rotation new_r)
rotate(i, new_r);
c->ensure_passability();
+ bool can_move = false;
for (auto k = 0u; k < nframes; k++)
{
@@ -188,6 +189,7 @@ void critter::update_movement(size_t i, Ns dt, rotation new_r)
offset_frac = Vector2us(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;
break;
@@ -200,6 +202,12 @@ void critter::update_movement(size_t i, Ns dt, rotation new_r)
}
}
}
+
+ if (!can_move)
+ {
+ delta = {};
+ offset_frac = {};
+ }
}
object_type critter::type() const noexcept { return object_type::critter; }
diff --git a/test/critter.cpp b/test/critter.cpp
index e75be7d9..3f13a87f 100644
--- a/test/critter.cpp
+++ b/test/critter.cpp
@@ -112,6 +112,7 @@ bool run(world& w, const function_view<Ns() const>& make_dt,
Ns time{0};
auto last_pos = npc.position();
+ auto last_delta = npc.delta;
uint32_t i;
if (!start.quiet) [[unlikely]]
@@ -140,8 +141,9 @@ bool run(world& w, const function_view<Ns() const>& make_dt,
fm_assert(dt <= Second * 1000);
npc.update_movement(index, dt, start.rotation);
const auto pos = npc.position();
- const bool same_pos = pos == last_pos;
+ const bool same_pos = pos == last_pos && npc.delta == last_delta;
last_pos = pos;
+ last_delta = npc.delta;
time += dt;
@@ -300,7 +302,7 @@ void test_app::test_critter()
test1("dt=100 accel=2", constantly(Millisecond * 100.0 ), 2);
// test1("dt=16.667 accel=0.5", constantly(Millisecond * 16.667),0.5); // todo! fix this!
test1("dt=100 accel=0.5", constantly(Millisecond * 100.0 ), 0.5);
- //test1("dt=16.667 ms accel=1", constantly(Millisecond * 16.667), 1); // todo! fix this!
+ test1("dt=16.667 ms accel=1", constantly(Millisecond * 16.667), 1); // todo! fix this!
test2("dt=33.334 accel=1", constantly(Millisecond * 33.334), 1);
test2("dt=33.334 accel=2", constantly(Millisecond * 33.334), 2);
test2("dt=33.334 accel=5", constantly(Millisecond * 33.334), 5);