diff --git a/src/DotRecast.Detour/DtFindPathOption.cs b/src/DotRecast.Detour/DtFindPathOption.cs new file mode 100644 index 0000000..35c9220 --- /dev/null +++ b/src/DotRecast.Detour/DtFindPathOption.cs @@ -0,0 +1,23 @@ +namespace DotRecast.Detour +{ + public readonly struct DtFindPathOption + { + public static readonly DtFindPathOption Zero = new DtFindPathOption(DefaultQueryHeuristic.Default, 0, 0); + + public readonly IQueryHeuristic heuristic; + public readonly int options; + public readonly float raycastLimit; + + public DtFindPathOption(IQueryHeuristic heuristic, int options, float raycastLimit) + { + this.heuristic = heuristic; + this.options = options; + this.raycastLimit = raycastLimit; + } + + public DtFindPathOption(int options, float raycastLimit) + : this(DefaultQueryHeuristic.Default, options, raycastLimit) + { + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 5e7b660..5c0bb96 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -764,19 +764,7 @@ namespace DotRecast.Detour * The polygon filter to apply to the query. * @return Found path */ - public virtual Result> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter) - { - return FindPath(startRef, endRef, startPos, endPos, filter, DefaultQueryHeuristic.Default, 0, 0); - } - - public virtual Result> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, - int options, float raycastLimit) - { - return FindPath(startRef, endRef, startPos, endPos, filter, DefaultQueryHeuristic.Default, options, raycastLimit); - } - - public Result> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, - IQueryHeuristic heuristic, int options, float raycastLimit) + public Result> FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, DtFindPathOption fpo) { // Validate input if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter) @@ -784,6 +772,10 @@ namespace DotRecast.Detour return Results.InvalidParam>(); } + var heuristic = fpo.heuristic; + var raycastLimit = fpo.raycastLimit; + var options = fpo.options; + float raycastLimitSqr = Sqr(raycastLimit); // trade quality with performance? diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 02c7145..c190131 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -197,7 +197,7 @@ public class TestNavmeshTool : IRcTool if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0) { m_polys = m_navQuery.FindPath(m_startRef, m_endRef, m_spos, m_epos, m_filter, - enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue).result; + new(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue)).result; if (0 < m_polys.Count) { List polys = new(m_polys); @@ -331,7 +331,7 @@ public class TestNavmeshTool : IRcTool if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0) { m_polys = m_navQuery.FindPath(m_startRef, m_endRef, m_spos, m_epos, m_filter, - enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue).result; + new(enableRaycast ? DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE : 0, float.MaxValue)).result; if (0 < m_polys.Count) { // In case of partial path, make sure the end point is clamped to the last polygon. diff --git a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs index 164e081..2d5dc7d 100644 --- a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs @@ -43,7 +43,7 @@ public class DynamicNavMeshTest query.FindNearestPoly(START_POS, EXTENT, filter, out var startRef, out var startPt, out var _); query.FindNearestPoly(END_POS, EXTENT, filter, out var endRef, out var endPt, out var _); - List path = query.FindPath(startRef, endRef, startPt, endPt, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue).result; + List path = query.FindPath(startRef, endRef, startPt, endPt, filter, new(DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue)).result; // check path length without any obstacles Assert.That(path.Count, Is.EqualTo(16)); @@ -61,8 +61,8 @@ public class DynamicNavMeshTest // find path again query.FindNearestPoly(START_POS, EXTENT, filter, out startRef, out startPt, out var _); query.FindNearestPoly(END_POS, EXTENT, filter, out endRef, out endPt, out var _); - path = query.FindPath(startRef, endRef, startPt, endPt, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue).result; - + path = query.FindPath(startRef, endRef, startPt, endPt, filter, new(DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue)).result; + // check path length with obstacles Assert.That(path.Count, Is.EqualTo(19)); // remove obstacle @@ -73,12 +73,12 @@ public class DynamicNavMeshTest _ = future.Result; // create new query query = new DtNavMeshQuery(mesh.NavMesh()); - + // find path one more time query.FindNearestPoly(START_POS, EXTENT, filter, out startRef, out startPt, out var _); query.FindNearestPoly(END_POS, EXTENT, filter, out endRef, out endPt, out var _); - path = query.FindPath(startRef, endRef, startPt, endPt, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue).result; - + path = query.FindPath(startRef, endRef, startPt, endPt, filter, new(DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue)).result; + // path length should be back to the initial value Assert.That(path.Count, Is.EqualTo(16)); } diff --git a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs index 3ae17aa..4890a16 100644 --- a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs +++ b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs @@ -96,7 +96,7 @@ public class UnityAStarPathfindingImporterTest IDtQueryFilter filter = new DtQueryDefaultFilter(); var polys = GetNearestPolys(mesh, startPos, endPos); - return query.FindPath(polys[0].refs, polys[1].refs, startPos, endPos, filter); + return query.FindPath(polys[0].refs, polys[1].refs, startPos, endPos, filter, DtFindPathOption.Zero); } private DtPolyPoint[] GetNearestPolys(DtNavMesh mesh, params RcVec3f[] positions) diff --git a/test/DotRecast.Detour.Test/FindPathTest.cs b/test/DotRecast.Detour.Test/FindPathTest.cs index e301797..21bd095 100644 --- a/test/DotRecast.Detour.Test/FindPathTest.cs +++ b/test/DotRecast.Detour.Test/FindPathTest.cs @@ -138,7 +138,7 @@ public class FindPathTest : AbstractDetourTest long endRef = endRefs[i]; RcVec3f startPos = startPoss[i]; RcVec3f endPos = endPoss[i]; - Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter); + Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero); Assert.That(path.status, Is.EqualTo(STATUSES[i])); Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length)); for (int j = 0; j < RESULTS[i].Length; j++) @@ -186,7 +186,7 @@ public class FindPathTest : AbstractDetourTest long endRef = endRefs[i]; var startPos = startPoss[i]; var endPos = endPoss[i]; - Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter); + Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero); var straightPath = new List(); query.FindStraightPath(startPos, endPos, path.result, ref straightPath, int.MaxValue, 0); Assert.That(straightPath.Count, Is.EqualTo(STRAIGHT_PATHS[i].Length)); diff --git a/test/DotRecast.Detour.Test/TiledFindPathTest.cs b/test/DotRecast.Detour.Test/TiledFindPathTest.cs index 1030c18..5e62bc9 100644 --- a/test/DotRecast.Detour.Test/TiledFindPathTest.cs +++ b/test/DotRecast.Detour.Test/TiledFindPathTest.cs @@ -71,7 +71,7 @@ public class TiledFindPathTest long endRef = END_REFS[i]; RcVec3f startPos = START_POS[i]; RcVec3f endPos = END_POS[i]; - Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter); + Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero); Assert.That(path.status, Is.EqualTo(STATUSES[i])); Assert.That(path.result.Count, Is.EqualTo(RESULTS[i].Length)); for (int j = 0; j < RESULTS[i].Length; j++) diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs index 4601d8b..19517de 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs @@ -52,7 +52,7 @@ public class TileCacheFindPathTest : AbstractTileCacheTest query.FindNearestPoly(start, extents, filter, out var startRef, out var startPos, out var _); query.FindNearestPoly(end, extents, filter, out var endRef, out var endPos, out var _); - Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter); + Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero); int maxStraightPath = 256; int options = 0; diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs index fb51a0c..136ecb8 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs @@ -90,7 +90,7 @@ public class TileCacheNavigationTest : AbstractTileCacheTest long endRef = endRefs[i]; RcVec3f startPos = startPoss[i]; RcVec3f endPos = endPoss[i]; - Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter); + Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, DtFindPathOption.Zero); Assert.That(path.status, Is.EqualTo(statuses[i])); Assert.That(path.result.Count, Is.EqualTo(results[i].Length)); for (int j = 0; j < results[i].Length; j++) @@ -110,8 +110,8 @@ public class TileCacheNavigationTest : AbstractTileCacheTest long endRef = endRefs[i]; RcVec3f startPos = startPoss[i]; RcVec3f endPos = endPoss[i]; - Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, new DefaultQueryHeuristic(0.0f), - 0, 0); + Result> path = query.FindPath(startRef, endRef, startPos, endPos, filter, new(new DefaultQueryHeuristic(0.0f), + 0, 0)); Assert.That(path.status, Is.EqualTo(statuses[i])); Assert.That(path.result.Count, Is.EqualTo(results[i].Length)); for (int j = 0; j < results[i].Length; j++)