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 /src | |
parent | 268e5aa4bfe6f46f1fd4b8ceb50c54904c7536bf (diff) |
a
Diffstat (limited to 'src')
-rw-r--r-- | src/path-search.cpp | 18 | ||||
-rw-r--r-- | src/path-search.hpp | 3 |
2 files changed, 21 insertions, 0 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; |