#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>
_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;
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;
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) {
_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)
{
}
}
+void FGFX::unbind()
+{
+ if (_smgr)
+ {
+ _smgr->remove(_refname);
+ }
+}
FGFX::~FGFX ()
{
}
_sound.clear();
init();
-};
+}
void