Skip to content

Commit

Permalink
[12691] Update code for new recast/detour return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberium committed Jul 30, 2014
1 parent 4681113 commit 3b6b2e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion contrib/mmap/src/MapBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ namespace MMAP
// DT_TILE_FREE_DATA tells detour to unallocate memory when the tile
// is removed via removeTile()
dtStatus dtResult = navMesh->addTile(navData, navDataSize, DT_TILE_FREE_DATA, 0, &tileRef);
if (!tileRef || dtResult != DT_SUCCESS)
if (!tileRef || dtStatusFailed(dtResult))
{
printf("%s Failed adding tile to navmesh! \n", tileString);
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/game/Level2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5408,8 +5408,8 @@ bool ChatHandler::HandleMmapLocCommand(char* /*args*/)
{
const dtMeshTile* tile;
const dtPoly* poly;
navmesh->getTileAndPolyByRef(polyRef, &tile, &poly);
if (tile)
dtStatus dtResult = navmesh->getTileAndPolyByRef(polyRef, &tile, &poly);
if ((dtStatusSucceed(dtResult)) && tile)
PSendSysMessage("Dt [%02i,%02i]", tile->header->x, tile->header->y);
else
PSendSysMessage("Dt [??,??] (no tile loaded)");
Expand Down
15 changes: 10 additions & 5 deletions src/game/MoveMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ namespace MMAP

dtNavMesh* mesh = dtAllocNavMesh();
MANGOS_ASSERT(mesh);
if (DT_SUCCESS != mesh->init(&params))
dtStatus dtResult = mesh->init(&params);
if (dtStatusFailed(dtResult))
{
dtFreeNavMesh(mesh);
sLog.outError("MMAP:loadMapData: Failed to initialize dtNavMesh for mmap %03u from file %s", mapId, fileName);
Expand Down Expand Up @@ -203,7 +204,8 @@ namespace MMAP
dtTileRef tileRef = 0;

// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
if (mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef) != DT_SUCCESS)
dtStatus dtResult = mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef);
if (dtStatusFailed(dtResult))
{
sLog.outError("MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y);
dtFree(data);
Expand Down Expand Up @@ -240,7 +242,8 @@ namespace MMAP
dtTileRef tileRef = mmap->mmapLoadedTiles[packedGridPos];

// unload, and mark as non loaded
if (DT_SUCCESS != mmap->navMesh->removeTile(tileRef, NULL, NULL))
dtStatus dtResult = mmap->navMesh->removeTile(tileRef, NULL, NULL);
if (dtStatusFailed(dtResult))
{
// this is technically a memory leak
// if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used
Expand Down Expand Up @@ -274,7 +277,8 @@ namespace MMAP
{
uint32 x = (i->first >> 16);
uint32 y = (i->first & 0x0000FFFF);
if (DT_SUCCESS != mmap->navMesh->removeTile(i->second, NULL, NULL))
dtStatus dtResult = mmap->navMesh->removeTile(i->second, NULL, NULL);
if (dtStatusFailed(dtResult) )
sLog.outError("MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y);
else
{
Expand Down Expand Up @@ -335,7 +339,8 @@ namespace MMAP
// allocate mesh query
dtNavMeshQuery* query = dtAllocNavMeshQuery();
MANGOS_ASSERT(query);
if (DT_SUCCESS != query->init(mmap->navMesh, 1024))
dtStatus dtResult = query->init(mmap->navMesh, 1024);
if (dtStatusFailed(dtResult))
{
dtFreeNavMeshQuery(query);
sLog.outError("MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId);
Expand Down
43 changes: 26 additions & 17 deletions src/game/PathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ dtPolyRef PathFinder::getPathPolyByPosition(const dtPolyRef* polyPath, uint32 po
for (uint32 i = 0; i < polyPathSize; ++i)
{
float closestPoint[VERTEX_SIZE];
if (DT_SUCCESS != m_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint))
dtStatus dtResult = m_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint);
if (dtStatusFailed(dtResult))
continue;

float d = dtVdist2DSqr(point, closestPoint);
Expand Down Expand Up @@ -126,8 +127,8 @@ dtPolyRef PathFinder::getPolyByLocation(const float* point, float* distance) con
// first try with low search box
float extents[VERTEX_SIZE] = {3.0f, 5.0f, 3.0f}; // bounds of poly search area
float closestPoint[VERTEX_SIZE] = {0.0f, 0.0f, 0.0f};
dtStatus result = m_navMeshQuery->findNearestPoly(point, extents, &m_filter, &polyRef, closestPoint);
if (DT_SUCCESS == result && polyRef != INVALID_POLYREF)
dtStatus dtResult = m_navMeshQuery->findNearestPoly(point, extents, &m_filter, &polyRef, closestPoint);
if (dtStatusSucceed(dtResult) && polyRef != INVALID_POLYREF)
{
*distance = dtVdist(closestPoint, point);
return polyRef;
Expand All @@ -136,8 +137,8 @@ dtPolyRef PathFinder::getPolyByLocation(const float* point, float* distance) con
// still nothing ..
// try with bigger search box
extents[1] = 200.0f;
result = m_navMeshQuery->findNearestPoly(point, extents, &m_filter, &polyRef, closestPoint);
if (DT_SUCCESS == result && polyRef != INVALID_POLYREF)
dtResult = m_navMeshQuery->findNearestPoly(point, extents, &m_filter, &polyRef, closestPoint);
if (dtStatusSucceed(dtResult) && polyRef != INVALID_POLYREF)
{
*distance = dtVdist(closestPoint, point);
return polyRef;
Expand All @@ -157,6 +158,8 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)
dtPolyRef startPoly = getPolyByLocation(startPoint, &distToStartPoly);
dtPolyRef endPoly = getPolyByLocation(endPoint, &distToEndPoly);

dtStatus dtResult;

// we have a hole in our mesh
// make shortcut path and mark it as NOPATH ( with flying exception )
// its up to caller how he will use this info
Expand Down Expand Up @@ -216,7 +219,8 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)
{
float closestPoint[VERTEX_SIZE];
// we may want to use closestPointOnPolyBoundary instead
if (DT_SUCCESS == m_navMeshQuery->closestPointOnPoly(endPoly, endPoint, closestPoint))
dtResult = m_navMeshQuery->closestPointOnPoly(endPoly, endPoint, closestPoint);
if (dtStatusSucceed(dtResult))
{
dtVcopy(endPoint, closestPoint);
setActualEndPosition(Vector3(endPoint[2], endPoint[0], endPoint[1]));
Expand Down Expand Up @@ -306,13 +310,15 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)

// we need any point on our suffix start poly to generate poly-path, so we need last poly in prefix data
float suffixEndPoint[VERTEX_SIZE];
if (DT_SUCCESS != m_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint))
dtResult = m_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint);
if (dtStatusFailed(dtResult))
{
// we can hit offmesh connection as last poly - closestPointOnPoly() don't like that
// try to recover by using prev polyref
--prefixPolyLength;
suffixStartPoly = m_pathPolyRefs[prefixPolyLength - 1];
if (DT_SUCCESS != m_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint))
dtResult = m_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint);
if (dtStatusFailed(dtResult))
{
// suffixStartPoly is still invalid, error state
BuildShortcut();
Expand All @@ -323,7 +329,7 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)

// generate suffix
uint32 suffixPolyLength = 0;
dtStatus dtResult = m_navMeshQuery->findPath(
dtResult = m_navMeshQuery->findPath(
suffixStartPoly, // start polygon
endPoly, // end polygon
suffixEndPoint, // start position
Expand All @@ -333,7 +339,7 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)
(int*)&suffixPolyLength,
MAX_PATH_LENGTH - prefixPolyLength); // max number of polygons in output path

if (!suffixPolyLength || dtResult != DT_SUCCESS)
if (!suffixPolyLength || dtStatusFailed(dtResult))
{
// this is probably an error state, but we'll leave it
// and hopefully recover on the next Update
Expand All @@ -357,7 +363,7 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)
// free and invalidate old path data
clear();

dtStatus dtResult = m_navMeshQuery->findPath(
dtResult = m_navMeshQuery->findPath(
startPoly, // start polygon
endPoly, // end polygon
startPoint, // start position
Expand All @@ -367,7 +373,7 @@ void PathFinder::BuildPolyPath(const Vector3& startPos, const Vector3& endPos)
(int*)&m_polyLength,
MAX_PATH_LENGTH); // max number of polygons in output path

if (!m_polyLength || dtResult != DT_SUCCESS)
if (!m_polyLength || dtStatusFailed(dtResult))
{
// only happens if we passed bad data to findPath(), or navmesh is messed up
sLog.outError("%u's Path Build failed: 0 length path", m_sourceUnit->GetGUIDLow());
Expand Down Expand Up @@ -417,7 +423,7 @@ void PathFinder::BuildPointPath(const float* startPoint, const float* endPoint)
m_pointPathLimit); // maximum number of points
}

if (pointCount < 2 || dtResult != DT_SUCCESS)
if (pointCount < 2 || dtStatusFailed(dtResult))
{
// only happens if pass bad data to findStraightPath or navmesh is broken
// single point paths can be generated here
Expand Down Expand Up @@ -602,7 +608,7 @@ bool PathFinder::getSteerTarget(const float* startPos, const float* endPos,
uint32 nsteerPath = 0;
dtStatus dtResult = m_navMeshQuery->findStraightPath(startPos, endPos, path, pathSize,
steerPath, steerPathFlags, steerPathPolys, (int*)&nsteerPath, MAX_STEER_POINTS);
if (!nsteerPath || DT_SUCCESS != dtResult)
if (!nsteerPath || dtStatusFailed(dtResult))
return false;

// Find vertex far enough to steer to.
Expand Down Expand Up @@ -639,10 +645,12 @@ dtStatus PathFinder::findSmoothPath(const float* startPos, const float* endPos,
uint32 npolys = polyPathSize;

float iterPos[VERTEX_SIZE], targetPos[VERTEX_SIZE];
if (DT_SUCCESS != m_navMeshQuery->closestPointOnPolyBoundary(polys[0], startPos, iterPos))
dtStatus dtResult = m_navMeshQuery->closestPointOnPolyBoundary(polys[0], startPos, iterPos);
if (dtStatusFailed(dtResult))
return DT_FAILURE;

if (DT_SUCCESS != m_navMeshQuery->closestPointOnPolyBoundary(polys[npolys - 1], endPos, targetPos))
dtResult = m_navMeshQuery->closestPointOnPolyBoundary(polys[npolys - 1], endPos, targetPos);
if (dtStatusFailed(dtResult))
return DT_FAILURE;

dtVcopy(&smoothPath[nsmoothPath * VERTEX_SIZE], iterPos);
Expand Down Expand Up @@ -721,7 +729,8 @@ dtStatus PathFinder::findSmoothPath(const float* startPos, const float* endPos,

// Handle the connection.
float startPos[VERTEX_SIZE], endPos[VERTEX_SIZE];
if (DT_SUCCESS == m_navMesh->getOffMeshConnectionPolyEndPoints(prevRef, polyRef, startPos, endPos))
dtResult = m_navMesh->getOffMeshConnectionPolyEndPoints(prevRef, polyRef, startPos, endPos);
if (dtStatusSucceed(dtResult))
{
if (nsmoothPath < maxSmoothPathSize)
{
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12690"
#define REVISION_NR "12691"
#endif // __REVISION_NR_H__

0 comments on commit 3b6b2e3

Please sign in to comment.