summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-04-08 06:21:58 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-04-08 06:21:58 +0200
commitceec1ce9106f21ff1fd42c3b709937079480911b (patch)
treee6f550fedef7add515b8ddbb40e3426a10c05071 /src
parent06794499ce99020203c7c45294dad0d81bdca13d (diff)
b
Diffstat (limited to 'src')
-rw-r--r--src/critter.cpp99
-rw-r--r--src/critter.hpp29
2 files changed, 70 insertions, 58 deletions
diff --git a/src/critter.cpp b/src/critter.cpp
index 7c3d4285..d7fc8627 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -99,7 +99,19 @@ constexpr std::array<rotation, 3> rotation_to_similar(rotation r)
}
}
+template<rotation r> constexpr uint8_t get_length_axis()
+{
+ static_assert((int)r % 2 == 0);
+ using enum rotation;
+ if constexpr(r == N || r == S)
+ return 1;
+ else if constexpr(r == W || r == E)
+ return 0;
+ fm_assert(false);
+}
+
template<rotation new_r, bool MultiStep>
+CORRADE_ALWAYS_INLINE
bool update_movement_body(size_t& i, critter& C, const anim_def& info, uint8_t nsteps)
{
constexpr auto vec = rotation_to_vec(new_r);
@@ -152,69 +164,60 @@ bool update_movement_3way(size_t& i, critter& C, const anim_def& info)
return false;
}
-template<rotation r> constexpr uint8_t get_length_axis()
-{
- static_assert((int)r % 2 == 0);
- using enum rotation;
- if constexpr(r == N || r == S)
- return 1;
- else if constexpr(r == W || r == E)
- return 0;
- fm_assert(false);
-}
-
constexpr bool DoUnroll = true;
template<rotation new_r>
+requires (((int)new_r & 1) % 2 != 0)
CORRADE_ALWAYS_INLINE
bool update_movement_1(critter& C, size_t& i, const anim_def& info, uint32_t nframes)
{
- if constexpr((int)new_r & 1)
+ if constexpr(DoUnroll)
{
- if constexpr(DoUnroll)
+ //Debug{} << "< nframes" << nframes;
+ while (nframes > 1)
{
- //Debug{} << "< nframes" << nframes;
- while (nframes > 1)
- {
- auto len = (uint8_t)Math::min(nframes, (uint32_t)C.bbox_size.min());
- if (len <= 1)
- break;
- if (!update_movement_body<new_r, true>(i, C, info, len))
- break;
- //Debug{} << " " << len;
- nframes -= len;
- }
- //Debug{} << ">" << nframes;
+ auto len = (uint8_t)Math::min(nframes, (uint32_t)C.bbox_size.min());
+ if (len <= 1)
+ break;
+ if (!update_movement_body<new_r, true>(i, C, info, len))
+ break;
+ //Debug{} << " " << len;
+ nframes -= len;
}
-
- for (auto k = 0u; k < nframes; k++)
- if (!update_movement_3way<new_r>(i, C, info))
- return false;
+ //Debug{} << ">" << nframes;
}
- else
+
+ for (auto k = 0u; k < nframes; k++)
+ if (!update_movement_3way<new_r>(i, C, info))
+ return false;
+ return true;
+}
+
+template<rotation new_r>
+requires (((int)new_r & 1) % 2 == 0)
+CORRADE_NEVER_INLINE
+bool update_movement_1(critter& C, size_t& i, const anim_def& info, uint32_t nframes)
+{
+ if constexpr(DoUnroll)
{
- if constexpr(DoUnroll)
+ //Debug{} << "< nframes" << nframes;
+ while (nframes > 1)
{
- //Debug{} << "< nframes" << nframes;
- while (nframes > 1)
- {
- constexpr auto len_axis = get_length_axis<new_r>();
- auto len = (uint8_t)Math::min(nframes, (uint32_t)C.bbox_size.data()[len_axis]);
- if (len <= 1) [[unlikely]]
- break;
- if (!update_movement_body<new_r, true>(i, C, info, len))
- break;
- //Debug{} << " " << len;
- nframes -= len;
- }
- //Debug{} << ">" << nframes;
+ constexpr auto len_axis = get_length_axis<new_r>();
+ auto len = (uint8_t)Math::min(nframes, (uint32_t)C.bbox_size.data()[len_axis]);
+ if (len <= 1) [[unlikely]]
+ break;
+ if (!update_movement_body<new_r, true>(i, C, info, len))
+ break;
+ //Debug{} << " " << len;
+ nframes -= len;
}
-
- for (auto k = 0u; k < nframes; k++)
- if (!update_movement_body<new_r, false>(i, C, info, 0))
- return false;
+ //Debug{} << ">" << nframes;
}
+ for (auto k = 0u; k < nframes; k++)
+ if (!update_movement_body<new_r, false>(i, C, info, 0))
+ return false;
return true;
}
diff --git a/src/critter.hpp b/src/critter.hpp
index d19c3382..9bf4529f 100644
--- a/src/critter.hpp
+++ b/src/critter.hpp
@@ -45,16 +45,25 @@ struct critter final : object
float speed = 1;
uint16_t offset_frac_ = 0;
- struct movement_s {
- bool L : 1 = false,
- R : 1 = false,
- U : 1 = false,
- D : 1 = false,
- AUTO : 1 = false,
- _pad1 : 1 = false,
- _pad2 : 1 = false,
- _pad3 : 1 = false;
- } movement;
+ struct movement_s
+ {
+ bool L : 1 = false;
+ bool R : 1 = false;
+ bool U : 1 = false;
+ bool D : 1 = false;
+ bool AUTO : 1 = false;
+
+ bool _pad1 : 1;
+ bool _pad2 : 1;
+ bool _pad3 : 1;
+ //bool _pad4 : 1;
+ };
+
+ union
+ {
+ uint8_t movement_value = 0;
+ movement_s movement;
+ };
bool playable : 1 = false;