Skip to content

Commit

Permalink
long[] -> Span<long>
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed May 19, 2024
1 parent c9a54d4 commit ec9ebe2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
16 changes: 6 additions & 10 deletions src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,15 @@ private bool GetNavMeshHeight(DtNavMeshQuery navMeshQuery, RcVec3f pt, float cs,
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);
}
}
}));
Expand Down
11 changes: 7 additions & 4 deletions src/DotRecast.Detour/DtCallbackPolyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
}
5 changes: 3 additions & 2 deletions src/DotRecast.Detour/DtCollectPolysQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DotRecast.Core;
using System;
using DotRecast.Core;

namespace DotRecast.Detour
{
Expand All @@ -25,7 +26,7 @@ public bool Overflowed()
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;
Expand Down
2 changes: 1 addition & 1 deletion src/DotRecast.Detour/DtFindNearestPolyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DtFindNearestPolyQuery(DtNavMeshQuery query, RcVec3f center)
_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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DotRecast.Detour/DtNavMeshQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public DtStatus FindNearestPoly(RcVec3f center, RcVec3f halfExtents, IDtQueryFil
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;

Expand Down
4 changes: 3 additions & 1 deletion src/DotRecast.Detour/IDtPolyQuery.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace DotRecast.Detour
{
/// Provides custom polygon query behavior.
Expand All @@ -7,6 +9,6 @@ public interface IDtPolyQuery
{
/// 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);
}
}

0 comments on commit ec9ebe2

Please sign in to comment.