X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FSound%2Ffg_fx.cxx;h=ab0ace0a94d059f693996f9e43599904babd21aa;hb=438e365aadc321f70941a31a0b9462b4b0155fd6;hp=8bc493bfae15d61a230eb83b7fa6c874750e7543;hpb=1b080515973ede0e74908888fcaec96bbe519319;p=flightgear.git diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 8bc493bfa..ab0ace0a9 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -39,14 +39,18 @@ #include FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) : - last_pause( true ), - last_volume( 0.0 ), - _pause( fgGetNode("/sim/sound/pause") ), - _volume( fgGetNode("/sim/sound/volume") ) + _enabled( fgGetNode("/sim/sound/effects/enabled", true) ), + _volume( fgGetNode("/sim/sound/effects/volume", true) ), + _avionics_enabled( fgGetNode("/sim/sound/avionics/enabled", true) ), + _avionics_volume( fgGetNode("/sim/sound/avionics/volume", true) ), + _avionics_external( fgGetNode("/sim/sound/avionics/external-view", true) ), + _internal( fgGetNode("/sim/current-view/internal", true) ) { SGSampleGroup::_smgr = smgr; SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); + _avionics = _smgr->find("avionics", true); + _avionics->tie_to_listener(); } @@ -65,13 +69,12 @@ FGFX::init() SGPropertyNode *node = fgGetNode("/sim/sound", true); string path_str = node->getStringValue("path"); - SGPath path( globals->get_fg_root() ); if (path_str.empty()) { SG_LOG(SG_GENERAL, SG_ALERT, "No path in /sim/sound/path"); return; } - - path.append(path_str.c_str()); + + SGPath path = globals->resolve_aircraft_path(path_str); SG_LOG(SG_GENERAL, SG_INFO, "Reading sound " << node->getName() << " from " << path.str()); @@ -91,7 +94,7 @@ FGFX::init() try { sound->init(globals->get_props(), node->getChild(i), this, - globals->get_fg_root()); + _avionics, path.dir()); _sound.push_back(sound); } catch ( sg_exception &e ) { @@ -114,31 +117,28 @@ FGFX::reinit() void FGFX::update (double dt) { - // command sound manger - bool new_pause = _pause->getBoolValue(); - if ( new_pause != last_pause ) { - if ( new_pause ) { - suspend(); - } else { - resume(); - } - last_pause = new_pause; - } + bool active = _avionics_external->getBoolValue() || + _internal->getBoolValue(); - double volume = _volume->getDoubleValue(); - if ( volume != last_volume ) { - set_volume( volume ); - last_volume = volume; - } + if ( active && _avionics_enabled->getBoolValue() ) + _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() ); + resume(); - if ( !new_pause ) { // update sound effects if not paused for ( unsigned int i = 0; i < _sound.size(); i++ ) { _sound[i]->update(dt); } - } - SGSampleGroup::update(dt); + SGSampleGroup::update(dt); + } + else + suspend(); } // end of fg_fx.cxx