diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-27 10:09:24 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-27 10:48:28 +0200 |
commit | 9c54e30caf785643c18aa254c56d90c6dafe2db7 (patch) | |
tree | 85ab8331c18fdf1d0b160ce06daec61567dead0e /src/path-search.hpp | |
parent | 030fe37d5a5c448ab2eda72c3caae145671e15ba (diff) |
a
Diffstat (limited to 'src/path-search.hpp')
-rw-r--r-- | src/path-search.hpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/path-search.hpp b/src/path-search.hpp index 04c20302..6004e700 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -4,6 +4,7 @@ #include "object-id.hpp" #include "rotation.hpp" #include "world.hpp" +#include "compat/function2.fwd.hpp" #include <array> #include <bitset> #include <memory> @@ -47,6 +48,8 @@ private: size_t _size = 0; }; +enum class path_search_continue : bool { pass = false, blocked = true }; + class path_search final { struct neighbors final @@ -80,24 +83,27 @@ public: struct bbox { Vector2 min, max; }; + using pred = fu2::function_view<path_search_continue(collision_data) const>; + static const pred& never_continue() noexcept; + void ensure_allocated(chunk_coords a, chunk_coords b); - void fill_cache(world& w, Vector2i cmin, Vector2i cmax, int8_t z, Vector2ub own_size, object_id own_id); - void fill_cache_(world& w, chunk_coords_ coord, Vector2ub own_size, object_id own_id); + void fill_cache(world& w, Vector2i cmin, Vector2i cmax, int8_t z, Vector2ub own_size, object_id own_id, const pred& p = never_continue()); + void fill_cache_(world& w, chunk_coords_ coord, Vector2ub own_size, object_id own_id, const pred& p = never_continue()); // todo remember to check from.z() == to.z() // todo add simple bresenham short-circuit - Optional<path_search_result> operator()(world& w, Vector2ub own_size, object_id own_id, global_coords from, Vector2b from_offset, global_coords to, Vector2b to_offset); - Optional<path_search_result> operator()(world& w, const object& obj, global_coords to, Vector2b to_offset); + Optional<path_search_result> dijkstra(world& w, Vector2ub own_size, object_id own_id, global_coords from, Vector2b from_offset, global_coords to, Vector2b to_offset, const pred& p = never_continue()); + Optional<path_search_result> dijkstra(world& w, const object& obj, global_coords to, Vector2b to_offset, const pred& p = never_continue()); - static bool is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id own_id); + static bool is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id own_id, const pred& p = never_continue()); static bool is_passable_(chunk* c0, const std::array<world::neighbor_pair, 8>& neighbors, - Vector2 min, Vector2 max, object_id own_id); - static bool is_passable(world& w, chunk_coords_ ch0, Vector2 min, Vector2 max, object_id own_id); - static bool is_passable(world& w, global_coords coord, Vector2b offset, Vector2ub size, object_id own_id); + Vector2 min, Vector2 max, object_id own_id, const pred& p = never_continue()); + static bool is_passable(world& w, chunk_coords_ ch0, Vector2 min, Vector2 max, object_id own_id, const pred& p = never_continue()); + static bool is_passable(world& w, global_coords coord, Vector2b offset, Vector2ub size, object_id own_id, const pred& p = never_continue()); static bbox make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, rotation r); static bbox bbox_union(bbox bb, Vector2i coord, Vector2b offset, Vector2ub size); - static neighbors get_walkable_neighbor_tiles(world& w, global_coords coord, Vector2ub size, object_id own_id); + static neighbors get_walkable_neighbor_tiles(world& w, global_coords coord, Vector2ub size, object_id own_id, const pred& p = never_continue()); }; } // namespace floormat |