forked from bit/DotRecastNetSim
changed UpdateSlicedFindPath
This commit is contained in:
parent
4112168f4a
commit
d38cddfbc6
|
@ -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<List<long>> pathFound;
|
||||
if (ag.targetReplan) // && npath > 10)
|
||||
{
|
||||
|
|
|
@ -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<List<long>> fpr = navquery.FinalizeSlicedFindPathPartial(m_path);
|
||||
|
||||
if (fpr.Succeeded() && fpr.result.Count > 0)
|
||||
|
|
|
@ -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<int> 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())
|
||||
|
|
|
@ -1101,18 +1101,19 @@ namespace DotRecast.Detour
|
|||
* The maximum number of iterations to perform.
|
||||
* @return The status flags for the query.
|
||||
*/
|
||||
public virtual Result<int> 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<long> 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;
|
||||
|
@ -1251,6 +1254,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.
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -162,8 +162,7 @@ public class FindPathTest : AbstractDetourTest
|
|||
DtStatus status = DtStatus.DT_IN_PROGRESS;
|
||||
while (status.InProgress())
|
||||
{
|
||||
Result<int> res = query.UpdateSlicedFindPath(10);
|
||||
status = res.status;
|
||||
status = query.UpdateSlicedFindPath(10, out var _);
|
||||
}
|
||||
|
||||
Result<List<long>> path = query.FinalizeSlicedFindPath();
|
||||
|
|
Loading…
Reference in New Issue