]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Tweak ODGauge usage, fix multiple instances of NavDisplay or wxRadar.
[flightgear.git] / src / Main / main.cxx
index 1cfdd7dbfe3489bd3c8643d21ea068077fa1fd3b..5535060d557180964e19f2df109d27441868cc9c 100644 (file)
@@ -93,42 +93,40 @@ using std::cerr;
 // splash screen up and running right away.
 int idle_state = 0;
 
-
-void fgInitSoundManager();
-void fgSetNewSoundDevice(const char *);
-
 // The atexit() function handler should know when the graphical subsystem
 // is initialized.
 extern int _bootstrap_OSInit;
 
-// What should we do when we have nothing else to do?  Let's get ready
-// for the next move and update the display?
-static void fgMainLoop( void )
+
+void fgInitSoundManager()
 {
-    static SGPropertyNode_ptr frame_signal
-        = fgGetNode("/sim/signals/frame", true);
+    SGSoundMgr *smgr = globals->get_soundmgr();
 
-    frame_signal->fireValueChanged();
-    
-    SG_LOG( SG_GENERAL, SG_DEBUG, "Running Main Loop");
-    SG_LOG( SG_GENERAL, SG_DEBUG, "======= ==== ====");
-    
-    
-  // update "time"
-    double sim_dt, real_dt;
-    TimeManager* timeMgr = (TimeManager*) globals->get_subsystem("time");
-    // compute simulated time (allowing for pause, warp, etc) and
-    // real elapsed time
-    timeMgr->computeTimeDeltas(sim_dt, real_dt);
+    smgr->bind();
+    smgr->init(fgGetString("/sim/sound/device-name", NULL));
 
-    // update magvar model
-    globals->get_mag()->update( globals->get_aircraft_position(),
-                                globals->get_time_params()->getJD() );
+    vector <const char*>devices = smgr->get_available_devices();
+    for (unsigned int i=0; i<devices.size(); i++) {
+        SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true);
+        p->setStringValue(devices[i]);
+    }
+    devices.clear();
+}
 
-    globals->get_subsystem_mgr()->update(sim_dt);
+void fgSetNewSoundDevice(const char *device)
+{
+    SGSoundMgr *smgr = globals->get_soundmgr();
+    smgr->suspend();
+    smgr->stop();
+    smgr->init(device);
+    smgr->resume();
+}
 
-    // Update the sound manager last so it can use the CPU while the GPU
-    // is processing the scenery (doubled the frame-rate for me) -EMH-
+// Update sound manager state (init/suspend/resume) and propagate property values,
+// since the sound manager doesn't read any properties itself.
+// Actual sound update is triggered by the subsystem manager.
+static void fgUpdateSound(double dt)
+{
 #ifdef ENABLE_AUDIO_SUPPORT
     static bool smgr_init = true;
     static SGPropertyNode *sound_working = fgGetNode("/sim/sound/working");
@@ -142,7 +140,7 @@ static void fgMainLoop( void )
         static SGSoundMgr *smgr = globals->get_soundmgr();
         static bool smgr_enabled = true;
 
-        if (sound_working->getBoolValue() == false) {  // request to reinit
+        if (sound_working->getBoolValue() == false) {   // request to reinit
            smgr->reinit();
            smgr->resume();
            sound_working->setBoolValue(true);
@@ -161,14 +159,17 @@ static void fgMainLoop( void )
         if (smgr_enabled == true) {
             static SGPropertyNode *volume = fgGetNode("/sim/sound/volume");
             smgr->set_volume(volume->getFloatValue());
-            smgr->update(sim_dt);
         }
     }
 #endif
+}
 
-    // END Tile Manager updates
-    bool scenery_loaded = fgGetBool("sim/sceneryloaded");
-    if (!scenery_loaded)
+static void fgLoadInitialScenery()
+{
+    static SGPropertyNode_ptr scenery_loaded
+        = fgGetNode("sim/sceneryloaded", true);
+
+    if (!scenery_loaded->getBoolValue())
     {
         if (globals->get_tile_mgr()->isSceneryLoaded()
              && fgGetBool("sim/fdm-initialized")) {
@@ -187,33 +188,43 @@ static void fgMainLoop( void )
             SGTimeStamp::sleepForMSec(500);
         }
     }
-
-    simgear::AtomicChangeListener::fireChangeListeners();
-
-    SG_LOG( SG_GENERAL, SG_DEBUG, "" );
 }
 
-void fgInitSoundManager()
+// What should we do when we have nothing else to do?  Let's get ready
+// for the next move and update the display?
+static void fgMainLoop( void )
 {
-    SGSoundMgr *smgr = globals->get_soundmgr();
+    static SGPropertyNode_ptr frame_signal
+        = fgGetNode("/sim/signals/frame", true);
 
-    smgr->bind();
-    smgr->init(fgGetString("/sim/sound/device-name", NULL));
+    frame_signal->fireValueChanged();
 
-    vector <const char*>devices = smgr->get_available_devices();
-    for (unsigned int i=0; i<devices.size(); i++) {
-        SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true);
-        p->setStringValue(devices[i]);
-    }
-    devices.clear();
-}
+    SG_LOG( SG_GENERAL, SG_DEBUG, "Running Main Loop");
+    SG_LOG( SG_GENERAL, SG_DEBUG, "======= ==== ====");
 
