]> git.mxchange.org Git - flightgear.git/commitdiff
Stop AI aircraft's sound when removing
authorThorstenB <brehmt@gmail.com>
Mon, 26 Nov 2012 23:02:28 +0000 (00:02 +0100)
committerThorstenB <brehmt@gmail.com>
Mon, 26 Nov 2012 23:02:28 +0000 (00:02 +0100)
Sound manager keeps a reference to _fx, so reducing its ref-count isn't
enough - it must be removed explicitly.

src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/Model/acmodel.cxx
src/Sound/fg_fx.cxx
src/Sound/fg_fx.hxx

index 79d6cb1483402fec4c8cfd64535e2a8bc3f3ce64..bbc1510bfc4fad1f5998fe8e3bf4310098f4e87c 100644 (file)
@@ -37,7 +37,6 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/model/modellib.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
-#include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/props/props.hxx>
 
@@ -76,7 +75,6 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
     _initialized(false),
     _modeldata(0),
     _fx(0)
-
 {
     tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
     tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
@@ -143,18 +141,7 @@ FGAIBase::~FGAIBase() {
             model_removed->setStringValue(props->getPath());
     }
 
-  // refID=0 is supposedley impossible, refID=1 is the special ai_ac aircaft
-  // representing the current user, in the ATCManager. Maybe both these
-  // tests could die?
-    if (_fx && _refID != 0 && _refID !=  1) {
-        SGSoundMgr *smgr = globals->get_soundmgr();
-        if (smgr) {
-          std::stringstream name;
-          name <<  "aifx:";
-          name << _refID;
-          smgr->remove(name.str());
-        }
-    }
+    removeSoundFx();
 
     if (fp)
         delete fp;
@@ -477,8 +464,18 @@ void FGAIBase::unbind() {
 
     props->setBoolValue("/sim/controls/radar", true);
 
+    removeSoundFx();
+}
+
+void FGAIBase::removeSoundFx() {
     // drop reference to sound effects now
-    _fx = 0;
+    if (_fx)
+    {
+        // must remove explicitly - since the sound manager also keeps a reference
+        _fx->unbind();
+        // now drop last reference - kill the object
+        _fx = 0;
+    }
 }
 
 double FGAIBase::UpdateRadar(FGAIManager* manager) {
index 3a9426140f0d3f6606ce76bb56abfb6af37f12b2..98f889aa593e401018b78c9d8d6196a5fa13dfd0 100644 (file)
@@ -229,6 +229,7 @@ protected:
     double UpdateRadar(FGAIManager* manager);
 
     void removeModel();
+    void removeSoundFx();
 
     static int _newAIModelID();
 
index 41967c6da06adad56c61ff11ebad6bb8151b0e02..b585df0600a1f6454f6bb505980dc117d7ea2614 100644 (file)
@@ -135,7 +135,7 @@ FGAircraftModel::bind ()
 void
 FGAircraftModel::unbind ()
 {
-  // No-op
+  _fx->unbind();
 }
 
 void
index 42b622108aa4f060c09130e78a66304ded142c96..d3a050426b62c903b35a230c72520b2f493ebbc3 100644 (file)
@@ -61,14 +61,13 @@ FGFX::FGFX ( const std::string &refname, SGPropertyNode *props ) :
     _avionics_ext = _props->getNode("sim/sound/avionics/external-view", true);
     _internal = _props->getNode("sim/current-view/internal", true);
 
-    SGSoundMgr *smgr = globals->get_soundmgr();
-    if (!smgr) {
+    _smgr = globals->get_soundmgr();
+    if (!_smgr) {
       return;
     }
   
-    SGSampleGroup::_smgr = smgr;
-    SGSampleGroup::_refname = refname;
-    SGSampleGroup::_smgr->add(this, refname);
+    _refname = refname;
+    _smgr->add(this, refname);
 
     if (!_is_aimodel)
     {
@@ -77,6 +76,13 @@ FGFX::FGFX ( const std::string &refname, SGPropertyNode *props ) :
     }
 }
 
+void FGFX::unbind()
+{
+    if (_smgr)
+    {
+        _smgr->remove(_refname);
+    }
+}
 
 FGFX::~FGFX ()
 {
@@ -147,7 +153,7 @@ FGFX::reinit()
     }
     _sound.clear();
     init();
-};
+}
 
 
 void
index 7d5132dd9e2a9c85a80fc4ba97f423b03ddab104..1f5336e359b1ecc67e8f51fc64a29d9eec9d9d1f 100644 (file)
@@ -55,6 +55,7 @@ public:
     virtual void init ();
     virtual void reinit ();
     virtual void update (double dt);
+            void unbind();
 
 private: