Unity-Technologies / UniteAustinTechnicalPresentation

Other
761 stars 192 forks source link

Hashing algorithm is slow #2

Open gamemachine opened 6 years ago

gamemachine commented 6 years ago

Performance can be greatly increased here. I just pulled a few lines of C# code here from my own implementation, it is based on http://www.cs.ucf.edu/~jmesit/publications/scsc%202005.pdf

ConvFactor = 1.0f / CellSize;
Width = (int)(Max / CellSize);

int Hash(float x, float z)
{
     return (int)((x * ConvFactor)) + (int)((z * ConvFactor)) * Width;
}
gamemachine commented 6 years ago

One thing I forgot with this algorithm. It doesn't work with negative numbers. So you need to pad the coordinates to keep them positive. I didn't even check to see if your current implementation has that same issue, might be worth checking if not already considered.