From a65aaeb43df61a9127aed0c4eb8dd4cb0b3b0bd6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 4 Feb 2024 15:18:32 +0100 Subject: b --- src/dijkstra.cpp | 3 ++- src/path-search-node.hpp | 24 ++++++++++++++++++++++++ src/path-search-result.cpp | 13 +++++++++---- src/path-search-result.hpp | 26 +++++++------------------- 4 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 src/path-search-node.hpp (limited to 'src') diff --git a/src/dijkstra.cpp b/src/dijkstra.cpp index 9081d5a7..c9433132 100644 --- a/src/dijkstra.cpp +++ b/src/dijkstra.cpp @@ -1,6 +1,7 @@ #include "path-search.hpp" #include "compat/format.hpp" #include "compat/debug.hpp" +#include "compat/vector-wrapper.hpp" #include "compat/heap.hpp" #include "object.hpp" #include "point.hpp" @@ -106,7 +107,7 @@ void set_result_from_idx(path_search_result& result, const Array& nodes { fm_debug_assert(idx != (uint32_t)-1); - auto& path = result.path(); + auto& path = result.raw_path().vec; path.clear(); const auto& to_node = nodes[idx]; diff --git a/src/path-search-node.hpp b/src/path-search-node.hpp new file mode 100644 index 00000000..ecad6a77 --- /dev/null +++ b/src/path-search-node.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "compat/defs.hpp" +#include "path-search-result.hpp" +#include +#include + +namespace floormat { + +struct path_search_result::node +{ + friend struct path_search_result; + friend struct test_app; + + node() noexcept; + fm_DECLARE_DELETED_COPY_ASSIGNMENT(node); + fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(node); + + std::vector vec; + +private: + Pointer _next; +}; + +} // namespace floormat diff --git a/src/path-search-result.cpp b/src/path-search-result.cpp index bc0ad31f..d805bd31 100644 --- a/src/path-search-result.cpp +++ b/src/path-search-result.cpp @@ -1,7 +1,9 @@ -#include "path-search.hpp" #include "path-search-result.hpp" -#include "src/point.hpp" +//#include "path-search.hpp" #include "compat/assert.hpp" +#include "compat/vector-wrapper.hpp" +#include "path-search-node.hpp" +#include "src/point.hpp" #include #include @@ -61,6 +63,9 @@ path_search_result& path_search_result::operator=(const path_search_result& x) n return *this; } +path_search_result::path_search_result(path_search_result&&) noexcept = default; +path_search_result& path_search_result::operator=(path_search_result&&) noexcept = default; + size_t path_search_result::size() const { return _node->vec.size(); } path_search_result::node::node() noexcept = default; float path_search_result::time() const { return _time; } @@ -88,7 +93,7 @@ const point& path_search_result::operator[](size_t index) const fm_debug_assert(index < _node->vec.size()); return data()[index]; } -auto path_search_result::path() -> std::vector& { fm_assert(_node); return _node->vec; } -auto path_search_result::path() const -> const std::vector& { fm_assert(_node); return _node->vec; } +vector_wrapper path_search_result::raw_path() { fm_assert(_node); return {_node->vec}; } +ArrayView path_search_result::path() const { fm_assert(_node); return {_node->vec.data(), _node->vec.size()}; } } // namespace floormat diff --git a/src/path-search-result.hpp b/src/path-search-result.hpp index fc02e1ba..8987a041 100644 --- a/src/path-search-result.hpp +++ b/src/path-search-result.hpp @@ -1,11 +1,11 @@ #pragma once #include "src/global-coords.hpp" #include "compat/defs.hpp" -#include #include namespace floormat { +template struct vector_wrapper; struct point; struct path_search_result final @@ -24,32 +24,20 @@ struct path_search_result final uint32_t distance() const; void set_distance(uint32_t dist); - std::vector& path(); - const std::vector& path() const; + vector_wrapper raw_path(); + ArrayView path() const; explicit operator ArrayView() const; explicit operator bool() const; - fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(path_search_result); + path_search_result(); path_search_result(const path_search_result& x) noexcept; path_search_result& operator=(const path_search_result& x) noexcept; - path_search_result(); + path_search_result(path_search_result&&) noexcept; + path_search_result& operator=(path_search_result&&) noexcept; ~path_search_result() noexcept; private: - struct node - { - friend struct path_search_result; - friend struct test_app; - - node() noexcept; - fm_DECLARE_DELETED_COPY_ASSIGNMENT(node); - fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(node); - - std::vector vec; - - private: - Pointer _next; - }; + struct node; static Pointer _pool; // NOLINT(*-avoid-non-const-global-variables) -- cgit v1.2.3