Browse Source

Flush the DetourTileCache update queue if necessary, when adding or removing an obstacle. Closes #726.

Lasse Öörni 10 years ago
parent
commit
fd8703dcec

+ 4 - 0
Source/ThirdParty/DetourTileCache/include/DetourTileCache.h

@@ -1,6 +1,8 @@
 #ifndef DETOURTILECACHE_H
 #ifndef DETOURTILECACHE_H
 #define DETOURTILECACHE_H
 #define DETOURTILECACHE_H
 
 
+// Modified by Lasse Oorni for Urho3D
+
 #include "DetourStatus.h"
 #include "DetourStatus.h"
 
 
 
 
@@ -121,6 +123,8 @@ public:
 	
 	
 	void getObstacleBounds(const struct dtTileCacheObstacle* ob, float* bmin, float* bmax) const;
 	void getObstacleBounds(const struct dtTileCacheObstacle* ob, float* bmin, float* bmax) const;
 	
 	
+    // Urho3D: added function to know when we have too many obstacle requests without update
+    bool isObstacleQueueFull() const { return m_nreqs >= MAX_REQUESTS; }
 
 
 	/// Encodes a tile id.
 	/// Encodes a tile id.
 	inline dtCompressedTileRef encodeTileId(unsigned int salt, unsigned int it) const
 	inline dtCompressedTileRef encodeTileId(unsigned int salt, unsigned int it) const

+ 7 - 0
Source/Urho3D/Navigation/DynamicNavigationMesh.cpp

@@ -864,6 +864,10 @@ void DynamicNavigationMesh::AddObstacle(Obstacle* obstacle, bool silent)
         Vector3 obsPos = obstacle->GetNode()->GetWorldPosition();
         Vector3 obsPos = obstacle->GetNode()->GetWorldPosition();
         rcVcopy(pos, &obsPos.x_);
         rcVcopy(pos, &obsPos.x_);
         dtObstacleRef refHolder;
         dtObstacleRef refHolder;
+
+        if (tileCache_->isObstacleQueueFull())
+            tileCache_->update(1, navMesh_);
+
         if (dtStatusFailed(tileCache_->addObstacle(pos, obstacle->GetRadius(), obstacle->GetHeight(), &refHolder)))
         if (dtStatusFailed(tileCache_->addObstacle(pos, obstacle->GetRadius(), obstacle->GetHeight(), &refHolder)))
         {
         {
             LOGERROR("Failed to add obstacle");
             LOGERROR("Failed to add obstacle");
@@ -900,6 +904,9 @@ void DynamicNavigationMesh::RemoveObstacle(Obstacle* obstacle, bool silent)
 {
 {
     if (tileCache_ && obstacle->obstacleId_ > 0)
     if (tileCache_ && obstacle->obstacleId_ > 0)
     {
     {
+        if (tileCache_->isObstacleQueueFull())
+            tileCache_->update(1, navMesh_);
+
         if (dtStatusFailed(tileCache_->removeObstacle(obstacle->obstacleId_)))
         if (dtStatusFailed(tileCache_->removeObstacle(obstacle->obstacleId_)))
         {
         {
             LOGERROR("Failed to remove obstacle");
             LOGERROR("Failed to remove obstacle");