refactor: DtNodeFlags

This commit is contained in:
ikpil 2023-10-08 14:40:07 +09:00
parent 78d4591c3c
commit 6416374f94
4 changed files with 66 additions and 67 deletions

View File

@ -4,12 +4,8 @@
/// @ingroup crowd
public enum DtCrowdAgentState
{
DT_CROWDAGENT_STATE_INVALID,
/// < The agent is not in a valid state.
DT_CROWDAGENT_STATE_WALKING,
/// < The agent is traversing a normal navigation mesh polygon.
DT_CROWDAGENT_STATE_OFFMESH, /// < The agent is traversing an off-mesh connection.
DT_CROWDAGENT_STATE_INVALID, // < The agent is not in a valid state.
DT_CROWDAGENT_STATE_WALKING, // < The agent is traversing a normal navigation mesh polygon.
DT_CROWDAGENT_STATE_OFFMESH, // < The agent is traversing an off-mesh connection.
};
}

View File

@ -226,7 +226,7 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = 0;
startNode.id = startRef;
startNode.flags = DT_NODE_OPEN;
startNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(startNode);
DtStatus status = DtStatus.DT_SUCCSESS;
@ -241,8 +241,8 @@ namespace DotRecast.Detour
while (!m_openList.IsEmpty())
{
DtNode bestNode = m_openList.Pop();
bestNode.flags &= ~DT_NODE_OPEN;
bestNode.flags |= DT_NODE_CLOSED;
bestNode.flags &= ~DtNodeFlags.DT_NODE_OPEN;
bestNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
// Get poly and tile.
// The API input has been checked already, skip checking internal data.
long bestRef = bestNode.id;
@ -331,7 +331,7 @@ namespace DotRecast.Detour
continue;
}
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
continue;
}
@ -345,23 +345,23 @@ namespace DotRecast.Detour
float total = bestNode.total + RcVec3f.Distance(bestNode.pos, neighbourNode.pos);
// The node is already in open list and the new result is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
{
continue;
}
neighbourNode.id = neighbourRef;
neighbourNode.flags = (neighbourNode.flags & ~DtNode.DT_NODE_CLOSED);
neighbourNode.flags = (neighbourNode.flags & ~DtNodeFlags.DT_NODE_CLOSED);
neighbourNode.pidx = m_nodePool.GetNodeIdx(bestNode);
neighbourNode.total = total;
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0)
{
m_openList.Modify(neighbourNode);
}
else
{
neighbourNode.flags = DtNode.DT_NODE_OPEN;
neighbourNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(neighbourNode);
}
}
@ -780,7 +780,7 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = heuristic.GetCost(startPos, endPos);
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_OPEN;
startNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(startNode);
DtNode lastBestNode = startNode;
@ -791,8 +791,8 @@ namespace DotRecast.Detour
{
// Remove node from open list and put it in closed list.
DtNode bestNode = m_openList.Pop();
bestNode.flags &= ~DtNode.DT_NODE_OPEN;
bestNode.flags |= DtNode.DT_NODE_CLOSED;
bestNode.flags &= ~DtNodeFlags.DT_NODE_OPEN;
bestNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
// Reached the goal, stop searching.
if (bestNode.id == endRef)
@ -925,13 +925,13 @@ namespace DotRecast.Detour
float total = cost + heuristicCost;
// The node is already in open list and the new result is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
{
continue;
}
// The node is already visited and process, and the new result is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0 && total >= neighbourNode.total)
{
continue;
}
@ -939,13 +939,13 @@ 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 & ~DtNodeFlags.DT_NODE_CLOSED);
neighbourNode.cost = cost;
neighbourNode.total = total;
neighbourNode.pos = neighbourPos;
neighbourNode.shortcut = shortcut;
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0)
{
// Already in open, update node location.
m_openList.Modify(neighbourNode);
@ -953,7 +953,7 @@ namespace DotRecast.Detour
else
{
// Put the node in open list.
neighbourNode.flags |= DtNode.DT_NODE_OPEN;
neighbourNode.flags |= DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(neighbourNode);
}
@ -1050,7 +1050,7 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = heuristic.GetCost(startPos, endPos);
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_OPEN;
startNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(startNode);
m_query.status = DtStatus.DT_IN_PROGRESS;
@ -1089,8 +1089,8 @@ namespace DotRecast.Detour
// Remove node from open list and put it in closed list.
DtNode bestNode = m_openList.Pop();
bestNode.flags &= ~DtNode.DT_NODE_OPEN;
bestNode.flags |= DtNode.DT_NODE_CLOSED;
bestNode.flags &= ~DtNodeFlags.DT_NODE_OPEN;
bestNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
// Reached the goal, stop searching.
if (bestNode.id == m_query.endRef)
@ -1249,14 +1249,14 @@ namespace DotRecast.Detour
// The node is already in open list and the new result is worse,
// skip.
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
{
continue;
}
// The node is already visited and process, and the new result
// is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0 && total >= neighbourNode.total)
{
continue;
}
@ -1264,13 +1264,13 @@ namespace DotRecast.Detour
// Add or update the node.
neighbourNode.pidx = foundShortCut ? bestNode.pidx : m_nodePool.GetNodeIdx(bestNode);
neighbourNode.id = neighbourRef;
neighbourNode.flags = (neighbourNode.flags & ~DT_NODE_CLOSED);
neighbourNode.flags = (neighbourNode.flags & ~DtNodeFlags.DT_NODE_CLOSED);
neighbourNode.cost = cost;
neighbourNode.total = total;
neighbourNode.pos = neighbourPos;
neighbourNode.shortcut = shortcut;
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0)
{
// Already in open, update node location.
m_openList.Modify(neighbourNode);
@ -1278,7 +1278,7 @@ namespace DotRecast.Detour
else
{
// Put the node in open list.
neighbourNode.flags |= DtNode.DT_NODE_OPEN;
neighbourNode.flags |= DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(neighbourNode);
}
@ -1792,7 +1792,7 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = 0;
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_CLOSED;
startNode.flags = DtNodeFlags.DT_NODE_CLOSED;
LinkedList<DtNode> stack = new LinkedList<DtNode>();
stack.AddLast(startNode);
@ -1894,7 +1894,7 @@ namespace DotRecast.Detour
{
DtNode neighbourNode = tinyNodePool.GetNode(neis[k]);
// Skip if already visited.
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
continue;
}
@ -1911,7 +1911,7 @@ namespace DotRecast.Detour
// Mark as the node as visited and push to queue.
neighbourNode.pidx = tinyNodePool.GetNodeIdx(curNode);
neighbourNode.flags |= DtNode.DT_NODE_CLOSED;
neighbourNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
stack.AddLast(neighbourNode);
}
}
@ -2452,7 +2452,7 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = 0;
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_OPEN;
startNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(startNode);
float radiusSqr = RcMath.Sqr(radius);
@ -2460,8 +2460,8 @@ namespace DotRecast.Detour
while (!m_openList.IsEmpty())
{
DtNode bestNode = m_openList.Pop();
bestNode.flags &= ~DtNode.DT_NODE_OPEN;
bestNode.flags |= DtNode.DT_NODE_CLOSED;
bestNode.flags &= ~DtNodeFlags.DT_NODE_OPEN;
bestNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
// Get poly and tile.
// The API input has been checked already, skip checking internal data.
@ -2522,7 +2522,7 @@ namespace DotRecast.Detour
DtNode neighbourNode = m_nodePool.GetNode(neighbourRef);
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
continue;
}
@ -2538,7 +2538,7 @@ namespace DotRecast.Detour
float total = bestNode.total + cost;
// The node is already in open list and the new result is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
{
continue;
}
@ -2547,13 +2547,13 @@ namespace DotRecast.Detour
neighbourNode.pidx = m_nodePool.GetNodeIdx(bestNode);
neighbourNode.total = total;
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0)
{
m_openList.Modify(neighbourNode);
}
else
{
neighbourNode.flags = DtNode.DT_NODE_OPEN;
neighbourNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(neighbourNode);
}
}
@ -2631,14 +2631,14 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = 0;
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_OPEN;
startNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(startNode);
while (!m_openList.IsEmpty())
{
DtNode bestNode = m_openList.Pop();
bestNode.flags &= ~DtNode.DT_NODE_OPEN;
bestNode.flags |= DtNode.DT_NODE_CLOSED;
bestNode.flags &= ~DtNodeFlags.DT_NODE_OPEN;
bestNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
// Get poly and tile.
// The API input has been checked already, skip checking internal data.
@ -2704,7 +2704,7 @@ namespace DotRecast.Detour
DtNode neighbourNode = m_nodePool.GetNode(neighbourRef);
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
continue;
}
@ -2721,7 +2721,7 @@ namespace DotRecast.Detour
float total = bestNode.total + cost;
// The node is already in open list and the new result is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
{
continue;
}
@ -2730,13 +2730,13 @@ namespace DotRecast.Detour
neighbourNode.pidx = m_nodePool.GetNodeIdx(bestNode);
neighbourNode.total = total;
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0)
{
m_openList.Modify(neighbourNode);
}
else
{
neighbourNode.flags = DtNode.DT_NODE_OPEN;
neighbourNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(neighbourNode);
}
}
@ -2795,7 +2795,7 @@ namespace DotRecast.Detour
DtNode startNode = tinyNodePool.GetNode(startRef);
startNode.pidx = 0;
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_CLOSED;
startNode.flags = DtNodeFlags.DT_NODE_CLOSED;
LinkedList<DtNode> stack = new LinkedList<DtNode>();
stack.AddLast(startNode);
@ -2830,7 +2830,7 @@ namespace DotRecast.Detour
DtNode neighbourNode = tinyNodePool.GetNode(neighbourRef);
// Skip visited.
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
continue;
}
@ -2867,7 +2867,7 @@ namespace DotRecast.Detour
// Mark node visited, this is done before the overlap test so that
// we will not visit the poly again if the test fails.
neighbourNode.flags |= DtNode.DT_NODE_CLOSED;
neighbourNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
neighbourNode.pidx = tinyNodePool.GetNodeIdx(curNode);
// Check that the polygon does not collide with existing polygons.
@ -3127,7 +3127,7 @@ namespace DotRecast.Detour
startNode.cost = 0;
startNode.total = 0;
startNode.id = startRef;
startNode.flags = DtNode.DT_NODE_OPEN;
startNode.flags = DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(startNode);
float radiusSqr = RcMath.Sqr(maxRadius);
@ -3140,8 +3140,8 @@ namespace DotRecast.Detour
while (!m_openList.IsEmpty())
{
DtNode bestNode = m_openList.Pop();
bestNode.flags &= ~DtNode.DT_NODE_OPEN;
bestNode.flags |= DtNode.DT_NODE_CLOSED;
bestNode.flags &= ~DtNodeFlags.DT_NODE_OPEN;
bestNode.flags |= DtNodeFlags.DT_NODE_CLOSED;
// Get poly and tile.
// The API input has been checked already, skip checking internal data.
@ -3260,7 +3260,7 @@ namespace DotRecast.Detour
continue;
}
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
continue;
}
@ -3276,23 +3276,23 @@ namespace DotRecast.Detour
float total = bestNode.total + RcVec3f.Distance(bestNode.pos, neighbourNode.pos);
// The node is already in open list and the new result is worse, skip.
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total)
{
continue;
}
neighbourNode.id = neighbourRef;
neighbourNode.flags = (neighbourNode.flags & ~DtNode.DT_NODE_CLOSED);
neighbourNode.flags = (neighbourNode.flags & ~DtNodeFlags.DT_NODE_CLOSED);
neighbourNode.pidx = m_nodePool.GetNodeIdx(bestNode);
neighbourNode.total = total;
if ((neighbourNode.flags & DtNode.DT_NODE_OPEN) != 0)
if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0)
{
m_openList.Modify(neighbourNode);
}
else
{
neighbourNode.flags |= DtNode.DT_NODE_OPEN;
neighbourNode.flags |= DtNodeFlags.DT_NODE_OPEN;
m_openList.Push(neighbourNode);
}
}
@ -3365,7 +3365,7 @@ namespace DotRecast.Detour
}
DtNode endNode = nodes[0];
if ((endNode.flags & DT_NODE_CLOSED) == 0)
if ((endNode.flags & DtNodeFlags.DT_NODE_CLOSED) == 0)
{
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
}
@ -3415,7 +3415,7 @@ namespace DotRecast.Detour
foreach (DtNode n in m_nodePool.FindNodes(refs))
{
if ((n.flags & DT_NODE_CLOSED) != 0)
if ((n.flags & DtNodeFlags.DT_NODE_CLOSED) != 0)
{
return true;
}

View File

@ -25,12 +25,6 @@ namespace DotRecast.Detour
{
public class DtNode
{
public const int DT_NODE_OPEN = 0x01;
public const int DT_NODE_CLOSED = 0x02;
/** parent of the node is not adjacent. Found using raycast. */
public const int DT_NODE_PARENT_DETACHED = 0x04;
public readonly int index;
/** Position of the node. */

View File

@ -0,0 +1,9 @@
namespace DotRecast.Detour
{
public static class DtNodeFlags
{
public const int DT_NODE_OPEN = 0x01;
public const int DT_NODE_CLOSED = 0x02;
public const int DT_NODE_PARENT_DETACHED = 0x04; // parent of the node is not adjacent. Found using raycast.
}
}