Skip to content

Commit 0796963

Browse files
committed
src/{critter,chunk}: simplify LUT generation a bit
1 parent 722f12e commit 0796963

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/chunk-walls.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "quads.hpp"
44
#include "wall-atlas.hpp"
55
#include "tile-bbox.hpp"
6-
#include "compat/iota.hpp"
7-
#include "compat/map.hpp"
86
#include "compat/unroll.hpp"
97
#include "RTree-search.hpp"
108
#include "shaders/shader.hpp"
@@ -133,11 +131,6 @@ constexpr std::array<quad_table_entry, 4> make_quad_table_entry(Group_ G)
133131
std::unreachable();
134132
}
135133

136-
constexpr auto quad_table = std::array{
137-
map(make_quad_table_entry<false>, iota_array<Group_, (size_t)Group_::COUNT>),
138-
map(make_quad_table_entry<true>, iota_array<Group_, (size_t)Group_::COUNT>),
139-
};
140-
141134
template<Group_ G, bool IsWest, typename F = float>
142135
constexpr auto get_quadʹ(minmax_v<F, 3> bounds, F d)
143136
{
@@ -151,7 +144,7 @@ constexpr auto get_quadʹ(minmax_v<F, 3> bounds, F d)
151144

152145
unroll<static_array_size<decltype(array)>>([&]<typename Index>(Index) {
153146
constexpr size_t i = Index::value;
154-
constexpr auto table = quad_table[IsWest][(size_t)G];
147+
constexpr auto table = make_quad_table_entry<IsWest>(G);
155148
constexpr auto e = table[i];
156149
array.data()[i] = { x[e.x] - dmx[e.dmx], y[e.y] - dmy[e.dmy], z[e.z], };
157150
});

src/critter.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ constexpr rotation arrows_to_dir_from_mask(unsigned mask)
5555
fm_assert(false);
5656
}
5757

58-
constexpr auto arrows_to_dir_array = map(arrows_to_dir_from_mask, iota_array<uint8_t, 16>);
59-
6058
constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)
6159
{
60+
constexpr auto table = map(arrows_to_dir_from_mask, iota_array<uint8_t, 16>);
6261
constexpr uint8_t L = 1 << 3, R = 1 << 2, U = 1 << 1, D = 1 << 0;
63-
const uint8_t bits = left*L | right*R | up*U | down*D;
6462
constexpr uint8_t mask = L|R|U|D;
63+
64+
const uint8_t bits = left*L | right*R | up*U | down*D;
6565
CORRADE_ASSUME((bits & mask) == bits);
66-
return arrows_to_dir_array.data()[bits];
66+
return table.data()[bits];
6767
}
6868

6969
#if 0
@@ -301,18 +301,18 @@ constexpr rotation dir_from_step_mask(uint8_t val)
301301
}
302302
}
303303

304-
constexpr auto dir_from_step_array = map(dir_from_step_mask, iota_array<uint8_t, 1 << 4>);
305-
306304
constexpr rotation dir_from_step(step_s step)
307305
{
306+
constexpr auto table = map(dir_from_step_mask, iota_array<uint8_t, 1 << 4>);
307+
308308
if (step.direction.isZero()) [[unlikely]]
309309
return rotation_COUNT;
310310

311311
auto x = uint8_t(step.direction.x() + 1);
312312
auto y = uint8_t(step.direction.y() + 1);
313313
//fm_debug_assert((x & 3) == x && (y & 3) == y);
314314
auto val = uint8_t(x << 2 | y);
315-
return dir_from_step_array.data()[val];
315+
return table.data()[val];
316316
}
317317

318318
constexpr step_s next_step(point from, point to)

0 commit comments

Comments
 (0)