Skip to content

Commit

Permalink
Use rented array instead of allocating
Browse files Browse the repository at this point in the history
(cherry picked from commit ff930712ee2c806753f39b7565f50e03a988691f)
  • Loading branch information
wrenge authored and ikpil committed Nov 21, 2024
1 parent 5413d8a commit 24b8a68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/DotRecast.Detour/DtNavMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,11 @@ int GetNeighbourTilesAt(int x, int y, int side, DtMeshTile[] tiles, int maxTiles
}

public int GetTilesAt(int x, int y, DtMeshTile[] tiles, int maxTiles)
{
return GetTilesAt(x, y, (Span<DtMeshTile>)tiles, maxTiles);
}

public int GetTilesAt(int x, int y, Span<DtMeshTile> tiles, int maxTiles)
{
int n = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/DotRecast.Detour/DtNavMeshQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ public DtStatus QueryPolygons(RcVec3f center, RcVec3f halfExtents, IDtQueryFilte
m_nav.CalcTileLoc(bmax, out var maxx, out var maxy);

const int MAX_NEIS = 32;
DtMeshTile[] neis = new DtMeshTile[MAX_NEIS];
using RcRentedArray<DtMeshTile> neisRent = RcRentedArray.Rent<DtMeshTile>(MAX_NEIS);
Span<DtMeshTile> neis = neisRent.AsSpan();

for (int y = miny; y <= maxy; ++y)
{
Expand Down

0 comments on commit 24b8a68

Please sign in to comment.