diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-06 12:52:06 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-06 12:52:06 +0200 |
commit | d402f109df796e691306879903ddf09b2328d9e6 (patch) | |
tree | 73dfd5a0eea545654dcf3b4250ff7b4ac91a027e | |
parent | 268e5aa4bfe6f46f1fd4b8ceb50c54904c7536bf (diff) |
a
-rw-r--r-- | src/path-search.cpp | 18 | ||||
-rw-r--r-- | src/path-search.hpp | 3 | ||||
-rw-r--r-- | test/path-search.cpp | 19 |
3 files changed, 25 insertions, 15 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp index 88026ed4..03f54422 100644 --- a/src/path-search.cpp +++ b/src/path-search.cpp @@ -124,6 +124,24 @@ static_assert(test_offsets2()); } // namespace +size_t path_search::cache_chunk_index(chunk_coords ch) +{ + auto ch_ = Vector2i(ch) - cache.start; + fm_assert(ch_ >= Vector2i{} && ch_ < cache.size); + auto index = ch_.y()*cache.size.x() + ch_.x(); + return (size_t)index; +} + +size_t path_search::cache_tile_index(local_coords tile, Vector2i subdiv) +{ + constexpr auto stride = TILE_MAX_DIM * (size_t)div; + auto jj = tile.y * (size_t)div + (size_t)subdiv.y(); + auto ii = tile.x * (size_t)div + (size_t)subdiv.x(); + auto index = jj * stride + ii; + fm_debug_assert(index < tile_count); + return index; +} + auto path_search::never_continue() noexcept -> const pred& { return never_continue_; } auto path_search::always_continue() noexcept -> const pred& { return always_continue_; } diff --git a/src/path-search.hpp b/src/path-search.hpp index 05abc941..bea1b76b 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -88,6 +88,9 @@ public: chunk_cache cache; + size_t cache_chunk_index(chunk_coords coord); + static size_t cache_tile_index(local_coords tile, Vector2i subdiv); + using pred = fu2::function_view<path_search_continue(collision_data) const>; static const pred& never_continue() noexcept; static const pred& always_continue() noexcept; diff --git a/test/path-search.cpp b/test/path-search.cpp index 269c8c79..9ff918e5 100644 --- a/test/path-search.cpp +++ b/test/path-search.cpp @@ -130,25 +130,14 @@ void test_bbox() search.ensure_allocated({}, {}); search.fill_cache_(w, {0, 0, 0}, {}, {}); - static constexpr auto c_idx = [](path_search& search, chunk_coords ch) { - auto ch_ = Vector2i(ch) - search.cache.start; - fm_assert(ch_ >= Vector2i{} && ch_ < search.cache.size); - return ch_.y()*search.cache.size.x() + ch_.x(); - }; - static constexpr auto t_idx = [](local_coords tile, Vector2i subdiv) constexpr { - constexpr auto stride = TILE_MAX_DIM * (size_t)div; - auto jj = tile.y * (size_t)div + (size_t)subdiv.y(); - auto ii = tile.x * (size_t)div + (size_t)subdiv.x(); - return jj * stride + ii; - }; constexpr auto check_N = [&](path_search& search, chunk_coords ch, local_coords tile, Vector2i subdiv) { - auto c = c_idx(search, ch); - auto t = t_idx(tile, subdiv); + auto c = search.cache_chunk_index(ch); + auto t = search.cache_tile_index(tile, subdiv); return search.cache.array[c].can_go_north[t]; }; constexpr auto check_W = [&](path_search& search, chunk_coords ch, local_coords tile, Vector2i subdiv) { - auto c = c_idx(search, ch); - auto t = t_idx(tile, subdiv); + auto c = search.cache_chunk_index(ch); + auto t = search.cache_tile_index(tile, subdiv); return search.cache.array[c].can_go_west[t]; }; |