summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/object.cpp2
-rw-r--r--src/path-search-dijkstra.cpp14
-rw-r--r--src/point.cpp2
-rw-r--r--src/point.hpp32
4 files changed, 29 insertions, 21 deletions
diff --git a/src/object.cpp b/src/object.cpp
index b2efb6a1..952f5765 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -149,7 +149,7 @@ point object::normalize_coords(global_coords coord, Vector2b cur, Vector2i new_o
point object::normalize_coords(const point& pt, Vector2i delta)
{
- return object::normalize_coords(pt.coord(), pt.offset, delta);
+ return object::normalize_coords(pt.coord(), pt.offset(), delta);
}
template<bool neighbor = true>
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp
index 7a4f9789..ff108829 100644
--- a/src/path-search-dijkstra.cpp
+++ b/src/path-search-dijkstra.cpp
@@ -81,7 +81,7 @@ uint32_t distance(point a, point b)
{
Vector2i dist;
dist += Math::abs(a.coord() - b.coord())*iTILE_SIZE2;
- dist += Vector2i(a.offset - b.offset);
+ dist += Vector2i(a.offset() - b.offset());
return (uint32_t)Math::sqrt(dist.dot());
}
@@ -143,9 +143,9 @@ uint32_t astar::pop_from_heap()
auto astar::make_edge(const point& a, const point& b) -> edge
{
if (a < b)
- return { a.coord, b.coord, a.offset, b.offset };
+ return { a.coord(), b.coord(), a.offset(), b.offset() };
else
- return { b.coord, a.coord, b.offset, a.offset };
+ return { b.coord(), a.coord(), b.offset(), a.offset() };
}
size_t astar::edge_hash::operator()(const edge& e) const
@@ -254,10 +254,10 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o
DBG_nospace << "node"
<< " px:" << closest << " path:" << closest_path_len
<< " pos:" << Vector3i(closest_pos.coord())
- << ";" << closest_pos.offset;
+ << ";" << closest_pos.offset();
#endif
- const auto bb0 = bbox_from_pos(Vector2(cur_pt.local()), cur_pt.offset, own_size);
+ const auto bb0 = bbox_from_pos(Vector2(cur_pt.local()), cur_pt.offset(), own_size);
for (auto [vec, len] : directions)
{
auto [new_coord, new_offset] = object::normalize_coords(cur_pt, vec);
@@ -288,7 +288,7 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o
continue;
}
#else
- auto e = make_edge(n_pt, {new_coord, new_offset});
+ auto e = make_edge(cur_pt, new_pt);
if (auto [it, fresh] = edges.try_emplace(e, edge_status::unknown); fresh)
{
auto& status = it.value();
@@ -335,7 +335,7 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o
DBG_nospace << "dijkstra: closest px:" << closest
<< " path:" << closest_path_len
<< " pos:" << Vector3i(closest_pos.coord())
- << ";" << closest_pos.offset
+ << ";" << closest_pos.offset()
<< " nodes:" << nodes.size()
#if !FM_ASTAR_NO_EDGE_CACHE
<< " edges:" << edges.size()
diff --git a/src/point.cpp b/src/point.cpp
index 67a79475..205e2a6a 100644
--- a/src/point.cpp
+++ b/src/point.cpp
@@ -9,7 +9,7 @@ Debug& operator<<(Debug& dbg, const point& pt)
auto c = Vector3i(pt.chunk3());
auto t = Vector2i(pt.local());
- auto o = pt.offset;
+ auto o = pt.offset();
dbg << "point{";
dbg << "{" << c.x() << "," << c.y() << "," << c.z() << "},";
diff --git a/src/point.hpp b/src/point.hpp
index fd23f72d..1ae511dd 100644
--- a/src/point.hpp
+++ b/src/point.hpp
@@ -18,26 +18,32 @@ namespace floormat {
struct point
{
- int16_t cx = 0, cy = 0;
- int8_t cz = 0;
- local_coords tile;
- Vector2b offset;
-
constexpr point();
constexpr point(global_coords coord, Vector2b offset);
constexpr point(chunk_coords_ coord, local_coords tile, Vector2b offset);
fm_DECLARE_DEFAULT_COPY_ASSIGNMENT(point);
- constexpr bool operator==(const point&) const noexcept = default;
+ constexpr bool operator==(const point&) const noexcept;
friend constexpr std::strong_ordering operator<=>(const point& a, const point& b);
constexpr global_coords coord() const;
constexpr chunk_coords chunk() const;
constexpr chunk_coords_ chunk3() const;
constexpr local_coords local() const;
+ constexpr Vector2b offset() const;
+ template<size_t N> std::tuple_element_t<N, point> constexpr get() const;
+
friend Debug& operator<<(Debug& dbg, const point& pt);
+
+private:
+ int16_t cx = 0, cy = 0;
+ int8_t cz = 0;
+ local_coords tile;
+ Vector2b _offset;
};
+constexpr bool point::operator==(const point&) const noexcept = default;
+
constexpr std::strong_ordering operator<=>(const point& p1, const point& p2)
{
if (auto val = p1.cz <=> p2.cz; val != std::strong_ordering::equal) return val;
@@ -45,8 +51,8 @@ constexpr std::strong_ordering operator<=>(const point& p1, const point& p2)
if (auto val = p1.cx <=> p2.cx; val != std::strong_ordering::equal) return val;
if (auto val = p1.tile.y <=> p2.tile.y; val != std::strong_ordering::equal) return val;
if (auto val = p1.tile.x <=> p2.tile.x; val != std::strong_ordering::equal) return val;
- if (auto val = p1.offset.y() <=> p2.offset.y(); val != std::strong_ordering::equal) return val;
- if (auto val = p1.offset.x() <=> p2.offset.x(); val != std::strong_ordering::equal) return val;
+ if (auto val = p1._offset.y() <=> p2._offset.y(); val != std::strong_ordering::equal) return val;
+ if (auto val = p1._offset.x() <=> p2._offset.x(); val != std::strong_ordering::equal) return val;
return std::strong_ordering::equal;
}
@@ -54,20 +60,22 @@ constexpr point::point() = default;
constexpr point::point(global_coords coord, Vector2b offset) : point{coord.chunk3(), coord.local(), offset} { }
constexpr point::point(chunk_coords_ coord, local_coords tile, Vector2b offset) :
- cx{coord.x}, cy{coord.y}, cz{coord.z}, tile{tile}, offset{offset}
+ cx{coord.x}, cy{coord.y}, cz{coord.z}, tile{tile}, _offset{offset}
{}
constexpr global_coords point::coord() const { return {{cx, cy}, tile, cz}; }
constexpr chunk_coords_ point::chunk3() const { return {cx, cy, cz}; }
constexpr chunk_coords point::chunk() const { return {cx, cy}; }
constexpr local_coords point::local() const { return tile; }
+constexpr Vector2b point::offset() const { return _offset; }
-template<size_t N> std::tuple_element_t<N, point> constexpr get(point pt) {
+template<size_t N> std::tuple_element_t<N, point> constexpr point::get() const
+{
static_assert(N < 2);
if constexpr(N == 0)
- return global_coords{{pt.cx, pt.cy}, pt.tile, pt.cz};
+ return global_coords{{cx, cy}, tile, cz};
if constexpr(N == 1)
- return pt.offset;
+ return _offset;
return {};
}