From 079696334dc0cb61b61788be99ed19bceb4c1fcd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 18 Nov 2024 03:11:08 +0100 Subject: src/{critter,chunk}: simplify LUT generation a bit --- src/critter.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/critter.cpp') diff --git a/src/critter.cpp b/src/critter.cpp index 5952bfd9..e99eb3a4 100644 --- a/src/critter.cpp +++ b/src/critter.cpp @@ -55,15 +55,15 @@ constexpr rotation arrows_to_dir_from_mask(unsigned mask) fm_assert(false); } -constexpr auto arrows_to_dir_array = map(arrows_to_dir_from_mask, iota_array); - constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down) { + constexpr auto table = map(arrows_to_dir_from_mask, iota_array); constexpr uint8_t L = 1 << 3, R = 1 << 2, U = 1 << 1, D = 1 << 0; - const uint8_t bits = left*L | right*R | up*U | down*D; constexpr uint8_t mask = L|R|U|D; + + const uint8_t bits = left*L | right*R | up*U | down*D; CORRADE_ASSUME((bits & mask) == bits); - return arrows_to_dir_array.data()[bits]; + return table.data()[bits]; } #if 0 @@ -301,10 +301,10 @@ constexpr rotation dir_from_step_mask(uint8_t val) } } -constexpr auto dir_from_step_array = map(dir_from_step_mask, iota_array); - constexpr rotation dir_from_step(step_s step) { + constexpr auto table = map(dir_from_step_mask, iota_array); + if (step.direction.isZero()) [[unlikely]] return rotation_COUNT; @@ -312,7 +312,7 @@ constexpr rotation dir_from_step(step_s step) auto y = uint8_t(step.direction.y() + 1); //fm_debug_assert((x & 3) == x && (y & 3) == y); auto val = uint8_t(x << 2 | y); - return dir_from_step_array.data()[val]; + return table.data()[val]; } constexpr step_s next_step(point from, point to) -- cgit v1.2.3