#endif
#include <stdio.h>
+#include <string>
#include "scenefx.hxx"
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
+#include <simgear/props/props_io.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/nasal/cppbind/Ghost.hxx>
+#include <simgear/sound/xmlsound.hxx>
+
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
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);
.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()
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();
}
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 {
#define _DEFAULT_MAX_DISTANCE 100000.0
+class SGXmlSound;
+
/**
* Container for FlightGear envirnonmetal sound effects.
*/
SGPropertyNode_ptr _volume;
SGPropertyNode_ptr _damping; // model sound damping
+ std::vector<SGXmlSound *> _sound;
+ SGPropertyNode_ptr _props;
+
const char* full_name(const std::string& refname, size_t num);
SGSoundSample *find(const std::string& refname, size_t num);
};