summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-07 21:11:34 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-07 21:11:34 +0200
commit4e36541f57c872c0f1308e559e5bddf367124aba (patch)
tree0e1c72ce5c4b15e9b80a033d122b17710c88f102
parentb9c715abb0ae43f58e5d03333d8858e6ab4904f2 (diff)
src: set global_coords data members as private
-rw-r--r--editor/editor.cpp15
-rw-r--r--src/global-coords.hpp13
2 files changed, 21 insertions, 7 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 9d283da0..f91467aa 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -37,15 +37,16 @@ auto editor::get_snap_value(snap_mode snap, int mods) const -> snap_mode
global_coords editor::apply_snap(global_coords pos, global_coords last, snap_mode snap) noexcept
{
+ auto rpos = pos.raw();
switch (snap)
{
default:
break;
case snap_mode::horizontal:
- pos.y = last.y;
+ rpos.y = last.raw().y;
break;
case snap_mode::vertical:
- pos.x = last.x;
+ rpos.x = last.raw().x;
break;
}
return pos;
@@ -66,14 +67,16 @@ void editor::on_mouse_move(world& world, global_coords& pos, int mods)
const auto draw_offset = draw_coord - last.draw_coord;
if (!!draw_offset[0] ^ !!draw_offset[1] && std::abs(draw_offset.sum()) > 1)
{
- const auto [minx, maxx] = std::minmax(draw_coord.x, last.draw_coord.x);
- const auto [miny, maxy] = std::minmax(draw_coord.y, last.draw_coord.y);
+ const auto drawc = draw_coord.raw();
+ auto lastc = last.draw_coord.raw();
+ const auto [minx, maxx] = std::minmax(drawc.x, lastc.x);
+ const auto [miny, maxy] = std::minmax(drawc.y, lastc.y);
if (draw_offset[0])
for (uint32_t i = minx; i <= maxx; i++)
- on_click_(world, { i, draw_coord.y, nullptr }, last.btn);
+ on_click_(world, { i, lastc.y, nullptr }, last.btn);
else
for (uint32_t j = miny; j <= maxy; j++)
- on_click_(world, { draw_coord.x, j, nullptr }, last.btn);
+ on_click_(world, { lastc.x, j, nullptr }, last.btn);
}
else
on_click_(world, draw_coord, last.btn);
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index 9df9e5de..4d420534 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -66,13 +66,19 @@ struct chunk_coords_ final {
constexpr inline int8_t chunk_z_min = -1, chunk_z_max = 14;
-struct global_coords final {
+struct global_coords final
+{
+ struct raw_coords final { uint32_t &x, &y; }; // NOLINT
+ struct raw_coords_ final { uint32_t x, y; };
+
+private:
using u0 = std::integral_constant<uint32_t, (1<<15)>;
using s0 = std::integral_constant<int32_t, int32_t(u0::value)>;
using z0 = std::integral_constant<int32_t, (1 << 0)>;
using z_mask = std::integral_constant<uint32_t, (1u << 4) - 1u << 20>;
uint32_t x = u0::value<<4|z0::value<<20, y = u0::value<<4;
+public:
constexpr global_coords() noexcept = default;
constexpr global_coords(chunk_coords c, local_coords xy, int8_t z) noexcept :
x{
@@ -94,6 +100,8 @@ struct global_coords final {
constexpr local_coords local() const noexcept;
constexpr chunk_coords chunk() const noexcept;
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;
@@ -122,6 +130,9 @@ constexpr global_coords::operator chunk_coords_() const noexcept
return chunk_coords_{ chunk(), z() };
}
+constexpr auto global_coords::raw() const noexcept -> raw_coords_ { return {x, y}; }
+constexpr auto global_coords::raw() noexcept -> raw_coords { return {x, y}; }
+
constexpr int8_t global_coords::z() const noexcept
{
return ((x >> 20) & 0x0f) - z0::value;