]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scenery/tilemgr.cxx
Improve error messages for system.fgfsrc removal
[flightgear.git] / src / Scenery / tilemgr.cxx
index fa8c530b5052b1c4d068136ed93357474ee43240..ec3028d3ea2a4e80d17d0ca7a059515c3012df3f 100644 (file)
@@ -59,16 +59,30 @@ public:
     TileManagerListener(FGTileMgr* manager) :
         _manager(manager),
         _useVBOsProp(fgGetNode("/sim/rendering/use-vbos", true)),
-        _enableCacheProp(fgGetNode("/sim/tile-cache/enable", true))
+        _enableCacheProp(fgGetNode("/sim/tile-cache/enable", true)),
+        _pagedLODMaximumProp(fgGetNode("/sim/rendering/max-paged-lod", true))
     {
         _useVBOsProp->addChangeListener(this, true);
+      
         _enableCacheProp->addChangeListener(this, true);
+        if (_enableCacheProp->getType() == simgear::props::NONE) {
+            _enableCacheProp->setBoolValue(true);
+        }
+      
+        if (_pagedLODMaximumProp->getType() == simgear::props::NONE) {
+            // not set, use OSG default / environment value variable
+            osg::ref_ptr<osgViewer::Viewer> viewer(globals->get_renderer()->getViewer());
+            int current = viewer->getDatabasePager()->getTargetMaximumNumberOfPageLOD();
+            _pagedLODMaximumProp->setIntValue(current);
+        }
+        _pagedLODMaximumProp->addChangeListener(this, true);
     }
     
     ~TileManagerListener()
     {
         _useVBOsProp->removeChangeListener(this);
         _enableCacheProp->removeChangeListener(this);
+        _pagedLODMaximumProp->removeChangeListener(this);
     }
     
     virtual void valueChanged(SGPropertyNode* prop)
@@ -79,13 +93,18 @@ public:
                                                 useVBOs ? "ON" : "OFF");
         } else if (prop == _enableCacheProp) {
             _manager->_enableCache = prop->getBoolValue();
+        } else if (prop == _pagedLODMaximumProp) {
+          int v = prop->getIntValue();
+          osg::ref_ptr<osgViewer::Viewer> viewer(globals->get_renderer()->getViewer());
+          viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(v);
         }
     }
     
 private:
     FGTileMgr* _manager;
     SGPropertyNode_ptr _useVBOsProp,
-      _enableCacheProp;
+      _enableCacheProp,
+      _pagedLODMaximumProp;
 };
 
 FGTileMgr::FGTileMgr():
@@ -118,40 +137,48 @@ FGTileMgr::~FGTileMgr()
 
 
 // Initialize the Tile Manager subsystem
