diff --git a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs index b482640..18a8d7e 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs @@ -7,8 +7,6 @@ namespace DotRecast.Detour.Extras.Jumplink { class NavMeshGroundSampler : AbstractGroundSampler { - private readonly IDtQueryFilter filter = new DtQueryNoOpFilter(); - public override void Sample(JumpLinkBuilderConfig acfg, RecastBuilderResult result, EdgeSampler es) { DtNavMeshQuery navMeshQuery = CreateNavMesh(result, acfg.agentRadius, acfg.agentHeight, acfg.agentClimb); @@ -51,7 +49,7 @@ namespace DotRecast.Detour.Extras.Jumplink RcAtomicBoolean found = new RcAtomicBoolean(); RcAtomicFloat minHeight = new RcAtomicFloat(pt.y); - navMeshQuery.QueryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) => + navMeshQuery.QueryPolygons(pt, halfExtents, DtQueryNoOpFilter.Shared, new PolyQueryInvoker((tile, poly, refs) => { var status = navMeshQuery.GetPolyHeight(refs, pt, out var h); if (status.Succeeded()) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index dc27feb..dafd1fe 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -200,7 +200,7 @@ namespace DotRecast.Detour public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, IDtQueryFilter filter, IRcRand frand, out long randomRef, out RcVec3f randomPt) { - return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, DtNoOpDtPolygonByCircleConstraint.Noop, out randomRef, out randomPt); + return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, DtNoOpDtPolygonByCircleConstraint.Shared, out randomRef, out randomPt); } /** @@ -221,7 +221,7 @@ namespace DotRecast.Detour public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius, IDtQueryFilter filter, IRcRand frand, out long randomRef, out RcVec3f randomPt) { - return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, DtStrictDtPolygonByCircleConstraint.Strict, out randomRef, out randomPt); + return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, DtStrictDtPolygonByCircleConstraint.Shared, out randomRef, out randomPt); } public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, diff --git a/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs b/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs index b938dc1..ef40f6e 100644 --- a/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs +++ b/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs @@ -4,7 +4,7 @@ namespace DotRecast.Detour { public class DtNoOpDtPolygonByCircleConstraint : IDtPolygonByCircleConstraint { - public static readonly DtNoOpDtPolygonByCircleConstraint Noop = new DtNoOpDtPolygonByCircleConstraint(); + public static readonly DtNoOpDtPolygonByCircleConstraint Shared = new DtNoOpDtPolygonByCircleConstraint(); private DtNoOpDtPolygonByCircleConstraint() { diff --git a/src/DotRecast.Detour/DtQueryEmptyFilter.cs b/src/DotRecast.Detour/DtQueryEmptyFilter.cs index 9248a73..b3d7ff7 100644 --- a/src/DotRecast.Detour/DtQueryEmptyFilter.cs +++ b/src/DotRecast.Detour/DtQueryEmptyFilter.cs @@ -4,12 +4,18 @@ namespace DotRecast.Detour { public class DtQueryEmptyFilter : IDtQueryFilter { + public static readonly DtQueryEmptyFilter Shared = new DtQueryEmptyFilter(); + + private DtQueryEmptyFilter() + { + } + public bool PassFilter(long refs, DtMeshTile tile, DtPoly poly) { return false; } - public float GetCost(RcVec3f pa, RcVec3f pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, + public float GetCost(RcVec3f pa, RcVec3f pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, DtMeshTile curTile, DtPoly curPoly, long nextRef, DtMeshTile nextTile, DtPoly nextPoly) { return 0; diff --git a/src/DotRecast.Detour/DtQueryNoOpFilter.cs b/src/DotRecast.Detour/DtQueryNoOpFilter.cs index 5a4149f..058693e 100644 --- a/src/DotRecast.Detour/DtQueryNoOpFilter.cs +++ b/src/DotRecast.Detour/DtQueryNoOpFilter.cs @@ -4,6 +4,13 @@ namespace DotRecast.Detour { public class DtQueryNoOpFilter : IDtQueryFilter { + public static readonly DtQueryNoOpFilter Shared = new DtQueryNoOpFilter(); + + private DtQueryNoOpFilter() + { + + } + public bool PassFilter(long refs, DtMeshTile tile, DtPoly poly) { return true; diff --git a/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs b/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs index 86ae5be..d2e7c64 100644 --- a/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs +++ b/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs @@ -11,7 +11,7 @@ namespace DotRecast.Detour private const int CIRCLE_SEGMENTS = 12; private static readonly float[] UnitCircle = MakeUnitCircle(); - public static readonly IDtPolygonByCircleConstraint Strict = new DtStrictDtPolygonByCircleConstraint(); + public static readonly IDtPolygonByCircleConstraint Shared = new DtStrictDtPolygonByCircleConstraint(); private DtStrictDtPolygonByCircleConstraint() { diff --git a/src/DotRecast.Recast.Toolset/Tools/TestNavmeshToolImpl.cs b/src/DotRecast.Recast.Toolset/Tools/TestNavmeshToolImpl.cs index 668c732..c763ae0 100644 --- a/src/DotRecast.Recast.Toolset/Tools/TestNavmeshToolImpl.cs +++ b/src/DotRecast.Recast.Toolset/Tools/TestNavmeshToolImpl.cs @@ -298,8 +298,8 @@ namespace DotRecast.Recast.Toolset.Tools float dist = (float)Math.Sqrt(dx * dx + dz * dz); IDtPolygonByCircleConstraint constraint = constrainByCircle - ? DtStrictDtPolygonByCircleConstraint.Strict - : DtNoOpDtPolygonByCircleConstraint.Noop; + ? DtStrictDtPolygonByCircleConstraint.Shared + : DtNoOpDtPolygonByCircleConstraint.Shared; var frand = new FRand(); var navQuery = _sample.GetNavMeshQuery(); diff --git a/test/DotRecast.Detour.Test/FindNearestPolyTest.cs b/test/DotRecast.Detour.Test/FindNearestPolyTest.cs index d0d377a..9ed5ad8 100644 --- a/test/DotRecast.Detour.Test/FindNearestPolyTest.cs +++ b/test/DotRecast.Detour.Test/FindNearestPolyTest.cs @@ -56,12 +56,11 @@ public class FindNearestPolyTest : AbstractDetourTest [Test] public void ShouldReturnStartPosWhenNoPolyIsValid() { - var filter = new DtQueryEmptyFilter(); RcVec3f extents = RcVec3f.Of(2, 4, 2); for (int i = 0; i < startRefs.Length; i++) { RcVec3f startPos = startPoss[i]; - var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _); + var status = query.FindNearestPoly(startPos, extents, DtQueryEmptyFilter.Shared, out var nearestRef, out var nearestPt, out var _); Assert.That(status.Succeeded(), Is.True); Assert.That(nearestRef, Is.EqualTo(0L)); for (int v = 0; v < POLY_POS[i].Length; v++) diff --git a/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs b/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs index a968e65..753aee7 100644 --- a/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs +++ b/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs @@ -24,7 +24,7 @@ namespace DotRecast.Detour.Test; [Parallelizable] public class PolygonByCircleConstraintTest { - private readonly IDtPolygonByCircleConstraint _constraint = DtStrictDtPolygonByCircleConstraint.Strict; + private readonly IDtPolygonByCircleConstraint _constraint = DtStrictDtPolygonByCircleConstraint.Shared; [Test] public void ShouldHandlePolygonFullyInsideCircle()