From 64102d0da9287575d85ccbcdb7ea3f33b74e7693 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sun, 20 Nov 2011 15:03:48 +0100 Subject: [PATCH] Allow for a different property root location besides '/' --- src/Sound/fg_fx.cxx | 24 ++++++++++++++---------- src/Sound/fg_fx.hxx | 5 +++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 376498c7f..eac5179ba 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -39,14 +39,18 @@ #include #include -FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) : +FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : + _props( props ), _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) ) + _volume( fgGetNode("/sim/sound/effects/volume", true) ) { + if (!props) _props = globals->get_props(); + + _avionics_enabled = _props->getNode("sim/sound/avionics/enabled", true); + _avionics_volume = _props->getNode("sim/sound/avionics/volume", true); + _avionics_ext = _props->getNode("sim/sound/avionics/external-view", true); + _internal = _props->getNode("sim/current-view/internal", true); + SGSampleGroup::_smgr = smgr; SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); @@ -67,7 +71,7 @@ FGFX::~FGFX () void FGFX::init() { - SGPropertyNode *node = fgGetNode("/sim/sound", true); + SGPropertyNode *node = _props->getNode("sim/sound", true); string path_str = node->getStringValue("path"); if (path_str.empty()) { @@ -121,12 +125,12 @@ FGFX::reinit() void FGFX::update (double dt) { - bool active = _avionics_external->getBoolValue() || + bool active = _avionics_ext->getBoolValue() || _internal->getBoolValue(); - if ( active && _avionics_enabled->getBoolValue() ) + if ( active && _avionics_enabled->getBoolValue() ) { _avionics->resume(); // no-op if already in resumed state - else + } else _avionics->suspend(); _avionics->set_volume( _avionics_volume->getFloatValue() ); diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 8051ce4aa..a46d8583c 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -49,7 +49,7 @@ class FGFX : public SGSampleGroup public: - FGFX ( SGSoundMgr *smgr, const string &refname ); + FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props = 0 ); virtual ~FGFX (); virtual void init (); @@ -61,11 +61,12 @@ private: SGSharedPtr _avionics; std::vector _sound; + SGPropertyNode_ptr _props; SGPropertyNode_ptr _enabled; SGPropertyNode_ptr _volume; SGPropertyNode_ptr _avionics_enabled; SGPropertyNode_ptr _avionics_volume; - SGPropertyNode_ptr _avionics_external; + SGPropertyNode_ptr _avionics_ext; SGPropertyNode_ptr _internal; };