diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 03:00:56 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 03:00:56 +0200 |
commit | 1a95ead477a0bebbb7017b6b0423ce82cca3ea78 (patch) | |
tree | dbc6728ff50ec2721ea2f61a0f13e3252d3eb763 /src | |
parent | b7c90db8cc966ed7bff33fba1a49de2c384e5e38 (diff) |
a
Diffstat (limited to 'src')
-rw-r--r-- | src/global-coords.hpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/global-coords.hpp b/src/global-coords.hpp index d3c36c96..182511ea 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -13,15 +13,18 @@ struct chunk_coords final { }; struct global_coords final { - std::uint32_t x = 1 << 15, y = 1 << 15; + static constexpr std::uint32_t _0u = 1 << 15; + static constexpr auto _0s = std::int32_t(_0u); + + std::uint32_t x = _0u, y = _0u; constexpr global_coords(chunk_coords c, local_coords xy) : - x{ std::uint32_t(c.x + (1 << 15)) << 4 | (xy.x & 0x0f) }, - y{ std::uint32_t(c.y + (1 << 15)) << 4 | (xy.y & 0x0f) } + x{ std::uint32_t(c.x + _0s) << 4 | (xy.x & 0x0f) }, + y{ std::uint32_t(c.y + _0s) << 4 | (xy.y & 0x0f) } {} constexpr global_coords(std::uint32_t x, std::uint32_t y) noexcept : x{x}, y{y} {} constexpr global_coords(std::int32_t x, std::int32_t y) noexcept : - x{std::uint32_t(x + (1 << 15))}, y{std::uint32_t(y + (1 << 15))} + x{std::uint32_t(x + _0s)}, y{std::uint32_t(y + _0s)} {} constexpr global_coords() noexcept = default; @@ -35,26 +38,17 @@ struct global_coords final { constexpr local_coords global_coords::local() const noexcept { - return { - std::uint8_t(x & 0x0f), - std::uint8_t(y & 0x0f), - }; + return { std::uint8_t(x & 0x0f), std::uint8_t(y & 0x0f), }; } constexpr chunk_coords global_coords::chunk() const noexcept { - return { - std::int16_t((x - (1 << 15)) >> 4), - std::int16_t((y - (1 << 15)) >> 4), - }; + return { std::int16_t((x - _0u) >> 4), std::int16_t((y - _0u) >> 4), }; } constexpr Vector2i global_coords::to_signed() const noexcept { - return { - std::int32_t(x - (1 << 15)), - std::int32_t(y - (1 << 15)), - }; + return { std::int32_t(x - _0s), std::int32_t(y - _0s), }; } } // namespace floormat |