diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-07 14:15:25 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-07 14:15:25 +0200 |
commit | e1e539709d6e197cd2f2118e14598fd8c7b42c7b (patch) | |
tree | 1da9003870abfc85cac79d732fc48583ff9e520e /src/world.hpp | |
parent | 405c6168198fe25eb791f048a37417e6cffb3c42 (diff) |
.
Diffstat (limited to 'src/world.hpp')
-rw-r--r-- | src/world.hpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/world.hpp b/src/world.hpp index 21b2c764..99b984c2 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -6,23 +6,24 @@ namespace Magnum::Examples { struct chunk_coords final { std::int16_t x = 0, y = 0; -#if 0 - static_assert(std::is_same_v<decltype(x), decltype(x)>); - static constexpr std::size_t max_bits = sizeof(chunk_coords::x)*8 * 3 / 4; - static_assert(max_bits*4/3/8 == sizeof(decltype(chunk_coords::x))); - constexpr chunk_coords(std::int16_t x, std::int16_t y); -#endif }; -#if 0 -constexpr chunk_coords::chunk_coords(std::int16_t x, std::int16_t y) : x{x}, y{y} { - using s = std::make_signed_t<std::size_t>; -} -#endif - struct global_coords final { - chunk_coords chunk; - local_coords tile; + std::int32_t x = 0, y = 0; + constexpr chunk_coords chunk() const noexcept; + constexpr chunk_coords local() const noexcept; }; +constexpr chunk_coords global_coords::chunk() const noexcept { + constexpr std::uint32_t mask = 0xffff0000u; + const auto x_ = (std::int16_t)(std::uint16_t)((std::uint32_t)x & mask >> 24), + y_ = (std::int16_t)(std::uint16_t)((std::uint32_t)y & mask >> 24); + return {x_, y_}; +} + +constexpr chunk_coords global_coords::local() const noexcept { + const auto x_ = (std::uint8_t)x, y_ = (std::uint8_t)y; + return {x_, y_}; +} + } // namespace Magnum::Examples |