-void FGTileMgr::init() {
+void FGTileMgr::init()
+{
+    reinit();
+}
+
+void FGTileMgr::reinit()
+{
     SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." );
+    _terra_sync = static_cast<simgear::SGTerraSync*> (globals->get_subsystem("terrasync"));
 
+  // drops the previous options reference
     _options = new simgear::SGReaderWriterOptions;
     _listener = new TileManagerListener(this);
     
     materialLibChanged();
     _options->setPropertyNode(globals->get_props());
-
+    
     osgDB::FilePathList &fp = _options->getDatabasePathList();
     const string_list &sc = globals->get_fg_scenery();
     fp.clear();
     std::copy(sc.begin(), sc.end(), back_inserter(fp));
     _options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root());
     
-    if (globals->get_subsystem("terrasync")) {
-        _options->setPluginStringData("SimGear::TERRASYNC_ROOT", fgGetString("/sim/terrasync/scenery-dir"));
+    if (_terra_sync) {
+      _options->setPluginStringData("SimGear::TERRASYNC_ROOT", fgGetString("/sim/terrasync/scenery-dir"));
     }
     
     if (!_disableNasalHooks->getBoolValue())
-        _options->setModelData(new FGNasalModelDataProxy);
-
-    reinit();
-}
-
-void FGTileMgr::reinit()
-{
-    _terra_sync = static_cast<simgear::SGTerraSync*> (globals->get_subsystem("terrasync"));
-    
-    // protect against multiple scenery reloads and properly reset flags,
-    // otherwise aircraft fall through the ground while reloading scenery
-    if (!fgGetBool("/sim/sceneryloaded",true))
+      _options->setModelData(new FGNasalModelDataProxy);
+  
+  
+    if (state != Start)
+    {
+      // protect against multiple scenery reloads and properly reset flags,
+      // otherwise aircraft fall through the ground while reloading scenery
+      if (_scenery_loaded->getBoolValue() == false) {
+        SG_LOG( SG_TERRAIN, SG_INFO, "/sim/sceneryloaded already false, avoiding duplicate re-init of tile manager" );
         return;
-    fgSetBool("/sim/sceneryloaded",false);
+      }
+    }
+  
+    _scenery_loaded->setBoolValue(false);
     fgSetDouble("/sim/startup/splash-alpha", 1.0);
     
     materialLibChanged();
@@ -180,7 +207,6 @@ void FGTileMgr::reinit()
 void FGTileMgr::materialLibChanged()
 {
     _options->setMaterialLib(globals->get_matlib());
-    _options->getMaterialLib()->refreshActiveMaterials();
 }
 
 /* schedule a tile for loading, keep request for given amount of time.
@@ -193,6 +219,9 @@ bool FGTileMgr::sched_tile( const SGBucket& b, double priority, bool current_vie
     {
         // create a new entry
         t = new TileEntry( b );
+        SG_LOG( SG_TERRAIN, SG_INFO, "sched_tile: new tile entry for:" << b );
+
+
         // insert the tile into the cache, update will generate load request
         if ( tile_cache.insert_tile( t ) )
         {
@@ -285,7 +314,7 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis)
 }
 
 /**
- * Update the various queues maintained by the tilemagr (private
+ * Update the various queues maintained by the tilemgr (private
  * internal function, do not call directly.)
  */
 void FGTileMgr::update_queues(bool& isDownloadingScenery)
@@ -297,7 +326,6 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
     TileEntry *e;
     int loading=0;
     int sz=0;
-    bool didRefreshMaterialCache = false;
     
     tile_cache.set_current_time( current_time );
     tile_cache.reset_traversal();
@@ -313,11 +341,6 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
             e->prep_ssg_node(vis);
             
             if (!e->is_loaded()) {
-                if (!didRefreshMaterialCache) {
-                    didRefreshMaterialCache = true;
-                    globals->get_matlib()->refreshActiveMaterials();
-                }
-                
                 bool nonExpiredOrCurrent = !e->is_expired(current_time) || e->is_current_view();
                 bool downloading = isTileDirSyncing(e->tileFileName);
                 isDownloadingScenery |= downloading;
@@ -351,12 +374,12 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
     if (dropTiles)
     {
         long drop_index = _enableCache ? tile_cache.get_drop_tile() :
-                                         tile_cache.get_first_invisible_tile();
+                                         tile_cache.get_first_expired_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());
+            SG_LOG(SG_TERRAIN, SG_DEBUG, "Dropping:" << old->get_tile_bucket());
 
             tile_cache.clear_entry(drop_index);
             
@@ -368,7 +391,7 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
             _pager->queueDeleteRequest(subgraph);
           
             if (!_enableCache)
-                drop_index = tile_cache.get_first_invisible_tile();
+                drop_index = tile_cache.get_first_expired_tile();
             // limit tiles dropped to drop_count
             else if (--drop_count > 0)
                 drop_index = tile_cache.get_drop_tile();
@@ -481,8 +504,10 @@ bool FGTileMgr::schedule_scenery(const SGGeod& position, double range_m, double
     SGBucket bucket(position);
     available = sched_tile( bucket, priority, false, duration );
   
-    if ((!available)&&(duration==0.0))
+    if ((!available)&&(duration==0.0)) {
+        SG_LOG( SG_TERRAIN, SG_DEBUG, "schedule_scenery: Scheduling tile at bucket:" << bucket << " return false" );
         return false;
+    }
 
     SGVec3d cartPos = SGVec3d::fromGeod(position);