From 36183edb55933e6d20bbf8d1aa1c202c2e5d2e05 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 25 Apr 2016 20:27:14 +0200 Subject: [PATCH] Add upToDate param for dtTileCache::update (#203) 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. --- DetourTileCache/Include/DetourTileCache.h | 8 +++++++- DetourTileCache/Source/DetourTileCache.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/DetourTileCache/Include/DetourTileCache.h b/DetourTileCache/Include/DetourTileCache.h index 9c7e01c..cbd1d36 100644 --- a/DetourTileCache/Include/DetourTileCache.h +++ b/DetourTileCache/Include/DetourTileCache.h @@ -111,7 +111,13 @@ public: 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); diff --git a/DetourTileCache/Source/DetourTileCache.cpp b/DetourTileCache/Source/DetourTileCache.cpp index 9ac11b6..e573fba 100644 --- a/DetourTileCache/Source/DetourTileCache.cpp +++ b/DetourTileCache/Source/DetourTileCache.cpp @@ -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) { @@ -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)); @@ -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; }