From: Erik Hofman Date: Sun, 20 Nov 2011 14:31:58 +0000 (+0100) Subject: Postpone initialization of the avionics soundgroup until avionics are enabled. This... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=04395fa9a5e2e1fe82652666252f597f51de3ebd;p=flightgear.git Postpone initialization of the avionics soundgroup until avionics are enabled. This prevents AI classes from creating new and unnecessary avionics sample groups. --- diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index d8c87f90f..2d7edd550 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -314,7 +314,7 @@ bool FGAIBase::init(bool search_in_AI_path) { // Get the sound-path tag from the configuration file and store it // in the property tree. - string fxpath = props->getStringValue("/sim/sound/path"); + string fxpath = props->getStringValue("sim/sound/path"); if ( !fxpath.empty() ) { props->setStringValue("sim/sound/path", fxpath.c_str()); diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index eac5179ba..7aad56b0b 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -54,8 +54,12 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : SGSampleGroup::_smgr = smgr; SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); - _avionics = _smgr->find("avionics", true); - _avionics->tie_to_listener(); + + if (_avionics_enabled->getBoolValue()) + { + _avionics = _smgr->find("avionics", true); + _avionics->tie_to_listener(); + } } @@ -128,11 +132,18 @@ FGFX::update (double dt) bool active = _avionics_ext->getBoolValue() || _internal->getBoolValue(); - if ( active && _avionics_enabled->getBoolValue() ) { - _avionics->resume(); // no-op if already in resumed state - } else - _avionics->suspend(); - _avionics->set_volume( _avionics_volume->getFloatValue() ); + if (_avionics_enabled->getBoolValue()) { + if (!_avionics) { + _avionics = _smgr->find("avionics", true); + _avionics->tie_to_listener(); + } + + if ( active ) + _avionics->resume(); // no-op if already in resumed state + else + _avionics->suspend(); + _avionics->set_volume( _avionics_volume->getFloatValue() ); + } if ( _enabled->getBoolValue() ) { set_volume( _volume->getDoubleValue() );