Optimisation: disable position snapping for FindStraightPath

This commit is contained in:
Семенов Иван 2025-03-06 16:31:05 +03:00
parent 6aff9574c9
commit 62ebb2298e
1 changed files with 24 additions and 24 deletions

View File

@ -1637,20 +1637,20 @@ namespace DotRecast.Detour
DtStatus stat = DtStatus.DT_STATUS_NOTHING; DtStatus stat = DtStatus.DT_STATUS_NOTHING;
// TODO: Should this be callers responsibility? // TODO: Should this be callers responsibility?
var closestStartPosRes = ClosestPointOnPolyBoundary(path[0], startPos, out var closestStartPos); // var closestStartPosRes = ClosestPointOnPolyBoundary(path[0], startPos, out var closestStartPos);
if (closestStartPosRes.Failed()) // if (closestStartPosRes.Failed())
{ // {
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; // return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
} // }
//
var closestEndPosRes = ClosestPointOnPolyBoundary(path[pathSize - 1], endPos, out var closestEndPos); // var closestEndPosRes = ClosestPointOnPolyBoundary(path[pathSize - 1], endPos, out var closestEndPos);
if (closestEndPosRes.Failed()) // if (closestEndPosRes.Failed())
{ // {
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; // return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
} // }
// Add start point. // 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()) if (!stat.InProgress())
{ {
return stat; return stat;
@ -1658,7 +1658,7 @@ namespace DotRecast.Detour
if (pathSize > 1) if (pathSize > 1)
{ {
RcVec3f portalApex = closestStartPos; RcVec3f portalApex = startPos;
RcVec3f portalLeft = portalApex; RcVec3f portalLeft = portalApex;
RcVec3f portalRight = portalApex; RcVec3f portalRight = portalApex;
int apexIndex = 0; 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. // 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. // Clamp the end point to path[i], and return the path so far.
var cpStatus = ClosestPointOnPolyBoundary(path[i], endPos, out closestEndPos); // var cpStatus = ClosestPointOnPolyBoundary(path[i], endPos, out closestEndPos);
if (cpStatus.Failed()) // if (cpStatus.Failed())
{ // {
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; // return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
} // }
// Append portals along the current straight path segment. // Append portals along the current straight path segment.
if ((options & (DtStraightPathOptions.DT_STRAIGHTPATH_AREA_CROSSINGS | DtStraightPathOptions.DT_STRAIGHTPATH_ALL_CROSSINGS)) != 0) 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. // 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. // 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); 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 else
{ {
// End of the path. // End of the path.
left = closestEndPos; left = endPos;
right = closestEndPos; right = endPos;
toType = DtPolyTypes.DT_POLYTYPE_GROUND; toType = DtPolyTypes.DT_POLYTYPE_GROUND;
} }
@ -1840,7 +1840,7 @@ namespace DotRecast.Detour
// Append portals along the current straight path segment. // Append portals along the current straight path segment.
if ((options & (DtStraightPathOptions.DT_STRAIGHTPATH_AREA_CROSSINGS | DtStraightPathOptions.DT_STRAIGHTPATH_ALL_CROSSINGS)) != 0) 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()) if (!stat.InProgress())
{ {
return stat; return stat;
@ -1849,7 +1849,7 @@ namespace DotRecast.Detour
} }
// Ignore status return value as we're just about to return anyway. // 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); return DtStatus.DT_SUCCESS | (straightPathCount >= maxStraightPath ? DtStatus.DT_BUFFER_TOO_SMALL : DtStatus.DT_STATUS_NOTHING);
} }