1 // fg_fx.cxx -- Sound effect management class implementation
3 // Started by David Megginson, October 2001
4 // (Reuses some code from main.cxx, probably by Curtis Olson)
6 // Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #pragma warning (disable: 4786)
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/structure/exception.hxx>
31 # define exception c_exception
33 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/props/props.hxx>
35 #include <simgear/sound/xmlsound.hxx>
37 #include <Main/fg_props.hxx>
56 SGPropertyNode *node = fgGetNode("/sim/sound", true);
59 string path_str = node->getStringValue("path");
60 SGPath path( globals->get_fg_root() );
61 if (path_str.empty()) {
62 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
66 path.append(path_str.c_str());
67 SG_LOG(SG_GENERAL, SG_INFO, "Reading sound " << node->getName()
68 << " from " << path.str());
72 readProperties(path.str(), &root);
73 } catch (const sg_exception &e) {
74 SG_LOG(SG_GENERAL, SG_ALERT,
75 "Incorrect path specified in configuration file");
79 node = root.getNode("fx");
80 for (i = 0; i < node->nChildren(); i++) {
81 SGXmlSound *sound = new SGXmlSound();
83 sound->init(globals->get_props(), node->getChild(i),
84 globals->get_soundmgr(), globals->get_fg_root());
86 _sound.push_back(sound);
108 FGFX::update (double dt)
110 // command sound manger
111 bool pause = fgGetBool("/sim/sound/pause");
112 if ( pause != last_pause ) {
114 globals->get_soundmgr()->pause();
116 globals->get_soundmgr()->resume();
121 double volume = fgGetDouble("/sim/sound/volume");
122 if ( volume != last_volume ) {
123 globals->get_soundmgr()->set_volume( volume );
124 last_volume = volume;
128 // update sound effects if not paused
129 for ( unsigned int i = 0; i < _sound.size(); i++ ) {
130 _sound[i]->update(dt);