[Add] Base Logic
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user