DETOUR return status codes changed, check blog! Changed Detour status codes to be bitfields which describes the highlevel status plus some details about the failure or quality of the result.

This commit is contained in:
Mikko Mononen
2010-11-26 11:56:34 +00:00
parent 7fbcfa9c4b
commit 08741e894c
11 changed files with 1011 additions and 856 deletions

View File

@@ -121,7 +121,7 @@ dtStatus dtNavMeshQuery::init(const dtNavMesh* nav, const int maxNodes)
}
m_nodePool = new (dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(maxNodes, dtNextPow2(maxNodes/4));
if (!m_nodePool)
return DT_FAILURE_OUT_OF_MEMORY;
return DT_FAILURE | DT_OUT_OF_MEMORY;
}
else
{
@@ -132,7 +132,7 @@ dtStatus dtNavMeshQuery::init(const dtNavMesh* nav, const int maxNodes)
{
m_tinyNodePool = new (dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(64, 32);
if (!m_tinyNodePool)
return DT_FAILURE_OUT_OF_MEMORY;
return DT_FAILURE | DT_OUT_OF_MEMORY;
}
else
{
@@ -150,7 +150,7 @@ dtStatus dtNavMeshQuery::init(const dtNavMesh* nav, const int maxNodes)
}
m_openList = new (dtAlloc(sizeof(dtNodeQueue), DT_ALLOC_PERM)) dtNodeQueue(maxNodes);
if (!m_openList)
return DT_FAILURE_OUT_OF_MEMORY;
return DT_FAILURE | DT_OUT_OF_MEMORY;
}
else
{
@@ -166,16 +166,18 @@ dtStatus dtNavMeshQuery::closestPointOnPoly(dtPolyRef ref, const float* pos, flo
dtAssert(m_nav);
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (m_nav->getTileAndPolyByRef(ref, &tile, &poly) != DT_SUCCESS)
return DT_FAILURE;
if (!tile) return DT_FAILURE;
if (closestPointOnPolyInTile(tile, poly, pos, closest) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
if (!tile)
return DT_FAILURE | DT_INVALID_PARAM;
closestPointOnPolyInTile(tile, poly, pos, closest);
return DT_SUCCESS;
}
dtStatus dtNavMeshQuery::closestPointOnPolyInTile(const dtMeshTile* tile, const dtPoly* poly,
const float* pos, float* closest) const
void dtNavMeshQuery::closestPointOnPolyInTile(const dtMeshTile* tile, const dtPoly* poly,
const float* pos, float* closest) const
{
const unsigned int ip = (unsigned int)(poly - tile->polys);
const dtPolyDetail* pd = &tile->detailMeshes[ip];
@@ -253,8 +255,6 @@ dtStatus dtNavMeshQuery::closestPointOnPolyInTile(const dtMeshTile* tile, const
closestDistSqr = d;
}
}
return DT_SUCCESS;
}
dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float* pos, float* closest) const
@@ -263,8 +263,8 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (m_nav->getTileAndPolyByRef(ref, &tile, &poly) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
// Collect vertices.
float verts[DT_VERTS_PER_POLYGON*3];
@@ -311,8 +311,8 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (m_nav->getTileAndPolyByRef(ref, &tile, &poly) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
{
@@ -350,7 +350,7 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h
}
}
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
}
dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* extents,
@@ -364,8 +364,8 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten
// Get nearby polygons from proximity grid.
dtPolyRef polys[128];
int polyCount = 0;
if (queryPolygons(center, extents, filter, polys, &polyCount, 128) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(queryPolygons(center, extents, filter, polys, &polyCount, 128)))
return DT_FAILURE | DT_INVALID_PARAM;
// Find nearest polygon amongst the nearby polygons.
dtPolyRef nearest = 0;
@@ -374,8 +374,7 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten
{
dtPolyRef ref = polys[i];
float closestPtPoly[3];
if (closestPointOnPoly(ref, center, closestPtPoly) != DT_SUCCESS)
continue;
closestPointOnPoly(ref, center, closestPtPoly);
float d = dtVdistSqr(center, closestPtPoly);
if (d < nearestDistanceSqr)
{
@@ -413,8 +412,7 @@ dtPolyRef dtNavMeshQuery::findNearestPolyInTile(const dtMeshTile* tile, const fl
dtPolyRef ref = polys[i];
const dtPoly* poly = &tile->polys[m_nav->decodePolyIdPoly(ref)];
float closestPtPoly[3];
if (closestPointOnPolyInTile(tile, poly, center, closestPtPoly) != DT_SUCCESS)
continue;
closestPointOnPolyInTile(tile, poly, center, closestPtPoly);
float d = dtVdistSqr(center, closestPtPoly);
if (d < nearestDistanceSqr)
@@ -547,7 +545,7 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents
if (n >= maxPolys)
{
*polyCount = n;
return DT_SUCCESS;
return DT_SUCCESS | DT_BUFFER_TOO_SMALL;
}
}
}
@@ -568,14 +566,14 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
*pathCount = 0;
if (!startRef || !endRef)
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
if (!maxPath)
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
// Validate input
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef))
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
if (startRef == endRef)
{
@@ -599,6 +597,8 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
dtNode* lastBestNode = startNode;
float lastBestNodeCost = startNode->total;
dtStatus status = DT_SUCCESS;
while (!m_openList->empty())
{
// Remove node from open list and put it in closed list.
@@ -648,7 +648,10 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
dtNode* neighbourNode = m_nodePool->getNode(neighbourRef);
if (!neighbourNode)
{
status |= DT_OUT_OF_NODES;
continue;
}
// If the node is visited the first time, calculate node position.
if (neighbourNode->flags == 0)
@@ -726,6 +729,9 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
}
}
if (lastBestNode->id != endRef)
status |= DT_PARTIAL_RESULT;
// Reverse the path.
dtNode* prev = 0;
dtNode* node = lastBestNode;
@@ -744,13 +750,18 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
do
{
path[n++] = node->id;
if (n >= maxPath)
{
status |= DT_BUFFER_TOO_SMALL;
break;
}
node = m_nodePool->getNodeAtIdx(node->pidx);
}
while (node && n < maxPath);
while (node);
*pathCount = n;
return DT_SUCCESS;
return status;
}
dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef,
@@ -771,11 +782,11 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
m_query.filter = filter;
if (!startRef || !endRef)
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
// Validate input
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef))
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
if (startRef == endRef)
{
@@ -804,7 +815,7 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter)
{
if (m_query.status!= DT_IN_PROGRESS)
if (!dtStatusInProgress(m_query.status))
return m_query.status;
// Make sure the request is still valid.
@@ -828,7 +839,8 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter)
if (bestNode->id == m_query.endRef)
{
m_query.lastBestNode = bestNode;
m_query.status = DT_SUCCESS;
const dtStatus details = m_query.status & DT_STATUS_DETAIL_MASK;
m_query.status = DT_SUCCESS | details;
return m_query.status;
}
@@ -837,7 +849,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter)
const dtPolyRef bestRef = bestNode->id;
const dtMeshTile* bestTile = 0;
const dtPoly* bestPoly = 0;
if (m_nav->getTileAndPolyByRef(bestRef, &bestTile, &bestPoly) != DT_SUCCESS)
if (dtStatusFailed(m_nav->getTileAndPolyByRef(bestRef, &bestTile, &bestPoly)))
{
// The polygon has disappeared during the sliced query, fail.
m_query.status = DT_FAILURE;
@@ -852,7 +864,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter)
parentRef = m_nodePool->getNodeAtIdx(bestNode->pidx)->id;
if (parentRef)
{
if (m_nav->getTileAndPolyByRef(parentRef, &parentTile, &parentPoly) != DT_SUCCESS)
if (dtStatusFailed(m_nav->getTileAndPolyByRef(parentRef, &parentTile, &parentPoly)))
{
// The polygon has disappeared during the sliced query, fail.
m_query.status = DT_FAILURE;
@@ -879,7 +891,10 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter)
dtNode* neighbourNode = m_nodePool->getNode(neighbourRef);
if (!neighbourNode)
{
m_query.status |= DT_OUT_OF_NODES;
continue;
}
// If the node is visited the first time, calculate node position.
if (neighbourNode->flags == 0)
@@ -959,7 +974,10 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter)
// Exhausted all nodes, but could not find path.
if (m_openList->empty())
m_query.status = DT_SUCCESS;
{
const dtStatus details = m_query.status & DT_STATUS_DETAIL_MASK;
m_query.status = DT_SUCCESS | details;
}
return m_query.status;
}
@@ -968,7 +986,7 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount,
{
*pathCount = 0;
if (m_query.status != DT_SUCCESS)
if (dtStatusFailed(m_query.status))
{
// Reset query.
memset(&m_query, 0, sizeof(dtQueryData));
@@ -986,6 +1004,10 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount,
{
// Reverse the path.
dtAssert(m_query.lastBestNode);
if (m_query.lastBestNode->id != m_query.endRef)
m_query.status |= DT_PARTIAL_RESULT;
dtNode* prev = 0;
dtNode* node = m_query.lastBestNode;
do
@@ -1002,17 +1024,24 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount,
do
{
path[n++] = node->id;
if (n >= maxPath)
{
m_query.status |= DT_BUFFER_TOO_SMALL;
break;
}
node = m_nodePool->getNodeAtIdx(node->pidx);
}
while (node && n < maxPath);
while (node);
}
const dtStatus details = m_query.status & DT_STATUS_DETAIL_MASK;
// Reset query.
memset(&m_query, 0, sizeof(dtQueryData));
*pathCount = n;
return DT_SUCCESS;
return DT_SUCCESS | details;
}
dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
@@ -1025,7 +1054,7 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing
return DT_FAILURE;
}
if (m_query.status != DT_SUCCESS && m_query.status != DT_IN_PROGRESS)
if (dtStatusFailed(m_query.status))
{
// Reset query.
memset(&m_query, 0, sizeof(dtQueryData));
@@ -1071,17 +1100,24 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing
do
{
path[n++] = node->id;
if (n >= maxPath)
{
m_query.status |= DT_BUFFER_TOO_SMALL;
break;
}
node = m_nodePool->getNodeAtIdx(node->pidx);
}
while (node && n < maxPath);
while (node);
}
const dtStatus details = m_query.status & DT_STATUS_DETAIL_MASK;
// Reset query.
memset(&m_query, 0, sizeof(dtQueryData));
*pathCount = n;
return DT_SUCCESS;
return DT_SUCCESS | details;
}
@@ -1095,17 +1131,17 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
*straightPathCount = 0;
if (!maxStraightPath)
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
if (!path[0])
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
int n = 0;
// TODO: Should this be callers responsibility?
float closestStartPos[3];
if (closestPointOnPolyBoundary(path[0], startPos, closestStartPos) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(closestPointOnPolyBoundary(path[0], startPos, closestStartPos)))
return DT_FAILURE | DT_INVALID_PARAM;
// Add start point.
dtVcopy(&straightPath[n*3], closestStartPos);
@@ -1117,12 +1153,12 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
if (n >= maxStraightPath)
{
*straightPathCount = n;
return DT_SUCCESS;
return DT_SUCCESS | DT_BUFFER_TOO_SMALL;
}
float closestEndPos[3];
if (closestPointOnPolyBoundary(path[pathSize-1], endPos, closestEndPos) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(closestPointOnPolyBoundary(path[pathSize-1], endPos, closestEndPos)))
return DT_FAILURE | DT_INVALID_PARAM;
if (pathSize > 1)
{
@@ -1148,10 +1184,10 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
if (i+1 < pathSize)
{
// Next portal.
if (getPortalPoints(path[i], path[i+1], left, right, fromType, toType) != DT_SUCCESS)
if (dtStatusFailed(getPortalPoints(path[i], path[i+1], left, right, fromType, toType)))
{
if (closestPointOnPolyBoundary(path[i], endPos, closestEndPos) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(closestPointOnPolyBoundary(path[i], endPos, closestEndPos)))
return DT_FAILURE | DT_INVALID_PARAM;
dtVcopy(&straightPath[n*3], closestEndPos);
if (straightPathFlags)
@@ -1215,7 +1251,7 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
if (flags == DT_STRAIGHTPATH_END || n >= maxStraightPath)
{
*straightPathCount = n;
return DT_SUCCESS;
return DT_SUCCESS | ((n >= maxStraightPath) ? DT_BUFFER_TOO_SMALL : 0);
}
}
else
@@ -1274,7 +1310,7 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
if (flags == DT_STRAIGHTPATH_END || n >= maxStraightPath)
{
*straightPathCount = n;
return DT_SUCCESS;
return DT_SUCCESS | ((n >= maxStraightPath) ? DT_BUFFER_TOO_SMALL : 0);
}
}
else
@@ -1316,7 +1352,8 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
}
*straightPathCount = n;
return DT_SUCCESS;
return DT_SUCCESS | ((n >= maxStraightPath) ? DT_BUFFER_TOO_SMALL : 0);
}
dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos,
@@ -1329,8 +1366,12 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
*visitedCount = 0;
// Validate input
if (!startRef) return DT_FAILURE;
if (!m_nav->isValidPolyRef(startRef)) return DT_FAILURE;
if (!startRef)
return DT_FAILURE | DT_INVALID_PARAM;
if (!m_nav->isValidPolyRef(startRef))
return DT_FAILURE | DT_INVALID_PARAM;
dtStatus status = DT_SUCCESS;
static const int MAX_STACK = 48;
dtNode* stack[MAX_STACK];
@@ -1495,16 +1536,21 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
do
{
visited[n++] = node->id;
if (n >= maxVisitedSize)
{
status |= DT_BUFFER_TOO_SMALL;
break;
}
node = m_tinyNodePool->getNodeAtIdx(node->pidx);
}
while (node && n < maxVisitedSize);
while (node);
}
dtVcopy(resultPos, bestPos);
*visitedCount = n;
return DT_SUCCESS;
return status;
}
@@ -1515,14 +1561,14 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, dtPolyRef to, float* le
const dtMeshTile* fromTile = 0;
const dtPoly* fromPoly = 0;
if (m_nav->getTileAndPolyByRef(from, &fromTile, &fromPoly) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(from, &fromTile, &fromPoly)))
return DT_FAILURE | DT_INVALID_PARAM;
fromType = fromPoly->getType();
const dtMeshTile* toTile = 0;
const dtPoly* toPoly = 0;
if (m_nav->getTileAndPolyByRef(to, &toTile, &toPoly) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(to, &toTile, &toPoly)))
return DT_FAILURE | DT_INVALID_PARAM;
toType = toPoly->getType();
return getPortalPoints(from, fromPoly, fromTile, to, toPoly, toTile, left, right);
@@ -1544,7 +1590,7 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
}
}
if (!link)
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
// Handle off-mesh connections.
if (fromPoly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
@@ -1560,7 +1606,7 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
return DT_SUCCESS;
}
}
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
}
if (toPoly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
@@ -1575,7 +1621,7 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
return DT_SUCCESS;
}
}
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
}
// Find portal vertices.
@@ -1607,7 +1653,8 @@ dtStatus dtNavMeshQuery::getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float* mi
{
float left[3], right[3];
unsigned char fromType, toType;
if (!getPortalPoints(from, to, left,right, fromType, toType)) return DT_FAILURE;
if (dtStatusFailed(getPortalPoints(from, to, left,right, fromType, toType)))
return DT_FAILURE | DT_INVALID_PARAM;
mid[0] = (left[0]+right[0])*0.5f;
mid[1] = (left[1]+right[1])*0.5f;
mid[2] = (left[2]+right[2])*0.5f;
@@ -1619,8 +1666,8 @@ dtStatus dtNavMeshQuery::getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly,
float* mid) const
{
float left[3], right[3];
if (getPortalPoints(from, fromPoly, fromTile, to, toPoly, toTile, left, right) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(getPortalPoints(from, fromPoly, fromTile, to, toPoly, toTile, left, right)))
return DT_FAILURE | DT_INVALID_PARAM;
mid[0] = (left[0]+right[0])*0.5f;
mid[1] = (left[1]+right[1])*0.5f;
mid[2] = (left[2]+right[2])*0.5f;
@@ -1639,7 +1686,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
// Validate input
if (!startRef || !m_nav->isValidPolyRef(startRef))
return DT_FAILURE;
return DT_FAILURE | DT_INVALID_PARAM;
dtPolyRef curRef = startRef;
float verts[DT_VERTS_PER_POLYGON*3];
@@ -1649,6 +1696,8 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
hitNormal[1] = 0;
hitNormal[2] = 0;
dtStatus status = DT_SUCCESS;
while (curRef)
{
// Cast ray against current polygon.
@@ -1673,7 +1722,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
// Could not hit the polygon, keep the old t and report hit.
if (pathCount)
*pathCount = n;
return DT_SUCCESS;
return status;
}
// Keep track of furthest t so far.
if (tmax > *t)
@@ -1682,6 +1731,8 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
// Store visited polygons.
if (n < maxPath)
path[n++] = curRef;
else
status |= DT_BUFFER_TOO_SMALL;
// Ray end is completely inside the polygon.
if (segMax == -1)
@@ -1689,7 +1740,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
*t = FLT_MAX;
if (pathCount)
*pathCount = n;
return DT_SUCCESS;
return status;
}
// Follow neighbours.
@@ -1791,7 +1842,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
if (pathCount)
*pathCount = n;
return DT_SUCCESS;
return status;
}
// No hit, advance to neighbour polygon.
@@ -1801,7 +1852,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
if (pathCount)
*pathCount = n;
return DT_SUCCESS;
return status;
}
dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius,
@@ -1816,8 +1867,8 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
*resultCount = 0;
// Validate input
if (!startRef) return DT_FAILURE;
if (!m_nav->isValidPolyRef(startRef)) return DT_FAILURE;
if (!startRef || !m_nav->isValidPolyRef(startRef))
return DT_FAILURE | DT_INVALID_PARAM;
m_nodePool->clear();
m_openList->clear();
@@ -1831,6 +1882,8 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
startNode->flags = DT_NODE_OPEN;
m_openList->push(startNode);
dtStatus status = DT_SUCCESS;
int n = 0;
if (n < maxResult)
{
@@ -1842,6 +1895,10 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
resultCost[n] = 0;
++n;
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
const float radiusSqr = dtSqr(radius);
@@ -1897,7 +1954,10 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
dtNode* neighbourNode = m_nodePool->getNode(neighbourRef);
if (!neighbourNode)
{
status |= DT_OUT_OF_NODES;
continue;
}
if (neighbourNode->flags & DT_NODE_CLOSED)
continue;
@@ -1933,6 +1993,10 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
resultCost[n] = neighbourNode->total;
++n;
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
neighbourNode->flags = DT_NODE_OPEN;
m_openList->push(neighbourNode);
}
@@ -1941,7 +2005,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
*resultCount = n;
return DT_SUCCESS;
return status;
}
dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* verts, const int nverts,
@@ -1956,8 +2020,8 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
*resultCount = 0;
// Validate input
if (!startRef) return DT_FAILURE;
if (!m_nav->isValidPolyRef(startRef)) return DT_FAILURE;
if (!startRef || !m_nav->isValidPolyRef(startRef))
return DT_FAILURE | DT_INVALID_PARAM;
m_nodePool->clear();
m_openList->clear();
@@ -1976,6 +2040,8 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
startNode->flags = DT_NODE_OPEN;
m_openList->push(startNode);
dtStatus status = DT_SUCCESS;
int n = 0;
if (n < maxResult)
{
@@ -1987,6 +2053,10 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
resultCost[n] = 0;
++n;
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
while (!m_openList->empty())
{
@@ -2042,7 +2112,10 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
dtNode* neighbourNode = m_nodePool->getNode(neighbourRef);
if (!neighbourNode)
{
status |= DT_OUT_OF_NODES;
continue;
}
if (neighbourNode->flags & DT_NODE_CLOSED)
continue;
@@ -2078,6 +2151,10 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
resultCost[n] = neighbourNode->total;
++n;
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
neighbourNode->flags = DT_NODE_OPEN;
m_openList->push(neighbourNode);
}
@@ -2086,7 +2163,7 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
*resultCount = n;
return DT_SUCCESS;
return status;
}
dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float* centerPos, const float radius,
@@ -2100,8 +2177,8 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
*resultCount = 0;
// Validate input
if (!startRef) return DT_FAILURE;
if (!m_nav->isValidPolyRef(startRef)) return DT_FAILURE;
if (!startRef || !m_nav->isValidPolyRef(startRef))
return DT_FAILURE | DT_INVALID_PARAM;
static const int MAX_STACK = 48;
dtNode* stack[MAX_STACK];
@@ -2120,6 +2197,8 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
float pa[DT_VERTS_PER_POLYGON*3];
float pb[DT_VERTS_PER_POLYGON*3];
dtStatus status = DT_SUCCESS;
int n = 0;
if (n < maxResult)
{
@@ -2128,6 +2207,10 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
resultParent[n] = 0;
++n;
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
while (nstack)
{
@@ -2241,6 +2324,10 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
resultParent[n] = curRef;
++n;
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
if (nstack < MAX_STACK)
{
@@ -2251,7 +2338,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
*resultCount = n;
return DT_SUCCESS;
return status;
}
@@ -2290,14 +2377,16 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (m_nav->getTileAndPolyByRef(ref, &tile, &poly) != DT_SUCCESS)
return DT_FAILURE;
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
return DT_FAILURE | DT_INVALID_PARAM;
int n = 0;
static const int MAX_INTERVAL = 16;
dtSegInterval ints[MAX_INTERVAL];
int nints;
dtStatus status = DT_SUCCESS;
for (int i = 0, j = (int)poly->vertCount-1; i < (int)poly->vertCount; j = i++)
{
// Skip non-solid edges.
@@ -2354,6 +2443,10 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
dtVcopy(seg+0, vj);
dtVcopy(seg+3, vi);
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
}
else
{
@@ -2366,13 +2459,17 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
dtVlerp(seg+0, vj,vi, tmin);
dtVlerp(seg+3, vj,vi, tmax);
}
else
{
status |= DT_BUFFER_TOO_SMALL;
}
}
}
}
*segmentCount = n;
return DT_SUCCESS;
return status;
}
dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* centerPos, const float maxRadius,
@@ -2384,8 +2481,8 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
dtAssert(m_openList);
// Validate input
if (!startRef) return DT_FAILURE;
if (!m_nav->isValidPolyRef(startRef)) return DT_FAILURE;
if (!startRef || !m_nav->isValidPolyRef(startRef))
return DT_FAILURE | DT_INVALID_PARAM;
m_nodePool->clear();
m_openList->clear();
@@ -2401,6 +2498,8 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
float radiusSqr = dtSqr(maxRadius);
dtStatus status = DT_SUCCESS;
while (!m_openList->empty())
{
dtNode* bestNode = m_openList->pop();
@@ -2508,7 +2607,10 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
dtNode* neighbourNode = m_nodePool->getNode(neighbourRef);
if (!neighbourNode)
{
status |= DT_OUT_OF_NODES;
continue;
}
if (neighbourNode->flags & DT_NODE_CLOSED)
continue;
@@ -2549,7 +2651,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
*hitDist = sqrtf(radiusSqr);
return DT_SUCCESS;
return status;
}
bool dtNavMeshQuery::isInClosedList(dtPolyRef ref) const