Skip to content

Commit

Permalink
src/{critter,chunk}: simplify LUT generation a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Nov 18, 2024
1 parent 722f12e commit 0796963
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
9 changes: 1 addition & 8 deletions src/chunk-walls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -133,11 +131,6 @@ constexpr std::array<quad_table_entry, 4> make_quad_table_entry(Group_ G)
std::unreachable();
}

constexpr auto quad_table = std::array{
map(make_quad_table_entry<false>, iota_array<Group_, (size_t)Group_::COUNT>),
map(make_quad_table_entry<true>, iota_array<Group_, (size_t)Group_::COUNT>),
};

template<Group_ G, bool IsWest, typename F = float>
constexpr auto get_quadʹ(minmax_v<F, 3> bounds, F d)
{
Expand All @@ -151,7 +144,7 @@ constexpr auto get_quadʹ(minmax_v<F, 3> bounds, F d)

unroll<static_array_size<decltype(array)>>([&]<typename Index>(Index) {
constexpr size_t i = Index::value;
constexpr auto table = quad_table[IsWest][(size_t)G];
constexpr auto table = make_quad_table_entry<IsWest>(G);
constexpr auto e = table[i];
array.data()[i] = { x[e.x] - dmx[e.dmx], y[e.y] - dmy[e.dmy], z[e.z], };
});
Expand Down
14 changes: 7 additions & 7 deletions src/critter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, 16>);

constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)
{
constexpr auto table = map(arrows_to_dir_from_mask, iota_array<uint8_t, 16>);
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
Expand Down Expand Up @@ -301,18 +301,18 @@ constexpr rotation dir_from_step_mask(uint8_t val)
}
}

constexpr auto dir_from_step_array = map(dir_from_step_mask, iota_array<uint8_t, 1 << 4>);

constexpr rotation dir_from_step(step_s step)
{
constexpr auto table = map(dir_from_step_mask, iota_array<uint8_t, 1 << 4>);

if (step.direction.isZero()) [[unlikely]]
return rotation_COUNT;

auto x = uint8_t(step.direction.x() + 1);
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)
Expand Down

0 comments on commit 0796963

Please sign in to comment.