From 079696334dc0cb61b61788be99ed19bceb4c1fcd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 18 Nov 2024 03:11:08 +0100 Subject: [PATCH] src/{critter,chunk}: simplify LUT generation a bit --- src/chunk-walls.cpp | 9 +-------- src/critter.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index b759d465..3e708ee5 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -3,8 +3,6 @@ #include "quads.hpp" #include "wall-atlas.hpp" #include "tile-bbox.hpp" -#include "compat/iota.hpp" -#include "compat/map.hpp" #include "compat/unroll.hpp" #include "RTree-search.hpp" #include "shaders/shader.hpp" @@ -133,11 +131,6 @@ constexpr std::array make_quad_table_entry(Group_ G) std::unreachable(); } -constexpr auto quad_table = std::array{ - map(make_quad_table_entry, iota_array), - map(make_quad_table_entry, iota_array), -}; - template constexpr auto get_quadʹ(minmax_v bounds, F d) { @@ -151,7 +144,7 @@ constexpr auto get_quadʹ(minmax_v bounds, F d) unroll>([&](Index) { constexpr size_t i = Index::value; - constexpr auto table = quad_table[IsWest][(size_t)G]; + constexpr auto table = make_quad_table_entry(G); constexpr auto e = table[i]; array.data()[i] = { x[e.x] - dmx[e.dmx], y[e.y] - dmy[e.dmy], z[e.z], }; }); 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)