diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-16 23:15:43 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-16 23:15:43 +0200 |
commit | 69aaa0205ae096654015924c75fdf43fbe16f768 (patch) | |
tree | 4acb91644767af685bfc965421e940805d336685 /src/world.hpp | |
parent | 98e9636d33f5c6101888609a2d2193cee4fd6c64 (diff) |
a
Diffstat (limited to 'src/world.hpp')
-rw-r--r-- | src/world.hpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/world.hpp b/src/world.hpp index b21502e0..8cbaa710 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -6,15 +6,38 @@ namespace floormat { struct chunk_coords final { std::int16_t x = 0, y = 0; + + constexpr bool operator==(const chunk_coords& other) const noexcept = default; }; struct global_coords final { - std::int16_t cx = 0, cy = 0; - std::int32_t x = 0, y = 0; + std::uint32_t x = 0, y = 0; - constexpr global_coords(chunk_coords c, local_coords xy) - : cx{c.x}, cy{c.y}, x{xy.x}, y{xy.y} + 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) } {} + constexpr global_coords(std::uint32_t x, std::uint32_t y) noexcept : x{x}, y{y} {} + constexpr global_coords() noexcept = default; + + constexpr local_coords local() const noexcept; + constexpr chunk_coords chunk() const noexcept; + + constexpr bool operator==(const global_coords& other) const noexcept = default; }; +constexpr local_coords global_coords::local() const noexcept +{ + return { (std::uint8_t)(x % TILE_MAX_DIM), (std::uint8_t)(y % TILE_MAX_DIM) }; +} + + +constexpr chunk_coords global_coords::chunk() const noexcept +{ + return { + (std::int16_t)(std::int32_t(x >> 4) - (1 << 15)), + (std::int16_t)(std::int32_t(y >> 4) - (1 << 15)), + }; +} + } // namespace floormat |