diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index 3b0ff83..7df2a9f 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -584,7 +584,7 @@ namespace DotRecast.Detour.Crowd // Quick search towards the goal. _navQuery.InitSlicedFindPath(path[0], ag.targetRef, ag.npos, ag.targetPos, _filters[ag.option.queryFilterType], 0); - _navQuery.UpdateSlicedFindPath(_config.maxTargetFindPathIterations); + _navQuery.UpdateSlicedFindPath(_config.maxTargetFindPathIterations, out var _); Result> pathFound; if (ag.targetReplan) // && npath > 10) { diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 0be8de8..8b060ff 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -350,7 +350,7 @@ namespace DotRecast.Detour.Crowd } navquery.InitSlicedFindPath(m_path[0], m_path[m_path.Count - 1], m_pos, m_target, filter, 0); - navquery.UpdateSlicedFindPath(maxIterations); + navquery.UpdateSlicedFindPath(maxIterations, out var _); Result> fpr = navquery.FinalizeSlicedFindPathPartial(m_path); if (fpr.Succeeded() && fpr.result.Count > 0) diff --git a/src/DotRecast.Detour.Crowd/DtPathQueue.cs b/src/DotRecast.Detour.Crowd/DtPathQueue.cs index acb741c..30b9b0d 100644 --- a/src/DotRecast.Detour.Crowd/DtPathQueue.cs +++ b/src/DotRecast.Detour.Crowd/DtPathQueue.cs @@ -46,6 +46,7 @@ namespace DotRecast.Detour.Crowd { break; } + queue.RemoveFirst(); // Handle query start. @@ -58,9 +59,8 @@ namespace DotRecast.Detour.Crowd // Handle query in progress. if (q.result.status.InProgress()) { - Result res = q.navQuery.UpdateSlicedFindPath(iterCount); - q.result.status = res.status; - iterCount -= res.result; + q.result.status = q.navQuery.UpdateSlicedFindPath(iterCount, out var iters); + iterCount -= iters; } if (q.result.status.Succeeded()) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index d463c7e..ea2992a 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -1101,18 +1101,19 @@ namespace DotRecast.Detour * The maximum number of iterations to perform. * @return The status flags for the query. */ - public virtual Result UpdateSlicedFindPath(int maxIter) + public virtual DtStatus UpdateSlicedFindPath(int maxIter, out int doneIters) { + doneIters = 0; if (!m_query.status.InProgress()) { - return Results.Of(m_query.status, 0); + return m_query.status; } // Make sure the request is still valid. if (!m_nav.IsValidPolyRef(m_query.startRef) || !m_nav.IsValidPolyRef(m_query.endRef)) { m_query.status = DtStatus.DT_FAILURE; - return Results.Of(m_query.status, 0); + return DtStatus.DT_FAILURE; } int iter = 0; @@ -1129,8 +1130,10 @@ namespace DotRecast.Detour if (bestNode.id == m_query.endRef) { m_query.lastBestNode = bestNode; - m_query.status = DtStatus.DT_SUCCSESS; - return Results.Of(m_query.status, iter); + var details = m_query.status & DtStatus.DT_STATUS_DETAIL_MASK; + m_query.status = DtStatus.DT_SUCCSESS | details; + doneIters = iter; + return m_query.status; } // Get current poly and tile. @@ -1140,9 +1143,10 @@ namespace DotRecast.Detour var status = m_nav.GetTileAndPolyByRef(bestRef, out var bestTile, out var bestPoly); if (status.Failed()) { - m_query.status = DtStatus.DT_FAILURE; // The polygon has disappeared during the sliced query, fail. - return Results.Of(m_query.status, iter); + m_query.status = DtStatus.DT_FAILURE; + doneIters = iter; + return m_query.status; } // Get parent and grand parent poly and tile. @@ -1167,10 +1171,10 @@ namespace DotRecast.Detour invalidParent = status.Failed(); if (invalidParent || (grandpaRef != 0 && !m_nav.IsValidPolyRef(grandpaRef))) { - // The polygon has disappeared during the sliced query, - // fail. + // The polygon has disappeared during the sliced query fail. m_query.status = DtStatus.DT_FAILURE; - return Results.Of(m_query.status, iter); + doneIters = iter; + return m_query.status; } } @@ -1236,8 +1240,7 @@ namespace DotRecast.Detour List shortcut = null; if (tryLOS) { - status = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter, - DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit); + status = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter, DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit); if (status.Succeeded()) { foundShortCut = rayHit.t >= 1.0f; @@ -1250,6 +1253,8 @@ namespace DotRecast.Detour } } } + + // update move cost if (!foundShortCut) @@ -1293,7 +1298,7 @@ namespace DotRecast.Detour // Add or update the node. neighbourNode.pidx = foundShortCut ? bestNode.pidx : m_nodePool.GetNodeIdx(bestNode); neighbourNode.id = neighbourRef; - neighbourNode.flags = (neighbourNode.flags & ~DtNode.DT_NODE_CLOSED); + neighbourNode.flags = (neighbourNode.flags & ~DT_NODE_CLOSED); neighbourNode.cost = cost; neighbourNode.total = total; neighbourNode.pos = neighbourPos; @@ -1323,10 +1328,12 @@ namespace DotRecast.Detour // Exhausted all nodes, but could not find path. if (m_openList.IsEmpty()) { - m_query.status = DtStatus.DT_PARTIAL_RESULT; + var details = m_query.status & DtStatus.DT_STATUS_DETAIL_MASK; + m_query.status = DtStatus.DT_SUCCSESS | details; } - return Results.Of(m_query.status, iter); + doneIters = iter; + return m_query.status; } /// Finalizes and returns the results of a sliced path query. diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 1f1aa2a..02c7145 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -977,7 +977,7 @@ public class TestNavmeshTool : IRcTool DtNavMeshQuery m_navQuery = _impl.GetSample().GetNavMeshQuery(); if (m_pathFindStatus.InProgress()) { - m_pathFindStatus = m_navQuery.UpdateSlicedFindPath(1).status; + m_pathFindStatus = m_navQuery.UpdateSlicedFindPath(1, out var _); } if (m_pathFindStatus.Succeeded()) diff --git a/test/DotRecast.Detour.Test/FindPathTest.cs b/test/DotRecast.Detour.Test/FindPathTest.cs index 7aca937..e301797 100644 --- a/test/DotRecast.Detour.Test/FindPathTest.cs +++ b/test/DotRecast.Detour.Test/FindPathTest.cs @@ -162,8 +162,7 @@ public class FindPathTest : AbstractDetourTest DtStatus status = DtStatus.DT_IN_PROGRESS; while (status.InProgress()) { - Result res = query.UpdateSlicedFindPath(10); - status = res.status; + status = query.UpdateSlicedFindPath(10, out var _); } Result> path = query.FinalizeSlicedFindPath();