summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/global-coords.hpp32
-rw-r--r--src/object.cpp5
-rw-r--r--src/object.hpp1
-rw-r--r--src/point.cpp23
-rw-r--r--src/point.hpp3
5 files changed, 58 insertions, 6 deletions
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index 017d7c90..e5218b17 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -14,12 +14,18 @@ struct chunk_coords final {
constexpr bool operator==(const chunk_coords& other) const noexcept = default;
template<typename T>
- requires (std::is_floating_point_v<T> || std::is_integral_v<T> && (sizeof(T) > sizeof(x) || std::is_same_v<T, std::decay_t<decltype(x)>>))
- explicit constexpr operator Math::Vector2<T>() const noexcept { return Math::Vector2<T>(T(x), T(y)); }
+ explicit constexpr operator Math::Vector2<T>() const noexcept
+ {
+ static_assert(std::is_signed_v<T> && sizeof(T) >= sizeof(int16_t));
+ return Math::Vector2<T>(T(x), T(y));
+ }
template<typename T>
- requires (std::is_floating_point_v<T> || std::is_integral_v<T> && (sizeof(T) > sizeof(x) || std::is_same_v<T, std::decay_t<decltype(x)>>))
- explicit constexpr operator Math::Vector3<T>() const noexcept { return Math::Vector3<T>(T(x), T(y), T(0)); }
+ explicit constexpr inline operator Math::Vector3<T>() const noexcept
+ {
+ static_assert(std::is_signed_v<T> && sizeof(T) >= sizeof(int16_t));
+ return Math::Vector3<T>(T(x), T(y), T(0));
+ }
constexpr Vector2i operator-(chunk_coords other) const noexcept { return Vector2i{x - other.x, y - other.y }; }
};
@@ -61,7 +67,13 @@ struct chunk_coords_ final {
constexpr Vector3i operator-(chunk_coords_ other) const noexcept { return Vector3i{x - other.x, y - other.y, z - other.z}; }
- explicit operator chunk_coords() const noexcept { return chunk_coords{x, y}; }
+ explicit constexpr inline operator chunk_coords() const noexcept { return chunk_coords{x, y}; }
+
+ template<typename T> explicit constexpr inline operator Math::Vector3<T>() const noexcept
+ {
+ static_assert(std::is_signed_v<T> && sizeof(T) >= sizeof(int16_t));
+ return Math::Vector3<T>(x, y, z);
+ }
};
constexpr inline int8_t chunk_z_min = -1, chunk_z_max = 14;
@@ -99,13 +111,15 @@ public:
constexpr local_coords local() const noexcept;
constexpr chunk_coords chunk() const noexcept;
- constexpr operator chunk_coords_() const noexcept; // todo make invoking this take less typing
+ constexpr chunk_coords_ chunk3() const noexcept { return chunk_coords_(*this); }
+ constexpr operator chunk_coords_() const noexcept;
constexpr raw_coords_ raw() const noexcept;
constexpr raw_coords raw() noexcept;
constexpr int8_t z() const noexcept;
constexpr Vector2i to_signed() const noexcept;
constexpr Vector3i to_signed3() const noexcept;
+ template<typename T> explicit constexpr inline operator Math::Vector3<T>() const noexcept;
constexpr bool operator==(const global_coords& other) const noexcept = default;
constexpr global_coords operator+(Vector2i vec) const noexcept;
@@ -143,6 +157,12 @@ constexpr Vector2i global_coords::to_signed() const noexcept
return { int32_t((x & ~z_mask::value) - (s0::value<<4)), int32_t(y - (s0::value<<4)), };
}
+template<typename T> constexpr global_coords::operator Math::Vector3<T>() const noexcept
+{
+ static_assert(std::is_signed_v<T> && sizeof(T) >= sizeof(int32_t));
+ return Math::Vector3<T>(to_signed3());
+}
+
constexpr Vector3i global_coords::to_signed3() const noexcept
{
return Vector3i(to_signed(), z());
diff --git a/src/object.cpp b/src/object.cpp
index ee21c14f..d5133337 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -132,6 +132,11 @@ point object::normalize_coords(global_coords coord, Vector2b cur_offset, Vector2
return { coord, Vector2b(off_new) };
}
+point object::normalize_coords(const point& pt, Vector2i delta)
+{
+ return object::normalize_coords(pt.coord, pt.offset, delta);
+}
+
template<bool neighbor = true>
static bool do_search(struct chunk* c, chunk_coords_ coord, object_id id, Vector2 min, Vector2 max, Vector2b off = {})
{
diff --git a/src/object.hpp b/src/object.hpp
index 3832572b..bd5066b9 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -77,6 +77,7 @@ struct object
object_type type_of() const noexcept;
static point normalize_coords(global_coords coord, Vector2b cur_offset, Vector2i delta);
+ static point normalize_coords(const point& pt, Vector2i delta);
virtual bool is_dynamic() const;
bool can_rotate(rotation new_r);
diff --git a/src/point.cpp b/src/point.cpp
new file mode 100644
index 00000000..23049a14
--- /dev/null
+++ b/src/point.cpp
@@ -0,0 +1,23 @@
+#include "point.hpp"
+
+namespace floormat {
+
+Debug& operator<<(Debug& dbg, const point& pt)
+{
+ const auto flags = dbg.flags();
+ dbg.setFlags(flags | Debug::Flag::NoSpace);
+
+ auto c = Vector3i(chunk_coords_{pt.coord});
+ auto t = Vector2i(pt.coord.local());
+
+ dbg << "point( ";
+ dbg << c << ", ";
+ dbg << t << ", ";
+ dbg << pt.offset;
+ dbg << " )";
+
+ dbg.setFlags(flags);
+ return dbg;
+}
+
+} // namespace floormat
diff --git a/src/point.hpp b/src/point.hpp
index 99c4acdf..b24f1015 100644
--- a/src/point.hpp
+++ b/src/point.hpp
@@ -1,5 +1,6 @@
#pragma once
#include "global-coords.hpp"
+#include <Corrade/Utility/Move.h>
#include <compare>
namespace floormat {
@@ -12,6 +13,8 @@ struct point
constexpr bool operator==(const point&) const = default;
friend constexpr std::strong_ordering operator<=>(const point& a, const point& b) noexcept;
+
+ friend Debug& operator<<(Debug& dbg, const point& pt);
};
constexpr std::strong_ordering operator<=>(const point& p1, const point& p2) noexcept