]> git.mxchange.org Git - flightgear.git/commitdiff
Initial mode to disable caching of tiles.
authorJames Turner <zakalawe@mac.com>
Fri, 16 May 2014 13:52:24 +0000 (14:52 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 16 May 2014 13:52:24 +0000 (14:52 +0100)
src/Scenery/tilecache.cxx
src/Scenery/tilecache.hxx
src/Scenery/tilemgr.cxx
src/Scenery/tilemgr.hxx

index d25c3878062430f7787ed23cf79ea2d03600bd98..701d1aba43bbe1511e6d1e15cad05c7b5e3c9c44 100644 (file)
@@ -127,6 +127,22 @@ long TileCache::get_drop_tile() {
     return min_index;
 }
 
+long TileCache::get_first_invisible_tile() const
+{
+  const_tile_map_iterator current = tile_cache.begin();
+  const_tile_map_iterator end = tile_cache.end();
+  
+  for ( ; current != end; ++current ) {
+    TileEntry *e = current->second;
+    if (!e->is_current_view())
+    {
+      return current->first;
+    }
+  }
+  
+  return -1; // no expired tile found
+}
+
 
 // Clear all flags indicating tiles belonging to the current view
 void TileCache::clear_current_view()
index a1f43cecf95ac9f6121b1da74c09e4569073c54c..124e074c6151c6e483faab20bb0e654407a101e9 100644 (file)
@@ -73,7 +73,9 @@ public:
     // Return the index of a tile to be dropped from the cache, return -1 if
     // nothing available to be removed.
     long get_drop_tile();
-    
+  
+    long get_first_invisible_tile() const;
+  
     // Clear all flags indicating tiles belonging to the current view
     void clear_current_view();
 
index 54fe7988e30c78dc08d93038d9fbd4f59b94857b..fa8c530b5052b1c4d068136ed93357474ee43240 100644 (file)
@@ -57,25 +57,35 @@ class FGTileMgr::TileManagerListener : public SGPropertyChangeListener
 {
 public:
     TileManagerListener(FGTileMgr* manager) :
-        _manager(manager)
+        _manager(manager),
+        _useVBOsProp(fgGetNode("/sim/rendering/use-vbos", true)),
+        _enableCacheProp(fgGetNode("/sim/tile-cache/enable", true))
     {
-        fgGetNode("/sim/rendering/use-vbos", true)->addChangeListener(this, true);
+        _useVBOsProp->addChangeListener(this, true);
+        _enableCacheProp->addChangeListener(this, true);
     }
     
     ~TileManagerListener()
     {
-        fgGetNode("/sim/rendering/use-vbos")->removeChangeListener(this);
+        _useVBOsProp->removeChangeListener(this);
+        _enableCacheProp->removeChangeListener(this);
     }
     
     virtual void valueChanged(SGPropertyNode* prop)
     {
-        bool useVBOs = prop->getBoolValue();
-        _manager->_options->setPluginStringData("SimGear::USE_VBOS",
+        if (prop == _useVBOsProp) {
+            bool useVBOs = prop->getBoolValue();
+            _manager->_options->setPluginStringData("SimGear::USE_VBOS",
                                                 useVBOs ? "ON" : "OFF");
+        } else if (prop == _enableCacheProp) {
+            _manager->_enableCache = prop->getBoolValue();
+        }
     }
     
 private:
     FGTileMgr* _manager;
+    SGPropertyNode_ptr _useVBOsProp,
+      _enableCacheProp;
 };
 
 FGTileMgr::FGTileMgr():
@@ -89,7 +99,8 @@ FGTileMgr::FGTileMgr():
     _disableNasalHooks(fgGetNode("/sim/temp/disable-scenery-nasal", true)),
     _scenery_loaded(fgGetNode("/sim/sceneryloaded", true)),
     _scenery_override(fgGetNode("/sim/sceneryloaded-override", true)),
-    _pager(FGScenery::getPagerSingleton())
+    _pager(FGScenery::getPagerSingleton()),
+    _enableCache(true)
 {
 }
 
@@ -329,14 +340,24 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
     }
 
     int drop_count = sz - tile_cache.get_max_cache_size();
-    if (( drop_count > 0 )&&
-         ((loading==0)||(drop_count > 10)))
+    bool dropTiles = false;
+    if (_enableCache) {
+      dropTiles = ( drop_count > 0 ) && ((loading==0)||(drop_count > 10));
+    } else {
+      dropTiles = true;
+      drop_count = sz; // no limit on tiles to drop
+    }
+  
+    if (dropTiles)
     {
-        long drop_index = tile_cache.get_drop_tile();
+        long drop_index = _enableCache ? tile_cache.get_drop_tile() :
+                                         tile_cache.get_first_invisible_tile();
         while ( drop_index > -1 )
         {
             // schedule tile for deletion with osg pager
             TileEntry* old = tile_cache.get_tile(drop_index);
+            SG_LOG(SG_TERRAIN, SG_ALERT, "Dropping:" << old->get_tile_bucket());
+
             tile_cache.clear_entry(drop_index);
             
             osg::ref_ptr<osg::Object> subgraph = old->getNode();
@@ -345,13 +366,16 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
             // zeros out subgraph ref_ptr, so subgraph is owned by
             // the pager and will be deleted in the pager thread.
             _pager->queueDeleteRequest(subgraph);
-            
-            if (--drop_count > 0)
+          
+            if (!_enableCache)
+                drop_index = tile_cache.get_first_invisible_tile();
+            // limit tiles dropped to drop_count
+            else if (--drop_count > 0)
                 drop_index = tile_cache.get_drop_tile();
             else
-                drop_index = -1;
+               drop_index = -1;
         }
-    }
+    } // of dropping tiles loop
 }
 
 // given the current lon/lat (in degrees), fill in the array of local
index 6931d4acca956d3145d61b0dcc60f346534f6e1e..c84cbf5058849534bd0641dc768e64ee9259b79a 100644 (file)
@@ -92,6 +92,8 @@ private:
 
     osg::ref_ptr<flightgear::SceneryPager> _pager;
 
+    /// is caching of expired tiles enabled or not?
+    bool _enableCache;
 public:
     FGTileMgr();
     ~FGTileMgr();