diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-25 04:45:17 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-25 04:48:09 +0100 |
commit | 50e42d74c9b25e2ec4c6b9fd3434f431c0b5c3d9 (patch) | |
tree | 826691d937867e21587fd87adb2de6d34175eecd | |
parent | 4746d19f7a749808391d1ad7ee6bd86950ba064f (diff) |
rename path_search -> search
-rw-r--r-- | bench/dijkstra.cpp | 2 | ||||
-rw-r--r-- | editor/tests/region-test.cpp | 4 | ||||
-rw-r--r-- | src/astar.hpp | 14 | ||||
-rw-r--r-- | src/chunk-region.cpp | 12 | ||||
-rw-r--r-- | src/chunk-region.hpp | 4 | ||||
-rw-r--r-- | src/chunk.hpp | 4 | ||||
-rw-r--r-- | src/dijkstra.cpp | 14 | ||||
-rw-r--r-- | src/path-search.hpp | 49 | ||||
-rw-r--r-- | src/search-bbox.hpp (renamed from src/path-search-bbox.hpp) | 6 | ||||
-rw-r--r-- | src/search-node.hpp (renamed from src/path-search-node.hpp) | 2 | ||||
-rw-r--r-- | src/search-pred.hpp (renamed from src/path-search-pred.hpp) | 4 | ||||
-rw-r--r-- | src/search-result.cpp (renamed from src/path-search-result.cpp) | 6 | ||||
-rw-r--r-- | src/search-result.hpp (renamed from src/path-search-result.hpp) | 0 | ||||
-rw-r--r-- | src/search.cpp (renamed from src/path-search.cpp) | 14 | ||||
-rw-r--r-- | src/search.hpp | 49 | ||||
-rw-r--r-- | test/path-search-result.cpp | 4 | ||||
-rw-r--r-- | test/path-search.cpp | 6 |
17 files changed, 97 insertions, 97 deletions
diff --git a/bench/dijkstra.cpp b/bench/dijkstra.cpp index 8567796a..c525fdbb 100644 --- a/bench/dijkstra.cpp +++ b/bench/dijkstra.cpp @@ -1,5 +1,5 @@ #include "src/astar.hpp" -#include "src/path-search-result.hpp" +#include "src/search-result.hpp" #include "src/world.hpp" #include "loader/loader.hpp" #include <benchmark/benchmark.h> diff --git a/editor/tests/region-test.cpp b/editor/tests/region-test.cpp index dcec2ff2..907ea99c 100644 --- a/editor/tests/region-test.cpp +++ b/editor/tests/region-test.cpp @@ -14,8 +14,8 @@ namespace floormat::tests { namespace { using namespace floormat::imgui; -using detail_astar::div_count; -using detail_astar::div_size; +using Search::div_count; +using Search::div_size; constexpr auto chunk_bits = div_count.product(); constexpr auto div_min = -iTILE_SIZE2/2 + div_size/2; diff --git a/src/astar.hpp b/src/astar.hpp index 0a46ec6d..7c48c5db 100644 --- a/src/astar.hpp +++ b/src/astar.hpp @@ -1,10 +1,10 @@ #pragma once -#include "path-search.hpp" +#include "search.hpp" #include "point.hpp" #include <bitset> #include <Corrade/Containers/Array.h> -namespace floormat::detail_astar { +namespace floormat::Search { struct cache; struct chunk_cache; @@ -32,7 +32,7 @@ struct cache std::array<chunk*, 8> get_neighbors(world& w, chunk_coords_ ch0); }; -} // namespace floormat::detail_astar +} // namespace floormat::Search namespace floormat { @@ -46,7 +46,7 @@ public: point pt; }; - using pred = detail_astar::pred; + using pred = Search::pred; fm_DECLARE_DELETED_COPY_ASSIGNMENT(astar); @@ -57,17 +57,17 @@ public: // todo add simple bresenham short-circuit path_search_result Dijkstra(world& w, point from, point to, object_id own_id, uint32_t max_dist, Vector2ub own_size, - int debug = 0, const pred& p = detail_astar::never_continue()); + int debug = 0, const pred& p = Search::never_continue()); private: - static constexpr auto initial_capacity = TILE_COUNT * 16 * detail_astar::div_factor*detail_astar::div_factor; + static constexpr auto initial_capacity = TILE_COUNT * 16 * Search::div_factor*Search::div_factor; struct chunk_cache; void add_to_heap(uint32_t id); uint32_t pop_from_heap(); - struct detail_astar::cache cache; + struct Search::cache cache; Array<visited> nodes; Array<uint32_t> Q; }; diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp index 54696bc0..228b1052 100644 --- a/src/chunk-region.cpp +++ b/src/chunk-region.cpp @@ -1,5 +1,5 @@ #include "chunk-region.hpp" -#include "path-search-bbox.hpp" +#include "search-bbox.hpp" #include "world.hpp" #include "collision.hpp" #include "object.hpp" @@ -13,11 +13,11 @@ namespace floormat { namespace { -using detail_astar::bbox; -using detail_astar::div_factor; -using detail_astar::div_size; -using detail_astar::div_count; -using detail_astar::pred; +using Search::bbox; +using Search::div_factor; +using Search::div_size; +using Search::div_count; +using Search::pred; static_assert(div_count.x() == div_count.y()); static_assert((iTILE_SIZE2 % div_size).isZero()); diff --git a/src/chunk-region.hpp b/src/chunk-region.hpp index 5720e93e..579ab1ef 100644 --- a/src/chunk-region.hpp +++ b/src/chunk-region.hpp @@ -1,13 +1,13 @@ #pragma once #include "chunk.hpp" -#include "path-search.hpp" +#include "search.hpp" #include <bitset> namespace floormat { struct chunk::pass_region { - std::bitset<detail_astar::div_count.product()> bits; + std::bitset<Search::div_count.product()> bits; }; } // namespace floormat diff --git a/src/chunk.hpp b/src/chunk.hpp index 217bd35a..682482f7 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -5,7 +5,7 @@ #include "src/RTree-fwd.h" #include "global-coords.hpp" #include "wall-defs.hpp" -#include "path-search-pred.hpp" +#include "search-pred.hpp" #include <type_traits> #include <array> #include <Corrade/Containers/Array.h> @@ -121,7 +121,7 @@ public: const pass_region* get_pass_region(); void make_pass_region(pass_region& ret); - void make_pass_region(pass_region& ret, const detail_astar::pred& f); + void make_pass_region(pass_region& ret, const Search::pred& f); private: struct ground_stuff diff --git a/src/dijkstra.cpp b/src/dijkstra.cpp index 11c85d01..1f353e30 100644 --- a/src/dijkstra.cpp +++ b/src/dijkstra.cpp @@ -1,5 +1,5 @@ #include "astar.hpp" -#include "path-search-bbox.hpp" +#include "search-bbox.hpp" #include "compat/format.hpp" #include "compat/vector-wrapper.hpp" #include "compat/heap.hpp" @@ -16,10 +16,10 @@ namespace floormat { using visited = astar::visited; -using detail_astar::bbox; -using detail_astar::div_size; -using detail_astar::div_factor; -using detail_astar::min_size; +using Search::bbox; +using Search::div_size; +using Search::div_factor; +using Search::min_size; namespace { @@ -360,7 +360,7 @@ path_search_result astar::Dijkstra(world& w, const point from, const point to, } // namespace floormat -namespace floormat::detail_astar { +namespace floormat::Search { struct chunk_cache { @@ -498,4 +498,4 @@ std::array<chunk*, 8> cache::get_neighbors(world& w, chunk_coords_ ch0) return neighbors; } -} // namespace floormat::detail_astar +} // namespace floormat::Search diff --git a/src/path-search.hpp b/src/path-search.hpp deleted file mode 100644 index 05516676..00000000 --- a/src/path-search.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#include "tile-constants.hpp" -#include "global-coords.hpp" -#include "object-id.hpp" -#include "path-search-result.hpp" -#include "path-search-pred.hpp" -#include <array> - -namespace floormat { -class world; -struct object; -class chunk; -} // namespace floormat - -// todo add pathfinding sub-namespace - -namespace floormat::detail_astar { - -template<typename T> struct bbox; -struct cache; -struct chunk_cache; -constexpr inline int div_factor = 4; -constexpr inline auto div_size = iTILE_SIZE2 / div_factor; -constexpr inline auto min_size = Vector2ui(div_size * 2); -constexpr inline auto div_count = iTILE_SIZE2 * TILE_MAX_DIM / detail_astar::div_size; - -} // namespace floormat::detail_astar - -namespace floormat { - -struct path_search_result; - -class path_search final -{ - friend struct path_search_result; - template<typename T> using bbox = detail_astar::bbox<T>; - using pred = detail_astar::pred; - -public: - static bool is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id own_id, const pred& p = detail_astar::never_continue()); - static bool is_passable_(chunk* c0, const std::array<chunk*, 8>& neighbors, - Vector2 min, Vector2 max, object_id own_id, const pred& p = detail_astar::never_continue()); - static bool is_passable(world& w, global_coords coord, Vector2b offset, Vector2ui size, object_id own_id, const pred& p = detail_astar::never_continue()); - static bool is_passable(world& w, struct detail_astar::cache& cache, global_coords coord, Vector2b offset, Vector2ui size, object_id own_id, const pred& p = detail_astar::never_continue()); - static bool is_passable(world& w, chunk_coords_ ch0, const bbox<float>& bb, object_id own_id, const pred& p = detail_astar::never_continue()); - static bool is_passable(world& w, struct detail_astar::cache& cache, chunk_coords_ ch0, const bbox<float>& bb, object_id own_id, const pred& p = detail_astar::never_continue()); -}; - -} // namespace floormat diff --git a/src/path-search-bbox.hpp b/src/search-bbox.hpp index 05ed726d..0d211daf 100644 --- a/src/path-search-bbox.hpp +++ b/src/search-bbox.hpp @@ -1,10 +1,10 @@ #pragma once -#include "path-search.hpp" +#include "search.hpp" #include <concepts> #include <Magnum/Math/Vector2.h> #include <Magnum/DimensionTraits.h> -namespace floormat::detail_astar { +namespace floormat::Search { template<typename T> struct bbox { @@ -22,4 +22,4 @@ template<typename T> struct bbox } }; -} // namespace floormat::detail_astar +} // namespace floormat::Search diff --git a/src/path-search-node.hpp b/src/search-node.hpp index ecad6a77..c2977f84 100644 --- a/src/path-search-node.hpp +++ b/src/search-node.hpp @@ -1,6 +1,6 @@ #pragma once #include "compat/defs.hpp" -#include "path-search-result.hpp" +#include "search-result.hpp" #include <vector> #include <Corrade/Containers/Pointer.h> diff --git a/src/path-search-pred.hpp b/src/search-pred.hpp index f0f99c3e..c2967549 100644 --- a/src/path-search-pred.hpp +++ b/src/search-pred.hpp @@ -8,11 +8,11 @@ enum class path_search_continue : bool { pass = false, blocked = true }; } // namespace floormat -namespace floormat::detail_astar { +namespace floormat::Search { using pred = fu2::function_view<path_search_continue(collision_data) const>; const pred& never_continue() noexcept; const pred& always_continue() noexcept; -} // namespace floormat::detail_astar +} // namespace floormat::Search diff --git a/src/path-search-result.cpp b/src/search-result.cpp index afc4bf59..ba94b6f0 100644 --- a/src/path-search-result.cpp +++ b/src/search-result.cpp @@ -1,8 +1,8 @@ -#include "path-search-result.hpp" -//#include "path-search.hpp" +#include "search-result.hpp" +//#include "search.hpp" #include "compat/assert.hpp" #include "compat/vector-wrapper.hpp" -#include "path-search-node.hpp" +#include "search-node.hpp" #include "src/point.hpp" #include <Corrade/Containers/ArrayView.h> #include <utility> diff --git a/src/path-search-result.hpp b/src/search-result.hpp index d29fdc44..d29fdc44 100644 --- a/src/path-search-result.hpp +++ b/src/search-result.hpp diff --git a/src/path-search.cpp b/src/search.cpp index a41c2820..9f497134 100644 --- a/src/path-search.cpp +++ b/src/search.cpp @@ -1,5 +1,5 @@ -#include "path-search.hpp" -#include "path-search-bbox.hpp" +#include "search.hpp" +#include "search-bbox.hpp" #include "astar.hpp" #include "global-coords.hpp" #include "world.hpp" @@ -8,7 +8,7 @@ #include "compat/function2.hpp" #include <bit> -namespace floormat::detail_astar { +namespace floormat::Search { namespace { constexpr auto never_continue_1 = [](collision_data) constexpr { return path_search_continue::blocked; }; @@ -21,11 +21,11 @@ const pred& never_continue() noexcept { return never_continue_; } const pred& always_continue() noexcept { return always_continue_; } //static_assert(1 << 2 == div_factor); -} // namespace floormat::detail_astar +} // namespace floormat::Search namespace floormat { -using namespace detail_astar; +using namespace Search; bool path_search::is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id own_id, const pred& p) { @@ -98,7 +98,7 @@ bool path_search::is_passable(world& w, global_coords coord, return is_passable(w, coord, {min, max}, own_id, p); } -bool path_search::is_passable(world& w, struct detail_astar::cache& cache, global_coords coord, +bool path_search::is_passable(world& w, struct Search::cache& cache, global_coords coord, Vector2b offset, Vector2ui size_, object_id own_id, const pred& p) { @@ -116,7 +116,7 @@ bool path_search::is_passable(world& w, chunk_coords_ ch, const bbox<float>& bb, 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, +bool path_search::is_passable(world& w, struct Search::cache& cache, chunk_coords_ ch0, const bbox<float>& bb, object_id own_id, const pred& p) { auto* c = cache.try_get_chunk(w, ch0); diff --git a/src/search.hpp b/src/search.hpp new file mode 100644 index 00000000..024c8613 --- /dev/null +++ b/src/search.hpp @@ -0,0 +1,49 @@ +#pragma once +#include "tile-constants.hpp" +#include "global-coords.hpp" +#include "object-id.hpp" +#include "search-result.hpp" +#include "search-pred.hpp" +#include <array> + +namespace floormat { +class world; +struct object; +class chunk; +} // namespace floormat + +// todo add pathfinding sub-namespace + +namespace floormat::Search { + +template<typename T> struct bbox; +struct cache; +struct chunk_cache; +constexpr inline int div_factor = 4; +constexpr inline auto div_size = iTILE_SIZE2 / div_factor; +constexpr inline auto min_size = Vector2ui(div_size * 2); +constexpr inline auto div_count = iTILE_SIZE2 * TILE_MAX_DIM / Search::div_size; + +} // namespace floormat::Search + +namespace floormat { + +struct path_search_result; + +class path_search final +{ + friend struct path_search_result; + template<typename T> using bbox = Search::bbox<T>; + using pred = Search::pred; + +public: + static bool is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id own_id, const pred& p = Search::never_continue()); + static bool is_passable_(chunk* c0, const std::array<chunk*, 8>& neighbors, + Vector2 min, Vector2 max, object_id own_id, const pred& p = Search::never_continue()); + static bool is_passable(world& w, global_coords coord, Vector2b offset, Vector2ui size, object_id own_id, const pred& p = Search::never_continue()); + static bool is_passable(world& w, struct Search::cache& cache, global_coords coord, Vector2b offset, Vector2ui size, object_id own_id, const pred& p = Search::never_continue()); + static bool is_passable(world& w, chunk_coords_ ch0, const bbox<float>& bb, object_id own_id, const pred& p = Search::never_continue()); + static bool is_passable(world& w, struct Search::cache& cache, chunk_coords_ ch0, const bbox<float>& bb, object_id own_id, const pred& p = Search::never_continue()); +}; + +} // namespace floormat diff --git a/test/path-search-result.cpp b/test/path-search-result.cpp index 3f9782b4..1ff90ad8 100644 --- a/test/path-search-result.cpp +++ b/test/path-search-result.cpp @@ -1,7 +1,7 @@ #include "app.hpp" #include "compat/assert.hpp" -#include "src/path-search-result.hpp" -#include "src/path-search-node.hpp" +#include "src/search-result.hpp" +#include "src/search-node.hpp" namespace floormat { diff --git a/test/path-search.cpp b/test/path-search.cpp index 4541d3f6..1d9df3f3 100644 --- a/test/path-search.cpp +++ b/test/path-search.cpp @@ -5,13 +5,13 @@ #include "loader/wall-cell.hpp" #include "src/world.hpp" #include "src/scenery.hpp" -#include "src/path-search-bbox.hpp" +#include "src/search-bbox.hpp" #include <Magnum/Math/Functions.h> namespace floormat { -using namespace floormat::detail_astar; -using detail_astar::bbox; +using namespace floormat::Search; +using Search::bbox; namespace { |