summaryrefslogtreecommitdiffhomepage
path: root/src/character.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-19 16:18:13 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-19 16:18:13 +0100
commit86bd6a4411badecfc76fe3a9d29b4aa30c8fdba7 (patch)
tree468c23d67bab654f98126c1fa7ab58e9043b3f6a /src/character.cpp
parentf1da751349fb52a8a88b10bc3289288a4fcd2396 (diff)
work on entity reodering
Diffstat (limited to 'src/character.cpp')
-rw-r--r--src/character.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/character.cpp b/src/character.cpp
index 110d2031..10ef4a34 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -96,26 +96,36 @@ void character::set_keys(bool L, bool R, bool U, bool D)
b_D = D;
}
-bool character::update(size_t i, float dt)
+Vector2 character::ordinal_offset(Vector2b offset) const
+{
+ return Vector2(offset);
+}
+
+entity_update_status character::update(size_t i, float dt)
{
auto [lr, ud, new_r] = arrows_to_dir(b_L, b_R, b_U, b_D);
if (!lr & !ud)
{
delta = 0;
- return false;
+ return entity_update_status::not_updated;
}
int nframes = allocate_frame_time(dt);
- rotate(i, new_r);
-
- if (!nframes)
- return false;
+ if (nframes == 0)
+ {
+ if (r == new_r) [[unlikely]]
+ return entity_update_status::not_updated;
+ rotate(i, new_r);
+ return entity_update_status::updated;
+ }
const auto vec = move_vec(lr, ud);
c->ensure_passability();
+ entity_update_status ret = entity_update_status::updated;
+
for (int k = 0; k < nframes; k++)
{
constexpr auto frac = Vector2(32767);
@@ -123,12 +133,22 @@ bool character::update(size_t i, float dt)
auto offset_ = vec + Vector2(offset_frac) * inv_frac;
offset_frac = Vector2s(Vector2(std::fmod(offset_[0], 1.f), std::fmod(offset_[1], 1.f)) * frac);
auto off_i = Vector2i(offset_);
+ const auto old_i = i;
if (can_move_to(off_i))
+ {
i = move_to(i, off_i, new_r);
+ if (i != old_i)
+ {
+ //Debug{} << "move_to repositioned" << i;
+ ret = entity_update_status::updated_repositioned;
+ }
+ }
+ else
+ break;
++frame %= atlas->info().nframes;
}
//Debug{} << "pos" << Vector2i(pos.local());
- return true;
+ return ret;
}
entity_type character::type() const noexcept { return entity_type::character; }