MCPcopy Create free account
hub / github.com/axmolengine/axmol / findPath

Method findPath

3rdparty/recast/DetourNavMeshQuery.cpp:973–1165  ·  view source on GitHub ↗

@par If the end polygon cannot be reached through the navigation graph, the last polygon in the path will be the nearest the end polygon. If the path array is to small to hold the full result, it will be filled as far as possible from the start polygon toward the end polygon. The start and end positions are used to calculate traversal costs. (The y-values impact the result.)

Source from the content-addressed store, hash-verified

971/// (The y-values impact the result.)
972///
973dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
974 const float* startPos, const float* endPos,
975 const dtQueryFilter* filter,
976 dtPolyRef* path, int* pathCount, const int maxPath) const
977{
978 dtAssert(m_nav);
979 dtAssert(m_nodePool);
980 dtAssert(m_openList);
981
982 if (!pathCount)
983 return DT_FAILURE | DT_INVALID_PARAM;
984
985 *pathCount = 0;
986
987 // Validate input
988 if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
989 !startPos || !dtVisfinite(startPos) ||
990 !endPos || !dtVisfinite(endPos) ||
991 !filter || !path || maxPath <= 0)
992 {
993 return DT_FAILURE | DT_INVALID_PARAM;
994 }
995
996 if (startRef == endRef)
997 {
998 path[0] = startRef;
999 *pathCount = 1;
1000 return DT_SUCCESS;
1001 }
1002
1003 m_nodePool->clear();
1004 m_openList->clear();
1005
1006 dtNode* startNode = m_nodePool->getNode(startRef);
1007 dtVcopy(startNode->pos, startPos);
1008 startNode->pidx = 0;
1009 startNode->cost = 0;
1010 startNode->total = dtVdist(startPos, endPos) * H_SCALE;
1011 startNode->id = startRef;
1012 startNode->flags = DT_NODE_OPEN;
1013 m_openList->push(startNode);
1014
1015 dtNode* lastBestNode = startNode;
1016 float lastBestNodeCost = startNode->total;
1017
1018 bool outOfNodes = false;
1019
1020 while (!m_openList->empty())
1021 {
1022 // Remove node from open list and put it in closed list.
1023 dtNode* bestNode = m_openList->pop();
1024 bestNode->flags &= ~DT_NODE_OPEN;
1025 bestNode->flags |= DT_NODE_CLOSED;
1026
1027 // Reached the goal, stop searching.
1028 if (bestNode->id == endRef)
1029 {
1030 lastBestNode = bestNode;

Callers

nothing calls this directly

Calls 15

dtVisfiniteFunction · 0.85
dtVcopyFunction · 0.85
dtVdistFunction · 0.85
getNodeAtIdxMethod · 0.80
passFilterMethod · 0.80
getCostMethod · 0.80
getNodeIdxMethod · 0.80
modifyMethod · 0.80
isValidPolyRefMethod · 0.45
clearMethod · 0.45
getNodeMethod · 0.45

Tested by

no test coverage detected