]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scenery/tilemgr.cxx
Fix native protocol crashes.
[flightgear.git] / src / Scenery / tilemgr.cxx
index e05133a3eb59b59678dc0f59825bb27c87164606..298b05c50d20bcf5a081ce1356cef564f1f14248 100644 (file)
@@ -41,8 +41,9 @@
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Viewer/renderer.hxx>
-#include <Viewer/viewer.hxx>
+#include <Viewer/splash.hxx>
 #include <Scripting/NasalSys.hxx>
+#include <Scripting/NasalModelData.hxx>
 
 #include "scenery.hxx"
 #include "SceneryPager.hxx"
@@ -61,6 +62,8 @@ FGTileMgr::FGTileMgr():
     _visibilityMeters(fgGetNode("/environment/visibility-m", true)),
     _maxTileRangeM(fgGetNode("/sim/rendering/static-lod/bare", true)),
     _disableNasalHooks(fgGetNode("/sim/temp/disable-scenery-nasal", true)),
+    _scenery_loaded(fgGetNode("/sim/sceneryloaded", true)),
+    _scenery_override(fgGetNode("/sim/sceneryloaded-override", true)),
     _pager(FGScenery::getPagerSingleton())
 {
 }
@@ -102,6 +105,10 @@ void FGTileMgr::refresh_tile(void* tileMgr, long tileIndex)
 
 void FGTileMgr::reinit()
 {
+    _terra_sync = static_cast<simgear::SGTerraSync*> (globals->get_subsystem("terrasync"));
+    if (_terra_sync)
+        _terra_sync->setTileRefreshCb(&refresh_tile, this);
+
     // protect against multiple scenery reloads and properly reset flags,
     // otherwise aircraft fall through the ground while reloading scenery
     if (!fgGetBool("/sim/sceneryloaded",true))
@@ -130,10 +137,6 @@ void FGTileMgr::reinit()
     longitude = latitude = -1000.0;
     scheduled_visibility = 100.0;
 
-    _terra_sync = (simgear::SGTerraSync*) globals->get_subsystem("terrasync");
-    if (_terra_sync)
-        _terra_sync->setTileRefreshCb(&refresh_tile, this);
-
     // force an update now
     update(0.0);
 }
@@ -311,22 +314,43 @@ void FGTileMgr::update_queues()
 // disk.
 void FGTileMgr::update(double)
 {
-    SGVec3d viewPos = globals->get_current_view()->get_view_pos();
     double vis = _visibilityMeters->getDoubleValue();
-    schedule_tiles_at(SGGeod::fromCart(viewPos), vis);
+    schedule_tiles_at(globals->get_view_position(), vis);
 
     update_queues();
+
+    // scenery loading check, triggers after each sim (tile manager) reinit
+    if (!_scenery_loaded->getBoolValue())
+    {
+        bool fdmInited = fgGetBool("sim/fdm-initialized");
+        bool positionFinalized = fgGetBool("sim/position-finalized");
+        bool sceneryOverride = _scenery_override->getBoolValue();
+        
+    // we are done if final position is set and the scenery & FDM are done.
+    // scenery-override can ignore the last two, but not position finalization.
+        if (positionFinalized && (sceneryOverride || (isSceneryLoaded() && fdmInited)))
+        {
+            _scenery_loaded->setBoolValue(true);
+            fgSplashProgress("");
+        }
+        else
+        {
+            fgSplashProgress(positionFinalized ? "loading-scenery" : "finalize-position");
+            // be nice to loader threads while waiting for initial scenery, reduce to 20fps
+            SGTimeStamp::sleepForMSec(50);
+        }
+    }
 }
 
-// schedule tiles for the viewer bucket (FDM/AI/groundcache/... use
-// "schedule_scenery" instead
-int FGTileMgr::schedule_tiles_at(const SGGeod& location, double range_m)
+// schedule tiles for the viewer bucket
+// (FDM/AI/groundcache/... should use "schedule_scenery" instead)
+void FGTileMgr::schedule_tiles_at(const SGGeod& location, double range_m)
 {
     longitude = location.getLongitudeDeg();
     latitude = location.getLatitudeDeg();
 
     // SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for "
-    //         << longitude << " " << latatitude );
+    //         << longitude << " " << latitude );
 
     current_bucket.set_bucket( location );
 
@@ -364,8 +388,6 @@ int FGTileMgr::schedule_tiles_at(const SGGeod& location, double range_m)
         previous_bucket.make_bad();
     }
     last_state = state;
-
-    return 1;
 }
 
 /** Schedules scenery for given position. Load request remains valid for given duration