- https://github.com/ikpil/DotRecast/issues/41
This commit is contained in:
ikpil 2024-05-06 14:34:46 +09:00
parent 884789a934
commit b165a3afed
1 changed files with 6 additions and 3 deletions

View File

@ -96,7 +96,9 @@ namespace DotRecast.Detour
} }
// Get connected polygons // Get connected polygons
List<long> neis = new List<long>(); const int maxNeis = 16;
Span<long> neis = stackalloc long[maxNeis];
int nneis = 0;
var status = navQuery.GetAttachedNavMesh().GetTileAndPolyByRef(path[0], out var tile, out var poly); var status = navQuery.GetAttachedNavMesh().GetTileAndPolyByRef(path[0], out var tile, out var poly);
if (status.Failed()) if (status.Failed())
@ -110,7 +112,8 @@ namespace DotRecast.Detour
DtLink link = tile.links[k]; DtLink link = tile.links[k];
if (link.refs != 0) if (link.refs != 0)
{ {
neis.Add(link.refs); if (nneis < maxNeis)
neis[nneis++] = link.refs;
} }
} }
@ -120,7 +123,7 @@ namespace DotRecast.Detour
int cut = 0; int cut = 0;
for (int i = Math.Min(maxLookAhead, path.Count) - 1; i > 1 && cut == 0; i--) for (int i = Math.Min(maxLookAhead, path.Count) - 1; i > 1 && cut == 0; i--)
{ {
for (int j = 0; j < neis.Count; j++) for (int j = 0; j < nneis; j++)
{ {
if (path[i] == neis[j]) if (path[i] == neis[j])
{ {