Skip to content

Commit

Permalink
Add upToDate param for dtTileCache::update (recastnavigation#203)
Browse files Browse the repository at this point in the history
This changes dtTileCache::update to add an optional parameter that
indicates whether the tile cache is up to date. This is useful to
determine whether calling the function again would do anything.
  • Loading branch information
jakobbotsch committed Apr 25, 2016
1 parent b05e454 commit 36183ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 7 additions & 1 deletion DetourTileCache/Include/DetourTileCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ class dtTileCache
dtStatus queryTiles(const float* bmin, const float* bmax,
dtCompressedTileRef* results, int* resultCount, const int maxResults) const;

dtStatus update(const float /*dt*/, class dtNavMesh* navmesh);
/// Updates the tile cache by rebuilding tiles touched by unfinished obstacle requests.
/// @param[in] dt The time step size. Currently not used.
/// @param[in] navmesh The mesh to affect when rebuilding tiles.
/// @param[out] upToDate Whether the tile cache is fully up to date with obstacle requests and tile rebuilds.
/// If the tile cache is up to date another (immediate) call to update will have no effect;
/// otherwise another call will continue processing obstacle requests and tile rebuilds.
dtStatus update(const float dt, class dtNavMesh* navmesh, bool* upToDate = 0);

dtStatus buildNavMeshTilesAt(const int tx, const int ty, class dtNavMesh* navmesh);

Expand Down
14 changes: 8 additions & 6 deletions DetourTileCache/Source/DetourTileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ dtStatus dtTileCache::queryTiles(const float* bmin, const float* bmax,
return DT_SUCCESS;
}

dtStatus dtTileCache::update(const float /*dt*/, dtNavMesh* navmesh)
dtStatus dtTileCache::update(const float /*dt*/, dtNavMesh* navmesh,
bool* upToDate)
{
if (m_nupdate == 0)
{
Expand Down Expand Up @@ -500,12 +501,13 @@ dtStatus dtTileCache::update(const float /*dt*/, dtNavMesh* navmesh)
m_nreqs = 0;
}

dtStatus status = DT_SUCCESS;
// Process updates
if (m_nupdate)
{
// Build mesh
const dtCompressedTileRef ref = m_update[0];
dtStatus status = buildNavMeshTile(ref, navmesh);
status = buildNavMeshTile(ref, navmesh);
m_nupdate--;
if (m_nupdate > 0)
memmove(m_update, m_update+1, m_nupdate*sizeof(dtCompressedTileRef));
Expand Down Expand Up @@ -548,12 +550,12 @@ dtStatus dtTileCache::update(const float /*dt*/, dtNavMesh* navmesh)
}
}
}

if (dtStatusFailed(status))
return status;
}

return DT_SUCCESS;
if (upToDate)
*upToDate = m_nupdate == 0 && m_nreqs == 0;

return status;
}


Expand Down

0 comments on commit 36183ed

Please sign in to comment.