long[] -> Span<long>

This commit is contained in:
ikpil 2024-05-20 00:16:36 +09:00
parent c9a54d4b4e
commit ec9ebe28b9
6 changed files with 21 additions and 19 deletions

View File

@ -55,19 +55,15 @@ namespace DotRecast.Detour.Extras.Jumplink
RcAtomicBoolean found = new RcAtomicBoolean();
RcAtomicFloat minHeight = new RcAtomicFloat(pt.Y);
navMeshQuery.QueryPolygons(pt, halfExtents, DtQueryNoOpFilter.Shared, new DtCallbackPolyQuery((tile, poly, refs, count) =>
navMeshQuery.QueryPolygons(pt, halfExtents, DtQueryNoOpFilter.Shared, new DtCallbackPolyQuery((tile, poly, refs) =>
{
for (int i = 0; i < count; ++i)
var status = navMeshQuery.GetPolyHeight(refs, pt, out var h);
if (status.Succeeded())
{
var status = navMeshQuery.GetPolyHeight(refs[i], pt, out var h);
if (status.Succeeded())
if (h > minHeight.Get() && h < maxHeight)
{
if (h > minHeight.Get() && h < maxHeight)
{
minHeight.Exchange(h);
found.Set(true);
return;
}
minHeight.Exchange(h);
found.Set(true);
}
}
}));

View File

@ -4,16 +4,19 @@ namespace DotRecast.Detour
{
public class DtCallbackPolyQuery : IDtPolyQuery
{
private readonly Action<DtMeshTile, DtPoly[], long[], int> _callback;
private readonly Action<DtMeshTile, DtPoly, long> _callback;
public DtCallbackPolyQuery(Action<DtMeshTile, DtPoly[], long[], int> callback)
public DtCallbackPolyQuery(Action<DtMeshTile, DtPoly, long> callback)
{
_callback = callback;
}
public void Process(DtMeshTile tile, DtPoly[] poly, long[] refs, int count)
public void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count)
{
_callback?.Invoke(tile, poly, refs, count);
for (int i = 0; i < count; ++i)
{
_callback?.Invoke(tile, poly[i], refs[i]);
}
}
}
}

View File

@ -1,4 +1,5 @@
using DotRecast.Core;
using System;
using DotRecast.Core;
namespace DotRecast.Detour
{
@ -25,7 +26,7 @@ namespace DotRecast.Detour
return m_overflow;
}
public void Process(DtMeshTile tile, DtPoly[] poly, long[] refs, int count)
public void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count)
{
int numLeft = m_maxPolys - m_numCollected;
int toCopy = count;

View File

@ -20,7 +20,7 @@ namespace DotRecast.Detour
_nearestPoint = center;
}
public void Process(DtMeshTile tile, DtPoly[] poly, long[] refs, int count)
public void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count)
{
for (int i = 0; i < count; ++i)
{

View File

@ -580,7 +580,7 @@ namespace DotRecast.Detour
protected void QueryPolygonsInTile(DtMeshTile tile, RcVec3f qmin, RcVec3f qmax, IDtQueryFilter filter, IDtPolyQuery query)
{
const int batchSize = 32;
long[] polyRefs = new long[batchSize];
Span<long> polyRefs = stackalloc long[batchSize];
DtPoly[] polys = new DtPoly[batchSize];
int n = 0;

View File

@ -1,3 +1,5 @@
using System;
namespace DotRecast.Detour
{
/// Provides custom polygon query behavior.
@ -7,6 +9,6 @@ namespace DotRecast.Detour
{
/// Called for each batch of unique polygons touched by the search area in dtNavMeshQuery::queryPolygons.
/// This can be called multiple times for a single query.
void Process(DtMeshTile tile, DtPoly[] poly, long[] refs, int count);
void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count);
}
}