From db09342af865ac5df7d4c35f25115ed39fbd0ddd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 24 Feb 2024 05:16:58 +0100 Subject: src: split bbox into its own header --- bench/dijkstra.cpp | 1 + src/dijkstra.cpp | 2 ++ src/path-search-bbox.hpp | 25 +++++++++++++++++++++++++ src/path-search.cpp | 1 + src/path-search.hpp | 25 +++---------------------- test/dijkstra.cpp | 1 + test/path-search.cpp | 4 ++-- 7 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 src/path-search-bbox.hpp diff --git a/bench/dijkstra.cpp b/bench/dijkstra.cpp index 0c771528..8567796a 100644 --- a/bench/dijkstra.cpp +++ b/bench/dijkstra.cpp @@ -1,5 +1,6 @@ #include "src/astar.hpp" #include "src/path-search-result.hpp" +#include "src/world.hpp" #include "loader/loader.hpp" #include #include diff --git a/src/dijkstra.cpp b/src/dijkstra.cpp index f3b07172..4ec71248 100644 --- a/src/dijkstra.cpp +++ b/src/dijkstra.cpp @@ -1,8 +1,10 @@ #include "astar.hpp" +#include "path-search-bbox.hpp" #include "compat/format.hpp" #include "compat/vector-wrapper.hpp" #include "compat/heap.hpp" #include "object.hpp" +#include "world.hpp" #include "point.hpp" #include #include diff --git a/src/path-search-bbox.hpp b/src/path-search-bbox.hpp new file mode 100644 index 00000000..05ed726d --- /dev/null +++ b/src/path-search-bbox.hpp @@ -0,0 +1,25 @@ +#pragma once +#include "path-search.hpp" +#include +#include +#include + +namespace floormat::detail_astar { + +template struct bbox +{ + static_assert(std::is_arithmetic_v); + + VectorTypeFor<2, T> min, max; + + constexpr bool operator==(const bbox&) const = default; + + template + requires std::is_arithmetic_v + explicit constexpr operator bbox() const { + using Vec = VectorTypeFor<2, U>; + return bbox{ Vec(min), Vec(max) }; + } +}; + +} // namespace floormat::detail_astar diff --git a/src/path-search.cpp b/src/path-search.cpp index 54f0b112..615b040e 100644 --- a/src/path-search.cpp +++ b/src/path-search.cpp @@ -1,4 +1,5 @@ #include "path-search.hpp" +#include "path-search-bbox.hpp" #include "astar.hpp" #include "global-coords.hpp" #include "world.hpp" diff --git a/src/path-search.hpp b/src/path-search.hpp index 3a32dbff..c48b5532 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -2,13 +2,10 @@ #include "tile-constants.hpp" #include "global-coords.hpp" #include "object-id.hpp" -#include "world.hpp" +#include "collision.hpp" #include "compat/function2.fwd.hpp" #include "path-search-result.hpp" -#include #include -#include -#include namespace floormat { class world; @@ -20,6 +17,7 @@ class chunk; namespace floormat::detail_astar { +template struct bbox; struct cache; struct chunk_cache; static constexpr int div_factor = 4; @@ -36,24 +34,9 @@ enum class path_search_continue : bool { pass = false, blocked = true }; class path_search final { friend struct path_search_result; + template using bbox = detail_astar::bbox; public: - template - requires std::is_arithmetic_v - struct bbox - { - VectorTypeFor<2, T> min, max; - - template - requires std::is_arithmetic_v - explicit constexpr operator bbox() const { - using Vec = VectorTypeFor<2, U>; - return bbox{ Vec(min), Vec(max) }; - } - - constexpr bool operator==(const bbox&) const = default; - }; - using pred = fu2::function_view; static const pred& never_continue() noexcept; @@ -68,6 +51,4 @@ public: static bool is_passable(world& w, struct detail_astar::cache& cache, chunk_coords_ ch0, const bbox& bb, object_id own_id, const pred& p = never_continue()); }; - - } // namespace floormat diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index b608f5fe..14015ade 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -1,5 +1,6 @@ #include "app.hpp" #include "src/astar.hpp" +#include "src/world.hpp" #include "loader/loader.hpp" #include "loader/wall-cell.hpp" #include diff --git a/test/path-search.cpp b/test/path-search.cpp index caaa55f2..99a2b0a8 100644 --- a/test/path-search.cpp +++ b/test/path-search.cpp @@ -5,14 +5,14 @@ #include "loader/wall-cell.hpp" #include "src/world.hpp" #include "src/scenery.hpp" -#include "src/path-search.hpp" +#include "src/path-search-bbox.hpp" #include namespace floormat { using namespace floormat::detail_astar; -template using bbox = path_search::bbox; using pred = path_search::pred; +using detail_astar::bbox; namespace { -- cgit v1.2.3