Files
TheDeclineOfWarriors/Assets/Features/VoxelWorld/Runtime/WorldSeedUtility.cs
T
2026-04-08 09:22:05 +07:00

40 lines
1019 B
C#

namespace InfiniteWorld.VoxelWorld
{
internal static class WorldSeedUtility
{
public static uint Hash(params int[] values)
{
uint hash = 2166136261u;
for (int i = 0; i < values.Length; i++)
{
hash ^= unchecked((uint)values[i]);
hash *= 16777619u;
hash ^= hash >> 13;
hash *= 1274126177u;
}
return hash;
}
public static float Value01(uint hash)
{
return (hash & 0x00FFFFFFu) / 16777215f;
}
public static int Range(uint hash, int minInclusive, int maxExclusive)
{
if (maxExclusive <= minInclusive)
{
return minInclusive;
}
return minInclusive + (int)(hash % (uint)(maxExclusive - minInclusive));
}
public static long ToStableId(uint hashA, uint hashB)
{
return ((long)hashA << 32) | hashB;
}
}
}