]> git.mxchange.org Git - flightgear.git/commitdiff
Erik Hofman:
authorcurt <curt>
Tue, 4 Jun 2002 16:27:20 +0000 (16:27 +0000)
committercurt <curt>
Tue, 4 Jun 2002 16:27:20 +0000 (16:27 +0000)
* Small updates and fixes
* Add random as an internal ( <intenral>random</internal> is now possible)

docs-mini/README.xmlsound
src/Sound/fg_sound.cxx
src/Sound/fg_sound.hxx

index c8ed950cf2efc990aa805b042f66ac36f6930c1d..165197768c9b7d07725024e11dd715a5ea3e0a1e 100644 (file)
@@ -166,6 +166,8 @@ Configuration description:
        dt_play:        the number of seconds since the sound started playing.
 
        dt_stop:        the number of seconds after the sound has stopped.
+
+       random:         a random number between 0.0 and 1.0
  
      <type>
        Defines the function that should be used upon the property
index 728a3a1aad44a9533ed68b6948f838e1a208c611..ad6bae072992f6b9645542f047a1070e722648d8 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/math/sg_random.h>
 
 #include <Main/fg_props.hxx>
 
@@ -63,6 +64,7 @@ static const struct {
 
 FGSound::FGSound()
   : _sample(NULL),
+    _active(false),
     _condition(NULL),
     _property(NULL),
     _dt_play(0.0),
@@ -135,6 +137,8 @@ FGSound::init(SGPropertyNode *node)
          volume.intern = &_dt_play;
       else if (!strcmp(intern_str, "dt_stop"))
          volume.intern = &_dt_stop;
+      else if (!strcmp(intern_str, "random"))
+         volume.intern = &_random;
 
       if ((volume.factor = kids[i]->getDoubleValue("factor")) != 0.0)
          if (volume.factor < 0.0) {
@@ -259,7 +263,7 @@ FGSound::update (double dt)
 
    if (                                                        // Lisp, anyone?
          (_condition && !_condition->test()) ||
-         (_property && !_condition &&
+         (!_condition && _property &&
             (
                !curr_value ||
                ( (_mode == FGSound::IN_TRANSIT) && (curr_value == _prev_value) )
@@ -268,12 +272,14 @@ FGSound::update (double dt)
       )
    {
 
+      _active = false;
       _dt_stop += dt;
+      _dt_play = 0.0;
+
       if (_sample->is_playing()) {
          SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
                                       << " sec: " << _name );
          _sample->stop( _mgr->get_scheduler() );
-         _dt_play = 0.0;
       }
 
       return;
@@ -284,14 +290,24 @@ FGSound::update (double dt)
    // If the mode is ONCE and the sound is still playing,
    //  we have nothing to do anymore.
    //
-   if (_dt_play && (_mode == FGSound::ONCE))
+   if (_active && (_mode == FGSound::ONCE)) {
+
+      if (!_sample->is_playing()) {
+         _dt_stop += dt;
+         _dt_play = 0.0;
+
+      } else
+         _dt_play += dt;
+
       return;
+   }
 
    //
-   // Cache current value and Update playing time
+   // Update playtime, cache the current value and feed the random number
    //
+    _dt_play += dt;
    _prev_value = curr_value;
-   _dt_play += dt;
+   _random = sg_random();
 
    //
    // Update the volume
@@ -376,9 +392,7 @@ FGSound::update (double dt)
    //
    // Do we need to start playing the sample?
    //
-   if (_dt_stop) {
-
-      _dt_stop = 0.0;
+   if (!_active) {
 
       if (_mode == FGSound::ONCE)
          _sample->play(_mgr->get_scheduler(), false);
@@ -386,8 +400,12 @@ FGSound::update (double dt)
       else
          _sample->play(_mgr->get_scheduler(), true);
 
-      SG_LOG(SG_GENERAL, SG_INFO, "Starting audio playback for: " << _name);
+      SG_LOG(SG_GENERAL, SG_INFO, "Playing audio after " << _dt_stop 
+                                   << " sec: " << _name);
       SG_LOG(SG_GENERAL, SG_BULK,
                          "Playing " << ((_mode == ONCE) ? "once" : "looped"));
+
+      _active = true;
+      _dt_stop = 0.0;
    }
 }
index 6681dc26153a4ca2bf6bcaf464d42f2cb2b0b10c..fb871d2cbfaeb9fdf15130ce6f6a890b495810cb 100644 (file)
@@ -77,9 +77,11 @@ private:
   FGCondition * _condition;
   SGPropertyNode * _property;
 
+  bool _active;
   string _name;
   int _mode;
   double _prev_value;
+  double _random;
   double _dt_play;
   double _dt_stop;