]> git.mxchange.org Git - flightgear.git/commitdiff
Make subsystem init incremental.
authorJames Turner <zakalawe@mac.com>
Tue, 18 Sep 2012 19:29:36 +0000 (20:29 +0100)
committerJames Turner <zakalawe@mac.com>
Tue, 18 Sep 2012 19:29:36 +0000 (20:29 +0100)
(Requires latest SimGear!)

Break fgInitSubsystems into several phases - subsystem creation, then binding and then init. Run init over multiple main-loop iterations so the application stays responsive to GUI/OS events during init.

There should be no behaviour changes due to this, except that during init Windows and OS-X should no longer show the beach ball / 'application not responding feedback', hopefully.

src/Main/fg_init.cxx
src/Main/fg_init.hxx
src/Main/main.cxx

index 82793ac2bbb13af1a544aed4affa779b3d36be61..a5fb21feeba57f1fc4c1c86e4eacec811bae077d 100644 (file)
@@ -1050,9 +1050,9 @@ bool fgInitGeneral() {
 // initialization routines.  If you are adding a subsystem to flight
 // gear, its initialization call should located in this routine.
 // Returns non-zero if a problem encountered.
-bool fgInitSubsystems() {
+void fgCreateSubsystems() {
 
-    SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
+    SG_LOG( SG_GENERAL, SG_INFO, "Creating Subsystems");
     SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
 
     ////////////////////////////////////////////////////////////////////
@@ -1264,14 +1264,13 @@ bool fgInitSubsystems() {
 
     globals->add_subsystem("tile-manager", globals->get_tile_mgr(), 
       SGSubsystemMgr::DISPLAY);
-      
-    ////////////////////////////////////////////////////////////////////
-    // Bind and initialize subsystems.
-    ////////////////////////////////////////////////////////////////////
-
-    globals->get_subsystem_mgr()->bind();
-    globals->get_subsystem_mgr()->init();
+}
 
+void fgPostInitSubsystems()
+{
+    SGTimeStamp st;
+    st.stamp();
+  
     ////////////////////////////////////////////////////////////////////////
     // Initialize the Nasal interpreter.
     // Do this last, so that the loaded scripts see initialized state
@@ -1279,10 +1278,13 @@ bool fgInitSubsystems() {
     FGNasalSys* nasal = new FGNasalSys();
     globals->add_subsystem("nasal", nasal, SGSubsystemMgr::INIT);
     nasal->init();
-
+    SG_LOG(SG_GENERAL, SG_INFO, "Nasal init took:" << st.elapsedMSec());
+  
     // initialize methods that depend on other subsystems.
+    st.stamp();
     globals->get_subsystem_mgr()->postinit();
-
+    SG_LOG(SG_GENERAL, SG_INFO, "Subsystems postinit took:" << st.elapsedMSec());
+  
     ////////////////////////////////////////////////////////////////////
     // TODO FIXME! UGLY KLUDGE!
     ////////////////////////////////////////////////////////////////////
@@ -1318,8 +1320,6 @@ bool fgInitSubsystems() {
                                 // Save the initial state for future
                                 // reference.
     globals->saveInitialState();
-    
-    return true;
 }
 
 // Reset: this is what the 'reset' command (and hence, GUI) is attached to
index 021feb8797d90605b343c15194c0b0eed1434a7e..03e12cd325a51653c088f462ac331fd4bea700c5 100644 (file)
@@ -29,7 +29,6 @@
 
 // forward decls
 class SGPropertyNode;
-class SGTime;
 class SGPath;
 
 // Return the current base package version
@@ -52,11 +51,12 @@ bool fgInitNav ();
 bool fgInitGeneral ();
 
 
-// This is the top level init routine which calls all the other
-// initialization routines.  If you are adding a subsystem to flight
-// gear, its initialization call should located in this routine.
-bool fgInitSubsystems();
+// Create all the subsystems needed by the sim
+void fgCreateSubsystems();
 
+// called after the subsystems have been bound and initialised,
+// to peform final init
+void fgPostInitSubsystems();
  
 // Reset: this is what the 'reset' command (and hence, GUI) is attached to
 void fgReInitSubsystems();
index 04e075c8861a4b73660067f14a7e2ba701ee6c3b..b682bafbde7ded7cdf5e31d1880ec1594792bc37 100644 (file)
@@ -181,7 +181,8 @@ static void fgIdleFunction ( void ) {
     // our initializations out of the idle callback so that we can get a
     // splash screen up and running right away.
     static int idle_state = 0;
-
+    static int spin_count = 0;
+  
     static osg::ref_ptr<GeneralInitOperation> genOp;
     if ( idle_state == 0 ) {
         idle_state++;
@@ -265,47 +266,40 @@ static void fgIdleFunction ( void ) {
 
     } else if ( idle_state == 6 ) {
         idle_state++;
-        fgSplashProgress("initializing subsystems");
+        fgSplashProgress("creating subsystems");
 
     } else if ( idle_state == 7 ) {
         idle_state++;
-        // Initialize audio support
-#ifdef ENABLE_AUDIO_SUPPORT
-
-        // Start the intro music
-        if ( fgGetBool("/sim/startup/intro-music") ) {
-            SGPath mp3file( globals->get_fg_root() );
-            mp3file.append( "Sounds/intro.mp3" );
-
-            SG_LOG( SG_GENERAL, SG_INFO,
-                "Starting intro music: " << mp3file.str() );
-
-# if defined( __CYGWIN__ )
-            string command = "start /m `cygpath -w " + mp3file.str() + "`";
-# elif defined( _WIN32 )
-            string command = "start /m " + mp3file.str();
-# else
-            string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
-# endif
-
-            if (0 != system ( command.c_str() ))
-            {
-                SG_LOG( SG_SOUND, SG_WARN,
-                    "Failed to play mp3 file " << mp3file.str() << ". Maybe mp3 player is not installed." );
-            }
-        }
-#endif
-        // This is the top level init routine which calls all the
-        // other subsystem initialization routines.  If you are adding
-        // a subsystem to flightgear, its initialization call should be
-        // located in this routine.
-        if( !fgInitSubsystems()) {
-            SG_LOG( SG_GENERAL, SG_ALERT,
-                "Subsystem initialization failed ..." );
-            exit(-1);
+        SGTimeStamp st;
+        st.stamp();
+        fgCreateSubsystems();
+        SG_LOG(SG_GENERAL, SG_INFO, "Creating subsystems took:" << st.elapsedMSec());
+        fgSplashProgress("binding subsystems");
+      
+    } else if ( idle_state == 8 ) {
+        idle_state++;
+        SGTimeStamp st;
+        st.stamp();
+        globals->get_subsystem_mgr()->bind();
+        SG_LOG(SG_GENERAL, SG_INFO, "Binding subsystems took:" << st.elapsedMSec());
+
+        fgSplashProgress("initing subsystems");
+    } else if ( idle_state == 9 ) {
+        SGSubsystem::InitStatus status = globals->get_subsystem_mgr()->incrementalInit();
+        if ( status == SGSubsystem::INIT_DONE) {
+          ++idle_state;
+          fgSplashProgress("finishing subsystem init");
+        } else {
+          const char* spinChars = "-\\|/";
+          string msg = string("initing subsystems ") + spinChars[spin_count++ % 4];
+          fgSplashProgress(msg.c_str());
         }
-
-        // Torsten Dreyer:
+      
+    } else if ( idle_state == 10 ) {
+        idle_state = 900;
+        fgPostInitSubsystems();
+      
+              // Torsten Dreyer:
         // ugly hack for automatic runway selection on startup based on
         // metar data. Makes startup.nas obsolete and guarantees the same
         // runway selection as for AI traffic. However, this code belongs to
@@ -335,7 +329,7 @@ static void fgIdleFunction ( void ) {
 
         fgSplashProgress("initializing graphics engine");
 
-    } else if ( idle_state == 8 ) {
+    } else if ( idle_state == 900 ) {
         idle_state = 1000;
         
         // setup OpenGL view parameters