From 534b0a84452e28dd98c608069a470e4a7f98f97e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 21 Feb 2022 17:11:49 +0100 Subject: flush --- tile.hpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'tile.hpp') diff --git a/tile.hpp b/tile.hpp index 8cf5eaa7..b014aa89 100644 --- a/tile.hpp +++ b/tile.hpp @@ -40,22 +40,23 @@ struct chunk_coords final { }; struct global_coords final { - decltype(chunk_coords{}.x) x = 0, y = 0; + decltype(chunk_coords::x) x = 0, y = 0; constexpr global_coords() noexcept = default; - constexpr global_coords(decltype(x) x, decltype(x) y) noexcept : x{x}, y{y} {} + constexpr global_coords(decltype(x) x, decltype(y) y) noexcept : x{x}, y{y} {} - constexpr std::size_t to_index() const noexcept { - using type = std::make_unsigned_t; - return (std::size_t)(type)y * (1 << sizeof(x)*8) + (std::size_t)(type)x; - } + constexpr std::size_t to_index() const noexcept; }; +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); + struct chunk final { static constexpr std::size_t N = 16; static constexpr std::size_t TILE_COUNT = N*N; - using index_type = decltype(local_coords{}.x); + using index_type = decltype(local_coords::x); using tile_index_array_type = std::array; //static constexpr inline local_coords center = { (index_type)(N/2), (index_type)(N/2) }; @@ -129,6 +130,10 @@ struct hash_chunk final { struct world final { + static_assert(sizeof(chunk_coords::x) <= sizeof(std::size_t)/2); + using max_coord_bits = std::integral_constant; + static_assert(max_coord_bits::value*4/3/8 == sizeof(decltype(chunk_coords::x))); + explicit world(); template std::shared_ptr ensure_chunk(chunk_coords xy, F&& fun); @@ -139,10 +144,6 @@ private: template std::shared_ptr world::ensure_chunk(chunk_coords xy, F&& fun) { - static_assert(sizeof(xy.x) <= sizeof(std::size_t)/2); - using max_coord_bits = std::integral_constant; - static_assert(max_coord_bits::value*4/3/8 == sizeof(decltype(xy.x))); - ASSERT(xy.x < 1 << max_coord_bits::value); ASSERT(xy.y < 1 << max_coord_bits::value); @@ -157,8 +158,10 @@ std::shared_ptr world::ensure_chunk(chunk_coords xy, F&& fun) } } -static_assert(std::is_same_v); -static_assert(std::is_same_v); -static_assert(std::is_same_v); +constexpr std::size_t global_coords::to_index() const noexcept +{ + using type = std::make_unsigned_t; + return (std::size_t)(type)y * (1 << sizeof(x)*8) + (std::size_t)(type)x; +} } //namespace Magnum::Examples -- cgit v1.2.3