From 66f89e04a50ad6ed8448c20c1731a3750d08e624 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 17 Oct 2022 10:38:44 +0200 Subject: a --- src/global-coords.hpp | 1 + src/world.cpp | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/global-coords.hpp b/src/global-coords.hpp index e51dc6aa..284c63c5 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -8,6 +8,7 @@ struct chunk_coords final { std::int16_t x = 0, y = 0; constexpr bool operator==(const chunk_coords& other) const noexcept = default; + constexpr operator std::size_t() const noexcept { return (std::uint32_t)y << 16 | (std::uint32_t)x; } }; struct global_coords final { diff --git a/src/world.cpp b/src/world.cpp index 56025587..5018b5c9 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -64,9 +64,8 @@ void world::collect() std::size_t world::hasher::operator()(chunk_coords c) const noexcept { - void _really_unreachable(); - std::size_t x = (std::size_t)c.y << 16 | (std::size_t)c.x; + if constexpr(sizeof(std::size_t) == 4) { // by Chris Wellons @@ -78,14 +77,13 @@ std::size_t world::hasher::operator()(chunk_coords c) const noexcept } else if constexpr(sizeof(std::size_t) == 8) { + // splitmix64 by George Marsaglia x ^= x >> 30; x *= 0xbf58476d1ce4e5b9U; x ^= x >> 27; x *= 0x94d049bb133111ebU; x ^= x >> 31; } - else - _really_unreachable(); return x; } -- cgit v1.2.3