Skip to content

Commit

Permalink
PPather: MPQTriangeSupplier: Replace loop with formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Xian55 committed Sep 19, 2023
1 parent 1d0fb16 commit 45855c0
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions PPather/Triangles/MPQTriangleSupplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,11 @@ private void GetChunkData(TriangleCollection triangles, int chunk_x, int chunk_y
[SkipLocalsInit]
private static void GetChunkCoord(float x, float y, out int chunk_x, out int chunk_y)
{
// yeah, this is ugly. But safe
for (chunk_x = 0; chunk_x < 64; chunk_x++)
{
float max_y = ChunkReader.ZEROPOINT - (chunk_x * ChunkReader.TILESIZE);
float min_y = max_y - ChunkReader.TILESIZE;
if (y >= min_y - 0.1f && y < max_y + 0.1f)
break;
}
for (chunk_y = 0; chunk_y < 64; chunk_y++)
{
float max_x = ChunkReader.ZEROPOINT - (chunk_y * ChunkReader.TILESIZE);
float min_x = max_x - ChunkReader.TILESIZE;
if (x >= min_x - 0.1f && x < max_x + 0.1f)
break;
}
float xOffset = ChunkReader.ZEROPOINT - y;
float yOffset = ChunkReader.ZEROPOINT - x;

chunk_x = (int)Round(xOffset / ChunkReader.TILESIZE) - 1;
chunk_y = (int)Round(yOffset / ChunkReader.TILESIZE) - 1;
}

[SkipLocalsInit]
Expand Down

0 comments on commit 45855c0

Please sign in to comment.