]> git.mxchange.org Git - flightgear.git/commitdiff
Add the Sound Manager before any other subsystem that uses it. This makes sure the...
authorehofman <ehofman>
Mon, 5 Oct 2009 09:12:50 +0000 (09:12 +0000)
committerTim Moore <timoore@redhat.com>
Tue, 6 Oct 2009 08:23:03 +0000 (10:23 +0200)
src/ATCDCL/AIPlane.cxx
src/ATCDCL/AIPlane.hxx
src/ATCDCL/ATC.cxx
src/Main/fg_init.cxx
src/Main/fg_props.cxx
src/Main/main.cxx
src/Main/viewmgr.cxx
src/Main/viewmgr.hxx
src/Model/acmodel.cxx

index 1db5820ec2d69cb02364c16de72623baf401d991..f672676eb8ad894e7ee3dd1665b3a1487b66b2b2 100644 (file)
@@ -29,6 +29,8 @@ using std::string;
 
 #include "AIPlane.hxx"
 
+SGSampleGroup *FGAIPlane::_sgr = 0;
+
 FGAIPlane::FGAIPlane() {
        leg = LEG_UNKNOWN;
        tuned_station = NULL;
@@ -47,18 +49,18 @@ FGAIPlane::FGAIPlane() {
        _trackSet = false;
        _tgtRoll = 0.0;
        _rollSuspended = false;
-        _sgr = 0;
+
+       if ( !_sgr ) {
+               SGSoundMgr *smgr;
+               smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+               _sgr = smgr->find("atc", true);
+       }
 }
 
 FGAIPlane::~FGAIPlane() {
 }
 
 void FGAIPlane::Update(double dt) {
-       if (!_sgr) {
-               SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
-               if (smgr) _sgr = smgr->find("atc", true);
-       }
-
        if(_pending) {
                if(tuned_station) {
                        if(tuned_station->GetFreqClear()) {
index aba6e7b7ec5c7297d41850445f2c66f056c53649..e099cdfac1132626d64ab75afd597b6f938dcf70 100644 (file)
@@ -160,7 +160,7 @@ private:
        double _tgtRoll;
        bool _rollSuspended;    // Set true when a derived class has suspended AIPlane's roll control
 
-        SGSampleGroup *_sgr;
+        static SGSampleGroup *_sgr;
 };
 
 #endif  // _FG_AI_PLANE_HXX
index ed62bad032130cd11da1205f2a452846928dcfff..92568edc56725be3de1cc605a47ed24685a6011a 100644 (file)
@@ -56,6 +56,9 @@ FGATC::FGATC() :
        _counter(0.0),
        _max_count(5.0)
 {
+       SGSoundMgr *smgr;
+       smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+       _sgr = smgr->find("atc", true);
 }
 
 FGATC::~FGATC() {
@@ -238,11 +241,6 @@ void FGATC::Render(string& msg, const float volume,
                                new SGSoundSample((unsigned char*) buf.c_str(),  buf.length(), 8000);
                                // TODO - at the moment the volume can't be changed 
                                // after the transmission has started.
-                               if (!_sgr) {
-                                       SGSoundMgr *smgr;
-                                       smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
-                                       _sgr = smgr->find("atc", true);
-                               }
                                simple->set_volume(volume);
                                _sgr->add(simple, refname);
                                _sgr->play(refname, repeating);
index 10bded7bb6b9970fb9dba081d8c6fc3112ed33c6..92d32a1caaf2bc5911bba51edf6b6923574c43db 100644 (file)
@@ -57,6 +57,7 @@
 #include <simgear/misc/interpolator.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/model/particles.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/timing/sg_time.hxx>
 #include <simgear/timing/lowleveltime.h>
 
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Scripting/NasalSys.hxx>
-#include <Sound/fg_fx.hxx>
-#include <Sound/beacon.hxx>
-#include <Sound/morse.hxx>
 #include <Sound/voice.hxx>
 #include <Systems/system_mgr.hxx>
 #include <Time/light.hxx>
 
 using std::string;
 
-class Sound;
-class SGSoundMgr;
 extern const char *default_root;
 float init_volume;
 
@@ -1668,18 +1664,6 @@ bool fgInitSubsystems() {
     globals->add_subsystem("replay", new FGReplay);
 
 
-    ////////////////////////////////////////////////////////////////////
-    // Add Sound Manager.
-    // Put the sound manager last so it can use the CPU while the GPU
-    // is processing the scenery (doubled the frame-rate for me) -EMH-
-    ////////////////////////////////////////////////////////////////////
-#ifdef ENABLE_AUDIO_SUPPORT
-    init_volume = fgGetFloat("/sim/sound/volume");
-    fgSetFloat("/sim/sound/volume", 0.0f);
-
-    globals->add_subsystem("soundmgr", new SGSoundMgr);
-#endif
-
     ////////////////////////////////////////////////////////////////////
     // Bind and initialize subsystems.
     ////////////////////////////////////////////////////////////////////
index e3340b8a42088a6a8da894c173d67ad18c30d879..6a54db66515efc2e9ba5185b9fdd5df2a3db79c7 100644 (file)
@@ -221,7 +221,6 @@ setFreeze (bool f)
 {
     frozen = f;
 
-#if 0
     // Stop sound on a pause
     SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
     if ( smgr != NULL ) {
@@ -231,7 +230,6 @@ setFreeze (bool f)
             smgr->resume();
         }
     }
-#endif
 }
 
 
index 023b4f87f8e3aa9d71809c89067c8b9c8561f18e..390aeb3b8693679db738e19be624e2eee7acd9a4 100644 (file)
@@ -478,14 +478,24 @@ static void fgMainLoop( void ) {
     // update the view angle as late as possible, but before sound calculations
     globals->get_viewmgr()->update(real_delta_time_sec);
 
+    ////////////////////////////////////////////////////////////////////
+    // 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-
+    ////////////////////////////////////////////////////////////////////
+#ifdef ENABLE_AUDIO_SUPPORT
+    static SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    smgr->update_late(delta_time_sec);
+#endif
+
     // END Tile Manager udpates
 
     if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded()
         && cur_fdm_state->get_inited()) {
         fgSetBool("sim/sceneryloaded",true);
         fgSetFloat("/sim/sound/volume", init_volume);
-        SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+#ifdef ENABLE_AUDIO_SUPPORT
         smgr->set_volume(init_volume);
+#endif
     }
 
     fgRequestRedraw();
@@ -623,6 +633,16 @@ static void fgIdleFunction ( void ) {
 
     } else if ( idle_state == 5 ) {
         idle_state++;
+#ifdef ENABLE_AUDIO_SUPPORT
+        ////////////////////////////////////////////////////////////////////
+        // Add the Sound Manager before any other subsystem that uses it.
+        // This makes sure the SoundMgr is available at construction time.
+        ////////////////////////////////////////////////////////////////////
+        init_volume = fgGetFloat("/sim/sound/volume");
+        fgSetFloat("/sim/sound/volume", 0.0f);
+        globals->add_subsystem("soundmgr", new SGSoundMgr);
+#endif
+
         ////////////////////////////////////////////////////////////////////
         // Initialize the 3D aircraft model subsystem (has a dependency on
         // the scenery subsystem.)
index 8f865265c64c1dc8055b3663f27a74d7cbe4259a..20db9476ba6b0660cd263a75cd2f629e594e5ae7 100644 (file)
@@ -43,6 +43,7 @@ FGViewMgr::FGViewMgr( void ) :
   config_list(fgGetNode("/sim", true)->getChildren("view")),
   current(0)
 {
+    smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
 }
 
 // Destructor
@@ -296,15 +297,10 @@ FGViewMgr::update (double dt)
   abs_viewer_position = loop_view->getViewPosition();
 
   // update audio listener values
-  static SGSoundMgr *smgr = 0;
-  if (!smgr) smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
-  if (smgr) {
-    // set the viewer posotion in Cartesian coordinates in meters
-    smgr->set_position(abs_viewer_position);
-    smgr->set_orientation(loop_view->getViewOrientation());
-//TODO: should be in meters per second
-//  smr->set_veloicty(SGVec3f(0,0,0));
-  }
+  // set the viewer posotion in Cartesian coordinates in meters
+  smgr->set_position(abs_viewer_position);
+  smgr->set_orientation(loop_view->getViewOrientation());
+  smgr->set_velocity(SGVec3f(0,0,0)); // TODO: in meters per second
 }
 
 void
index 2955ac845c9af2ab42375775ad859ec8d3fd141e..76ede702eb7ae2420aa4f1117992a594ac3d8f69 100644 (file)
@@ -32,6 +32,7 @@
 
 // forward decls
 class FGViewer;
+class SGSoundMgr;
 typedef SGSharedPtr<FGViewer> FGViewerPtr;
 
 // Define a structure containing view information
@@ -124,6 +125,8 @@ private:
 
     int current;
 
+    SGSoundMgr *smgr;
+
 };
 
 
index 866c09188e7c9e0c3e4e684a601f8064083ce237..f54e4721ecdaa50046d1c705d1328cdff055cb95 100644 (file)
@@ -47,6 +47,10 @@ FGAircraftModel::FGAircraftModel ()
     _speed_east(0),
     _speed_up(0)
 {
+    SGSoundMgr *smgr;
+    smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+    _fx = new FGFX(smgr, "fx");
+    _fx->init();
 }
 
 FGAircraftModel::~FGAircraftModel ()
@@ -119,33 +123,24 @@ FGAircraftModel::update (double dt)
                            _heading->getDoubleValue());
   _aircraft->update();
 
-  if ( !_fx) {
-    SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
-    if (smgr) {
-        _fx = new FGFX(smgr, "fx");
-        _fx->init();
-    }
-  }
-
-  if (_fx) {
-    // Get the Cartesian coordinates in meters
-    SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
-    _fx->set_position( pos );
-
-    SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
-    orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
-                                             _pitch->getDoubleValue(),
-                                             _roll->getDoubleValue());
-    SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
-    _fx->set_orientation( toVec3f(orient) );
+  // update model's sample group values
+  // Get the Cartesian coordinates in meters
+  SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
+  _fx->set_position( pos );
+
+  SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
+  orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
+                                           _pitch->getDoubleValue(),
+                                           _roll->getDoubleValue());
+  SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
+  _fx->set_orientation( toVec3f(orient) );
  
-    SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
-                           _speed_east->getFloatValue(),
-                           _speed_up->getFloatValue());
+  SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
+                         _speed_east->getFloatValue(),
+                         _speed_up->getFloatValue());
 // TODO: rotate to properly align with the model orientation
 
-    _fx->set_velocity( vel*SG_FEET_TO_METER );
-  }
+  _fx->set_velocity( vel*SG_FEET_TO_METER );
 }