diff options
Diffstat (limited to 'src/path-search.cpp')
-rw-r--r-- | src/path-search.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/path-search.cpp b/src/path-search.cpp index 739826be..f5a36feb 100644 --- a/src/path-search.cpp +++ b/src/path-search.cpp @@ -85,7 +85,8 @@ bool path_search::is_passable_(chunk* c0, const std::array<world::neighbor_pair, return true; } -bool path_search::is_passable(world& w, global_coords coord, Vector2b offset, Vector2ui size_, +bool path_search::is_passable(world& w, global_coords coord, + Vector2b offset, Vector2ui size_, object_id own_id, const pred& p) { auto center = iTILE_SIZE2 * Vector2i(coord.local()) + Vector2i(offset); @@ -94,23 +95,30 @@ bool path_search::is_passable(world& w, global_coords coord, Vector2b offset, Ve return is_passable(w, coord, {min, max}, own_id, p); } -bool path_search::is_passable(world& w, chunk_coords_ ch, const bbox<float>& bb, object_id own_id, const pred& p) +bool path_search::is_passable(world& w, struct detail_astar::cache& cache, global_coords coord, + Vector2b offset, Vector2ui size_, + object_id own_id, const pred& p) +{ + auto center = iTILE_SIZE2 * Vector2i(coord.local()) + Vector2i(offset); + auto size = Vector2(size_); + auto min = Vector2(center) - size*.5f, max = min + size; + return is_passable(w, cache, coord, {min, max}, own_id, p); +} + +bool path_search::is_passable(world& w, chunk_coords_ ch, const bbox<float>& bb, + object_id own_id, const pred& p) { auto* c = w.at(ch); auto neighbors = w.neighbors(ch); return is_passable_(c, neighbors, bb.min, bb.max, own_id, p); } -bool path_search::is_passable(world& w, struct detail_astar::cache& cache, chunk_coords_ ch0, const bbox<float>& bb, object_id own_id, const pred& p) +bool path_search::is_passable(world& w, struct detail_astar::cache& cache, chunk_coords_ ch0, + const bbox<float>& bb, object_id own_id, const pred& p) { - fm_debug_assert(!cache.size.isZero()); - std::array<world::neighbor_pair, 8> neighbors; - for (auto i = 0uz; const auto& x : world::neighbor_offsets) - { - auto ch = ch0 + x; - neighbors[i++] = { cache.try_get_chunk(w, ch), ch0 }; - } - return is_passable_(cache.try_get_chunk(w, ch0), neighbors, bb.min, bb.max, own_id, p); + auto* c = cache.try_get_chunk(w, ch0); + auto nbs = cache.get_neighbors(w, ch0); + return is_passable_(c, nbs, bb.min, bb.max, own_id, p); } } // namespace floormat |