From ec9ebe28b94545d098e5da8cfd1440313f853c14 Mon Sep 17 00:00:00 2001 From: ikpil Date: Mon, 20 May 2024 00:16:36 +0900 Subject: [PATCH] long[] -> Span --- .../Jumplink/NavMeshGroundSampler.cs | 16 ++++++---------- src/DotRecast.Detour/DtCallbackPolyQuery.cs | 11 +++++++---- src/DotRecast.Detour/DtCollectPolysQuery.cs | 5 +++-- src/DotRecast.Detour/DtFindNearestPolyQuery.cs | 2 +- src/DotRecast.Detour/DtNavMeshQuery.cs | 2 +- src/DotRecast.Detour/IDtPolyQuery.cs | 4 +++- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs index 93085ca..5a62246 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs @@ -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); } } })); diff --git a/src/DotRecast.Detour/DtCallbackPolyQuery.cs b/src/DotRecast.Detour/DtCallbackPolyQuery.cs index 79d9c31..088b366 100644 --- a/src/DotRecast.Detour/DtCallbackPolyQuery.cs +++ b/src/DotRecast.Detour/DtCallbackPolyQuery.cs @@ -4,16 +4,19 @@ namespace DotRecast.Detour { public class DtCallbackPolyQuery : IDtPolyQuery { - private readonly Action _callback; + private readonly Action _callback; - public DtCallbackPolyQuery(Action callback) + public DtCallbackPolyQuery(Action callback) { _callback = callback; } - public void Process(DtMeshTile tile, DtPoly[] poly, long[] refs, int count) + public void Process(DtMeshTile tile, DtPoly[] poly, Span refs, int count) { - _callback?.Invoke(tile, poly, refs, count); + for (int i = 0; i < count; ++i) + { + _callback?.Invoke(tile, poly[i], refs[i]); + } } } } \ No newline at end of file diff --git a/src/DotRecast.Detour/DtCollectPolysQuery.cs b/src/DotRecast.Detour/DtCollectPolysQuery.cs index 31acaac..4b5c998 100644 --- a/src/DotRecast.Detour/DtCollectPolysQuery.cs +++ b/src/DotRecast.Detour/DtCollectPolysQuery.cs @@ -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 refs, int count) { int numLeft = m_maxPolys - m_numCollected; int toCopy = count; diff --git a/src/DotRecast.Detour/DtFindNearestPolyQuery.cs b/src/DotRecast.Detour/DtFindNearestPolyQuery.cs index ec3d62c..b0c4cf1 100644 --- a/src/DotRecast.Detour/DtFindNearestPolyQuery.cs +++ b/src/DotRecast.Detour/DtFindNearestPolyQuery.cs @@ -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 refs, int count) { for (int i = 0; i < count; ++i) { diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index e815fd3..040eb5d 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -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 polyRefs = stackalloc long[batchSize]; DtPoly[] polys = new DtPoly[batchSize]; int n = 0; diff --git a/src/DotRecast.Detour/IDtPolyQuery.cs b/src/DotRecast.Detour/IDtPolyQuery.cs index 0baf9c5..890d171 100644 --- a/src/DotRecast.Detour/IDtPolyQuery.cs +++ b/src/DotRecast.Detour/IDtPolyQuery.cs @@ -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 refs, int count); } } \ No newline at end of file