]> git.mxchange.org Git - simgear.git/commitdiff
Add an out_of_range property to sound samples. If set the sound is set to non playing...
authorErik Hofman <erik@ehofman.com>
Tue, 13 Dec 2011 10:09:12 +0000 (11:09 +0100)
committerErik Hofman <erik@ehofman.com>
Tue, 13 Dec 2011 10:09:12 +0000 (11:09 +0100)
simgear/sound/sample_group.cxx
simgear/sound/sample_openal.cxx
simgear/sound/sample_openal.hxx

index bdc00ee64bb899f4899f34d43427296973b2f1ef..0be6d13d89b12efec1ccb5d4e7be1fafc7277f1a 100644 (file)
@@ -412,10 +412,10 @@ void SGSampleGroup::update_pos_and_orientation() {
         float max2 = sample->get_max_dist() * sample->get_max_dist();
         float dist2 = position[0]*position[0]
                       + position[1]*position[1] + position[2]*position[2];
-        if (sample->is_playing() && (dist2 > max2)) {
-            sample->stop();
-        } else if (!sample->is_playing() && (dist2 < max2)) {
-            sample->play(sample->is_looping());
+        if ((dist2 > max2) && !sample->test_out_of_range()) {
+            sample->set_out_of_range(true);
+        } else if ((dist2 < max2) && sample->test_out_of_range()) {
+            sample->set_out_of_range(false);
         }
     }
 }
index 2029d9ccc80b04d4d2697ba788c04143cb383336..13e27145f418bcac3fc0ee2dc4c7895da7be441e 100644 (file)
@@ -74,6 +74,7 @@ SGSoundSample::SGSoundSample() :
     _playing(false),
     _changed(true),
     _static_changed(true),
+    _out_of_range(false),
     _is_file(false)
 {
 }
@@ -109,6 +110,7 @@ SGSoundSample::SGSoundSample(const char *file, const SGPath& currentDir) :
     _playing(false),
     _changed(true),
     _static_changed(true),
+    _out_of_range(false),
     _is_file(true)
 {
     SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir);
@@ -146,6 +148,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data,
     _playing(false),
     _changed(true),
     _static_changed(true),
+    _out_of_range(false),
     _is_file(false)
 {
     SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" );
@@ -182,6 +185,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
     _playing(false),
     _changed(true),
     _static_changed(true),
+    _out_of_range(false),
     _is_file(false)
 {
     SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" );
index 9e816c21aaf9aed5316003e9f590135829258a3c..a5ad521dc60fff46bba27f0ab67e6b78f03eef15 100644 (file)
@@ -152,6 +152,22 @@ public:
      */
     inline bool is_playing() { return _playing; }
 
+
+    /**
+     * Set this sample to out-of-range (or not) and
+     * Schedule this audio sample to stop (or start) playing.
+     */
+    inline void set_out_of_range(bool oor = true) {
+        _out_of_range = oor; _playing = oor ? false : true; _changed = true;
+    }
+
+    /**
+     * Test if this sample to out-of-range or not.
+     */
+    inline bool test_out_of_range() {
+        return _out_of_range;
+    }
+
     /**
      * Set the data associated with this audio sample
      * @param data Pointer to a memory block containg this audio sample data.
@@ -495,6 +511,7 @@ private:
     bool _playing;
     bool _changed;
     bool _static_changed;
+    bool _out_of_range;
     bool _is_file;
 
     string random_string();