summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-04 15:18:32 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-04 15:18:32 +0100
commita65aaeb43df61a9127aed0c4eb8dd4cb0b3b0bd6 (patch)
tree020f69f766545fa6fc960b3fdfcb4a7cda20313d /src
parent7fa7b3bc844d61ecc986f77819a11d1e4a526c57 (diff)
b
Diffstat (limited to 'src')
-rw-r--r--src/dijkstra.cpp3
-rw-r--r--src/path-search-node.hpp24
-rw-r--r--src/path-search-result.cpp13
-rw-r--r--src/path-search-result.hpp26
4 files changed, 42 insertions, 24 deletions
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<visited>& 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 <vector>
+#include <Corrade/Containers/Pointer.h>
+
+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<point> vec;
+
+private:
+ Pointer<node> _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 <Corrade/Containers/ArrayView.h>
#include <utility>
@@ -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<point>& { fm_assert(_node); return _node->vec; }
-auto path_search_result::path() const -> const std::vector<point>& { fm_assert(_node); return _node->vec; }
+vector_wrapper<point> path_search_result::raw_path() { fm_assert(_node); return {_node->vec}; }
+ArrayView<const point> 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 <vector>
#include <Corrade/Containers/Pointer.h>
namespace floormat {
+template<typename T> 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<point>& path();
- const std::vector<point>& path() const;
+ vector_wrapper<point> raw_path();
+ ArrayView<const point> path() const;
explicit operator ArrayView<const point>() 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<point> vec;
-
- private:
- Pointer<node> _next;
- };
+ struct node;
static Pointer<node> _pool; // NOLINT(*-avoid-non-const-global-variables)