diff options
-rw-r--r-- | editor/draw.cpp | 6 | ||||
-rw-r--r-- | src/global-coords.hpp | 17 | ||||
-rw-r--r-- | src/path-search-dijkstra.cpp | 10 | ||||
-rw-r--r-- | src/point.hpp | 2 |
4 files changed, 16 insertions, 19 deletions
diff --git a/editor/draw.cpp b/editor/draw.cpp index 429ce0fc..f482d373 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -28,7 +28,7 @@ void app::draw_cursor() if (cursor.tile && !cursor.in_imgui) { const auto draw = [&, pos = *cursor.tile](auto& mesh, const auto& size) { - const auto center = Vector3(pos.to_signed3() * iTILE_SIZE); + const auto center = Vector3(pos) * TILE_SIZE; mesh.draw(shader, {center, size, LINE_WIDTH}); }; @@ -58,7 +58,7 @@ void app::draw_cursor() shader.set_tint({1, 1, 1, 0.75f}); auto [_f, _w, anim_mesh] = M->meshes(); const auto offset = Vector3i(Vector2i(sel.offset), 0); - const auto pos = cursor.tile->to_signed3()*iTILE_SIZE + offset; + const auto pos = Vector3i(*cursor.tile)*iTILE_SIZE + offset; auto [ch, t] = w[*cursor.tile]; if (!ch.can_place_object(sel, cursor.tile->local())) shader.set_tint({1, 0, 1, 0.5f}); @@ -75,7 +75,7 @@ void app::draw_cursor() draw(_wireframe_quad, TILE_SIZE2); shader.set_tint({1, 1, 1, 0.75f}); auto [_f, _w, anim_mesh] = M->meshes(); - const auto pos = cursor.tile->to_signed3()*iTILE_SIZE; + const auto pos = Vector3i(*cursor.tile)*iTILE_SIZE; anim_mesh.draw(shader, *atlas, rotation::N, 0, Vector3(pos), 1); } } diff --git a/src/global-coords.hpp b/src/global-coords.hpp index e5218b17..8e0cf5a8 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -117,8 +117,7 @@ public: 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::Vector2<T>() const noexcept; template<typename T> explicit constexpr inline operator Math::Vector3<T>() const noexcept; constexpr bool operator==(const global_coords& other) const noexcept = default; @@ -152,20 +151,16 @@ constexpr int8_t global_coords::z() const noexcept return ((x >> 20) & 0x0f) - z0::value; } -constexpr Vector2i global_coords::to_signed() const noexcept +template<typename T> constexpr global_coords::operator Math::Vector2<T>() const noexcept { - return { int32_t((x & ~z_mask::value) - (s0::value<<4)), int32_t(y - (s0::value<<4)), }; + static_assert(std::is_signed_v<T> && sizeof(T) >= sizeof(int32_t)); + return { (T)int32_t((x & ~z_mask::value) - (s0::value<<4)), (T)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()); + return Math::Vector3<T>(Math::Vector2<T>(*this), (T)z()); } constexpr global_coords global_coords::operator+(Vector2i vec) const noexcept @@ -194,7 +189,7 @@ constexpr global_coords& global_coords::operator-=(Vector2i vec) noexcept constexpr Vector2i global_coords::operator-(global_coords other) const noexcept { - return to_signed() - other.to_signed(); + return Vector2i(*this) - Vector2i(other); } } // namespace floormat diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp index ec8ec502..69db2442 100644 --- a/src/path-search-dijkstra.cpp +++ b/src/path-search-dijkstra.cpp @@ -61,7 +61,7 @@ constexpr auto directions = []() constexpr template<typename T> requires std::is_arithmetic_v<T> -constexpr auto bbox_from_pos(Math::Vector<2, T> pos, Vector2b offset, Vector2ui size) +constexpr auto bbox_from_pos(Math::Vector2<T> pos, Vector2b offset, Vector2ui size) { const auto vec = Vector2i(pos) * iTILE_SIZE2 + Vector2i(offset); const auto min = vec - Vector2i(size / 2); @@ -257,7 +257,7 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o if (debug >= 2) [[unlikely]] DBG_nospace << "node" << " px:" << closest << " path:" << closest_path_len - << " pos:" << closest_pos.coord.to_signed() + << " pos:" << Vector3i(closest_pos.coord) << ";" << closest_pos.offset; #endif @@ -336,8 +336,10 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o fm_debug_assert(nodes.size() == indexes.size()); #ifndef FM_NO_DEBUG if (debug >= 1) - DBG_nospace << "dijkstra: closest px:" << closest << " path:" << closest_path_len - << " pos:" << closest_pos.coord.to_signed() << ";" << closest_pos.offset + DBG_nospace << "dijkstra: closest px:" << closest + << " path:" << closest_path_len + << " pos:" << Vector3i(closest_pos.coord) + << ";" << closest_pos.offset << " nodes:" << nodes.size() #if !FM_ASTAR_NO_EDGE_CACHE << " edges:" << edges.size() diff --git a/src/point.hpp b/src/point.hpp index b24f1015..0d9db1df 100644 --- a/src/point.hpp +++ b/src/point.hpp @@ -19,7 +19,7 @@ struct point constexpr std::strong_ordering operator<=>(const point& p1, const point& p2) noexcept { - auto c1 = p1.coord.to_signed3(), c2 = p2.coord.to_signed3(); + auto c1 = Vector3i(p1.coord), c2 = Vector3i(p2.coord); if (auto val = c1.z() <=> c2.z(); val != std::strong_ordering::equal) return val; |