feat(world-gen): add WormHash deterministic mixing function
This commit is contained in:
21
World/WorldGen/WormHash.cs
Normal file
21
World/WorldGen/WormHash.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace VoxelEngine.World.WorldGen;
|
||||
|
||||
// Deterministic 32-bit mixing hash for worm-cell coordinates.
|
||||
// Cell coords can be negative; cast through unchecked to preserve bit pattern.
|
||||
internal static class WormHash
|
||||
{
|
||||
public static uint Hash(int cellX, int cellY, int cellZ, int seed)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
uint h = (uint)seed;
|
||||
h ^= (uint)cellX * 73856093u;
|
||||
h ^= (uint)cellY * 19349663u;
|
||||
h ^= (uint)cellZ * 83492791u;
|
||||
h ^= h >> 13;
|
||||
h *= 0x5bd1e995u;
|
||||
h ^= h >> 15;
|
||||
return h;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user