diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-06 16:04:17 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-06 16:04:17 +0200 |
| commit | 2085e643eb422eedba887c40ff4c6331f6f247c2 (patch) | |
| tree | ffc3f75a0dfbe55f361d81166ed0ede6d43f7e36 /src/critter.cpp | |
| parent | cb484be64de45ad6529952366273978502a17b6d (diff) | |
walk script wip
Diffstat (limited to 'src/critter.cpp')
| -rw-r--r-- | src/critter.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/critter.cpp b/src/critter.cpp index 4a4fa617..07f8466f 100644 --- a/src/critter.cpp +++ b/src/critter.cpp @@ -18,6 +18,8 @@ namespace floormat { namespace { +constexpr auto m_auto_mask = critter::move_u { .bits {.AUTO = true} }; + constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down) { constexpr unsigned L = 1 << 3, R = 1 << 2, U = 1 << 1, D = 1 << 0; @@ -341,14 +343,14 @@ bool critter_proto::operator==(const object_proto& e0) const return name == s0.name && playable == s0.playable; } -void critter::set_keys(bool L, bool R, bool U, bool D) -{ - movement = { L, R, U, D, movement.AUTO, false, false, false }; -} - -void critter::set_keys_auto() +void critter::set_keys(bool L, bool R, bool U, bool D) { moves = { L, R, U, D, moves.AUTO, }; } +void critter::set_keys_auto() { moves_ = m_auto_mask.val; } +void critter::clear_auto_movement() { moves_ &= ~m_auto_mask.val; } +bool critter::maybe_stop_auto_movement() { - movement = { false, false, false, false, true, false, false, false }; + bool b1 = moves_ == m_auto_mask.val; + bool b2 = moves.AUTO &= b1; + return !b2; } float critter::depth_offset() const @@ -372,13 +374,11 @@ void critter::update(const std::shared_ptr<object>& ptrʹ, size_t& i, const Ns& if (check_script_update_2(script.state())) [[unlikely]] return; #endif - if (playable && !movement.AUTO) [[unlikely]] + if (playable) [[unlikely]] { - movement.AUTO &= (movement.L | movement.R | movement.U | movement.D) == 0; - - if (!movement.AUTO) + if (!moves.AUTO) { - const auto new_r = arrows_to_dir(movement.L, movement.R, movement.U, movement.D); + const auto new_r = arrows_to_dir(moves.L, moves.R, moves.U, moves.D); if (new_r == rotation_COUNT) { offset_frac_ = {}; @@ -430,15 +430,10 @@ auto critter::move_toward(size_t& index, const Ns& dt, const point& dest) -> mov { fm_assert(is_dynamic()); - if (movement.L | movement.R | movement.U | movement.D) [[unlikely]] - return { .blocked = true, .moved = false, }; - const auto& info = atlas->info(); const auto nframes = alloc_frame_time(dt, delta, info.fps, speed); bool moved = false; - set_keys_auto(); - if (nframes == 0) return { .blocked = false, .moved = moved }; @@ -509,6 +504,8 @@ auto critter::move_toward(size_t& index, const Ns& dt, const point& dest) -> mov } } + // todo return unused movement frames into the offset_frac pool + if (!ok) [[unlikely]] { //Debug{} << "bad"; |
