From: Erik Hofman Date: Thu, 10 Dec 2015 12:24:52 +0000 (+0100) Subject: Read the scenery global scene effects configration file and update them every frame... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c1729253eea6a7917a4067831409a59cc5d24ac8;p=flightgear.git Read the scenery global scene effects configration file and update them every frame. The SceneFX class is not yet registered though. --- diff --git a/src/Sound/scenefx.cxx b/src/Sound/scenefx.cxx index 2a1fbfbc2..beb8c97c3 100644 --- a/src/Sound/scenefx.cxx +++ b/src/Sound/scenefx.cxx @@ -29,15 +29,19 @@ #endif #include +#include #include "scenefx.hxx" #include
#include
+#include #include #include #include +#include + #include #include @@ -50,6 +54,7 @@ typedef boost::shared_ptr FGSceneFXRef; FGSceneFX::FGSceneFX() { + _props = _props = globals->get_props(); _enabled = fgGetNode("/sim/sound/scene/enabled", true); _volume = fgGetNode("/sim/sound/scene/volume", true); _damping = fgGetNode("/sim/sound/model-damping", true); @@ -61,15 +66,20 @@ FGSceneFX::FGSceneFX() .method("damping", &FGSceneFX::model_damping); } -FGSceneFX::~FGSceneFX() +void FGSceneFX::unbind() { + if (_smgr) + { + _smgr->remove(_refname); + } } -void FGSceneFX::unbind() +FGSceneFX::~FGSceneFX() { - if (_smgr) { - _smgr->remove(_refname); + for (unsigned int i = 0; i < _sound.size(); i++ ) { + delete _sound[i]; } + _sound.clear(); } void FGSceneFX::init() @@ -77,10 +87,41 @@ void FGSceneFX::init() if (!_smgr) { return; } + + SGPath path(globals->get_fg_root()); + path.append("Sounds/sounds.xml"); + + SGPropertyNode root; + try { + readProperties(path.str(), &root); + } catch (const sg_exception &) { + SG_LOG(SG_SOUND, SG_ALERT, + "Error reading file '" << path.str() << '\''); + return; + } + + SGPropertyNode *node = root.getNode("fx"); + if(node) { + for (int i = 0; i < node->nChildren(); ++i) { + SGXmlSound *soundfx = new SGXmlSound(); + + try { + soundfx->init( _props, node->getChild(i), this, 0, path.dir() ); + _sound.push_back( soundfx ); + } catch ( sg_exception &e ) { + SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage()); + delete soundfx; + } + } + } } void FGSceneFX::reinit() { + for ( unsigned int i = 0; i < _sound.size(); i++ ) { + delete _sound[i]; + } + _sound.clear(); init(); } @@ -96,6 +137,11 @@ void FGSceneFX::update (double dt) set_volume(_volume->getFloatValue() * fact); resume(); + // update sound effects if not paused + for ( unsigned int i = 0; i < _sound.size(); i++ ) { + _sound[i]->update(dt); + } + SGSampleGroup::update(dt); } else { diff --git a/src/Sound/scenefx.hxx b/src/Sound/scenefx.hxx index 310ecb178..b3d24a04c 100644 --- a/src/Sound/scenefx.hxx +++ b/src/Sound/scenefx.hxx @@ -32,6 +32,8 @@ #define _DEFAULT_MAX_DISTANCE 100000.0 +class SGXmlSound; + /** * Container for FlightGear envirnonmetal sound effects. */ @@ -78,6 +80,9 @@ private: SGPropertyNode_ptr _volume; SGPropertyNode_ptr _damping; // model sound damping + std::vector _sound; + SGPropertyNode_ptr _props; + const char* full_name(const std::string& refname, size_t num); SGSoundSample *find(const std::string& refname, size_t num); };