From 62ebb2298e5d792eefde1033a4dc99dacf5eaf53 Mon Sep 17 00:00:00 2001 From: Greysnek Date: Thu, 6 Mar 2025 16:31:05 +0300 Subject: [PATCH] Optimisation: disable position snapping for FindStraightPath --- src/DotRecast.Detour/DtNavMeshQuery.cs | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 766f8ef..5657fd0 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -1637,20 +1637,20 @@ namespace DotRecast.Detour DtStatus stat = DtStatus.DT_STATUS_NOTHING; // TODO: Should this be callers responsibility? - var closestStartPosRes = ClosestPointOnPolyBoundary(path[0], startPos, out var closestStartPos); - if (closestStartPosRes.Failed()) - { - return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; - } - - var closestEndPosRes = ClosestPointOnPolyBoundary(path[pathSize - 1], endPos, out var closestEndPos); - if (closestEndPosRes.Failed()) - { - return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; - } + // var closestStartPosRes = ClosestPointOnPolyBoundary(path[0], startPos, out var closestStartPos); + // if (closestStartPosRes.Failed()) + // { + // return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; + // } + // + // var closestEndPosRes = ClosestPointOnPolyBoundary(path[pathSize - 1], endPos, out var closestEndPos); + // if (closestEndPosRes.Failed()) + // { + // return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; + // } // Add start point. - stat = AppendVertex(closestStartPos, DtStraightPathFlags.DT_STRAIGHTPATH_START, path[0], straightPath, ref straightPathCount, maxStraightPath); + stat = AppendVertex(startPos, DtStraightPathFlags.DT_STRAIGHTPATH_START, path[0], straightPath, ref straightPathCount, maxStraightPath); if (!stat.InProgress()) { return stat; @@ -1658,7 +1658,7 @@ namespace DotRecast.Detour if (pathSize > 1) { - RcVec3f portalApex = closestStartPos; + RcVec3f portalApex = startPos; RcVec3f portalLeft = portalApex; RcVec3f portalRight = portalApex; int apexIndex = 0; @@ -1687,21 +1687,21 @@ namespace DotRecast.Detour { // Failed to get portal points, in practice this means that path[i+1] is invalid polygon. // Clamp the end point to path[i], and return the path so far. - var cpStatus = ClosestPointOnPolyBoundary(path[i], endPos, out closestEndPos); - if (cpStatus.Failed()) - { - return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; - } + // var cpStatus = ClosestPointOnPolyBoundary(path[i], endPos, out closestEndPos); + // if (cpStatus.Failed()) + // { + // return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; + // } // Append portals along the current straight path segment. if ((options & (DtStraightPathOptions.DT_STRAIGHTPATH_AREA_CROSSINGS | DtStraightPathOptions.DT_STRAIGHTPATH_ALL_CROSSINGS)) != 0) { // Ignore status return value as we're just about to return anyway. - AppendPortals(apexIndex, i, closestEndPos, path, straightPath, ref straightPathCount, maxStraightPath, options); + AppendPortals(apexIndex, i, endPos, path, straightPath, ref straightPathCount, maxStraightPath, options); } // Ignore status return value as we're just about to return anyway. - AppendVertex(closestEndPos, 0, path[i], straightPath, ref straightPathCount, maxStraightPath); + AppendVertex(endPos, 0, path[i], straightPath, ref straightPathCount, maxStraightPath); return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM | (straightPathCount >= maxStraightPath ? DtStatus.DT_BUFFER_TOO_SMALL : DtStatus.DT_STATUS_NOTHING); } @@ -1719,8 +1719,8 @@ namespace DotRecast.Detour else { // End of the path. - left = closestEndPos; - right = closestEndPos; + left = endPos; + right = endPos; toType = DtPolyTypes.DT_POLYTYPE_GROUND; } @@ -1840,7 +1840,7 @@ namespace DotRecast.Detour // Append portals along the current straight path segment. if ((options & (DtStraightPathOptions.DT_STRAIGHTPATH_AREA_CROSSINGS | DtStraightPathOptions.DT_STRAIGHTPATH_ALL_CROSSINGS)) != 0) { - stat = AppendPortals(apexIndex, pathSize - 1, closestEndPos, path, straightPath, ref straightPathCount, maxStraightPath, options); + stat = AppendPortals(apexIndex, pathSize - 1, endPos, path, straightPath, ref straightPathCount, maxStraightPath, options); if (!stat.InProgress()) { return stat; @@ -1849,7 +1849,7 @@ namespace DotRecast.Detour } // Ignore status return value as we're just about to return anyway. - AppendVertex(closestEndPos, DtStraightPathFlags.DT_STRAIGHTPATH_END, 0, straightPath, ref straightPathCount, maxStraightPath); + AppendVertex(endPos, DtStraightPathFlags.DT_STRAIGHTPATH_END, 0, straightPath, ref straightPathCount, maxStraightPath); return DtStatus.DT_SUCCESS | (straightPathCount >= maxStraightPath ? DtStatus.DT_BUFFER_TOO_SMALL : DtStatus.DT_STATUS_NOTHING); }