]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/fg_fx.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Sound / fg_fx.cxx
index 9a8fe0a6fc9c78da2e6be1fc887fb5ec40c60ce1..de5f4e152bd7882b8a6a7d3333042ebaa27394af 100644 (file)
@@ -17,7 +17,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #pragma warning (disable: 4786)
 #endif
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
 #ifdef __BORLANDC__
 
 
 FGFX::FGFX () :
-    _volume( fgGetNode("/sim/sound/volume") ),
-    _pause( fgGetNode("/sim/sound/pause") ),
     last_pause( true ),
-    last_volume( 0.0 )
+    last_volume( 0.0 ),
+    _pause( fgGetNode("/sim/sound/pause") ),
+    _volume( fgGetNode("/sim/sound/volume") )
 {
 }
 
@@ -70,7 +74,7 @@ FGFX::init()
    string path_str = node->getStringValue("path");
    SGPath path( globals->get_fg_root() );
    if (path_str.empty()) {
-      SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
+      SG_LOG(SG_GENERAL, SG_ALERT, "No path in /sim/sound/path");
       return;
    }
 
@@ -81,9 +85,9 @@ FGFX::init()
    SGPropertyNode root;
    try {
       readProperties(path.str(), &root);
-   } catch (const sg_exception &e) {
+   } catch (const sg_exception &) {
       SG_LOG(SG_GENERAL, SG_ALERT,
-       "Incorrect path specified in configuration file");
+       "Error reading file '" << path.str() << '\'');
       return;
    }
 
@@ -91,10 +95,15 @@ FGFX::init()
    for (i = 0; i < node->nChildren(); i++) {
       SGXmlSound *sound = new SGXmlSound();
 
-      sound->init(globals->get_props(), node->getChild(i),
-                  globals->get_soundmgr(), globals->get_fg_root());
+      try {
+         sound->init(globals->get_props(), node->getChild(i),
+                     globals->get_soundmgr(), globals->get_fg_root());
 
-      _sound.push_back(sound);
+         _sound.push_back(sound);
+      } catch ( sg_io_exception &e ) {
+         SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
+         delete sound;
+      }
    }
 }
 
@@ -120,6 +129,10 @@ FGFX::update (double dt)
 {
     SGSoundMgr *smgr = globals->get_soundmgr();
 
+    if (smgr->is_working() == false) {
+        return;
+    }
+
     // command sound manger
     bool pause = _pause->getBoolValue();
     if ( pause != last_pause ) {
@@ -174,14 +187,17 @@ FGFX::update (double dt)
 void
 FGFX::play_message( SGSoundSample *_sample )
 {
-    _sample->set_volume( 1.0 );
     _samplequeue.push( _sample );
 }
 void
-FGFX::play_message( const string path, const string fname )
+FGFX::play_message( const string path, const string fname, double volume )
 {
+    if (globals->get_soundmgr()->is_working() == false) {
+        return;
+    }
     SGSoundSample *sample;
     sample = new SGSoundSample( path.c_str(), fname.c_str() );
+    sample->set_volume( volume );
     play_message( sample );
 }