summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-17 10:38:44 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-17 10:38:44 +0200
commit66f89e04a50ad6ed8448c20c1731a3750d08e624 (patch)
treed1c5b55e86cdf52de34fd2624a5c85cd1e86da71
parent3b2e2ed05b593f2fdd8ec7153bddb6cd8dd1e246 (diff)
a
-rw-r--r--src/global-coords.hpp1
-rw-r--r--src/world.cpp6
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 <https://nullprogram.com/blog/2018/07/31/>
@@ -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;
}