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