-void fgSetNewSoundDevice(const char *device)
-{
-    globals->get_soundmgr()->suspend();
-    globals->get_soundmgr()->stop();
-    globals->get_soundmgr()->init(device);
-    globals->get_soundmgr()->resume();
+    // compute simulated time (allowing for pause, warp, etc) and
+    // real elapsed time
+    double sim_dt, real_dt;
+    TimeManager* timeMgr = (TimeManager*) globals->get_subsystem("time");
+    timeMgr->computeTimeDeltas(sim_dt, real_dt);
+
+    // update magvar model
+    globals->get_mag()->update( globals->get_aircraft_position(),
+                                globals->get_time_params()->getJD() );
+
+    // Propagate sound manager properties (note: actual update is triggered
+    // by the subsystem manager).
+    fgUpdateSound(sim_dt);
+
+    // update all subsystems
+    globals->get_subsystem_mgr()->update(sim_dt);
+
+    // END Tile Manager updates
+    fgLoadInitialScenery();
+
+    simgear::AtomicChangeListener::fireChangeListeners();
+
+    SG_LOG( SG_GENERAL, SG_DEBUG, "" );
 }
 
 // Operation for querying OpenGL parameters. This must be done in a
@@ -248,19 +259,6 @@ struct GeneralInitOperation : public GraphicsContextOperation
     }
 };
 
-
-osg::Node* load_panel(SGPropertyNode *n)
-{
-    osg::Geode* geode = new osg::Geode;
-    geode->addDrawable(new FGPanelNode(n));
-    return geode;
-}
-
-SGPath resolve_path(const std::string& s)
-{
-  return globals->resolve_maybe_aircraft_path(s);
-}
-
 }
 
 // This is the top level master main function that is registered as
@@ -338,7 +336,7 @@ static void fgIdleFunction ( void ) {
         ////////////////////////////////////////////////////////////////////
         globals->set_matlib( new SGMaterialLib );
         simgear::SGModelLib::init(globals->get_fg_root(), globals->get_props());
-        simgear::SGModelLib::setPanelFunc(load_panel);
+        simgear::SGModelLib::setPanelFunc(FGPanelNode::load);
 
         ////////////////////////////////////////////////////////////////////
         // Initialize the TG scenery subsystem.
@@ -376,9 +374,6 @@ static void fgIdleFunction ( void ) {
                                    fgGetDouble("/position/altitude-ft")
                                    * SG_FEET_TO_METER,
                                    globals->get_time_params()->getJD() );
-        double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
-        fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
-        fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var);
 
         fgSplashProgress("initializing subsystems");
 
@@ -403,7 +398,11 @@ static void fgIdleFunction ( void ) {
             string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
 # endif
 
-            system ( command.c_str() );
+            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