forked from mirror/DotRecast
Merge branch 'risky_optimizations'
This commit is contained in:
commit
7de4b51135
|
@ -23,6 +23,7 @@ using System.Collections.Generic;
|
|||
using DotRecast.Core;
|
||||
using DotRecast.Core.Buffers;
|
||||
using DotRecast.Core.Numerics;
|
||||
using CollectionExtensions = DotRecast.Core.Collections.CollectionExtensions;
|
||||
|
||||
namespace DotRecast.Detour
|
||||
{
|
||||
|
@ -33,6 +34,8 @@ namespace DotRecast.Detour
|
|||
/// @ingroup detour
|
||||
public class DtNavMeshQuery
|
||||
{
|
||||
public const int MAX_PATH_LENGTH = 256;
|
||||
|
||||
protected readonly DtNavMesh m_nav; //< Pointer to navmesh data.
|
||||
protected DtQueryData m_query; //< Sliced query state.
|
||||
|
||||
|
@ -882,7 +885,8 @@ namespace DotRecast.Detour
|
|||
float lastBestNodeCost = startNode.total;
|
||||
|
||||
DtRaycastHit rayHit = new DtRaycastHit();
|
||||
rayHit.path = new List<long>();
|
||||
using var pathRent = RcRentedArray.Rent<long>(MAX_PATH_LENGTH);
|
||||
rayHit.path = pathRent.AsArray();
|
||||
while (!m_openList.IsEmpty())
|
||||
{
|
||||
// Remove node from open list and put it in closed list.
|
||||
|
@ -1171,7 +1175,8 @@ namespace DotRecast.Detour
|
|||
}
|
||||
|
||||
var rayHit = new DtRaycastHit();
|
||||
rayHit.path = new List<long>();
|
||||
using var pathRent = RcRentedArray.Rent<long>(MAX_PATH_LENGTH);
|
||||
rayHit.path = pathRent.AsArray();
|
||||
|
||||
int iter = 0;
|
||||
while (iter < maxIter && !m_openList.IsEmpty())
|
||||
|
@ -2263,13 +2268,15 @@ namespace DotRecast.Detour
|
|||
out float t, out RcVec3f hitNormal, ref List<long> path)
|
||||
{
|
||||
DtRaycastHit hit = new DtRaycastHit();
|
||||
hit.path = path;
|
||||
using var pathRent = RcRentedArray.Rent<long>(MAX_PATH_LENGTH);
|
||||
hit.path = pathRent.AsArray();
|
||||
|
||||
DtStatus status = Raycast(startRef, startPos, endPos, filter, 0, ref hit, 0);
|
||||
|
||||
t = hit.t;
|
||||
hitNormal = hit.hitNormal;
|
||||
path = hit.path;
|
||||
path.Clear();
|
||||
CollectionExtensions.AddRange(path, new Span<long>(hit.path, 0, hit.pathCount));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -2335,7 +2342,7 @@ namespace DotRecast.Detour
|
|||
}
|
||||
|
||||
hit.t = 0;
|
||||
hit.path.Clear();
|
||||
hit.pathCount = 0;
|
||||
hit.pathCost = 0;
|
||||
|
||||
Span<RcVec3f> verts = stackalloc RcVec3f[m_nav.GetMaxVertsPerPoly() + 1];
|
||||
|
@ -2388,7 +2395,7 @@ namespace DotRecast.Detour
|
|||
}
|
||||
|
||||
// Store visited polygons.
|
||||
hit.path.Add(curRef);
|
||||
hit.AddPathNode(curRef);
|
||||
|
||||
// Ray end is completely inside the polygon.
|
||||
if (segMax == -1)
|
||||
|
|
|
@ -38,9 +38,16 @@ namespace DotRecast.Detour
|
|||
public int hitEdgeIndex;
|
||||
|
||||
/// Pointer to an array of reference ids of the visited polygons. [opt]
|
||||
public List<long> path;
|
||||
public long[] path;
|
||||
|
||||
public int pathCount;
|
||||
|
||||
/// The cost of the path until hit.
|
||||
public float pathCost;
|
||||
|
||||
public void AddPathNode(long nodeRef)
|
||||
{
|
||||
path[pathCount++] = nodeRef;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue