]> git.mxchange.org Git - simgear.git/commitdiff
Free OpenAL sounds of objects that are farther away than the max_distance.
authorErik Hofman <erik@ehofman.com>
Mon, 12 Dec 2011 12:19:43 +0000 (13:19 +0100)
committerErik Hofman <erik@ehofman.com>
Mon, 12 Dec 2011 12:19:43 +0000 (13:19 +0100)
simgear/sound/sample_group.cxx

index e48cd0ab2cc10978f9e12eaf4e8f17f317b5d65f..bdc00ee64bb899f4899f34d43427296973b2f1ef 100644 (file)
@@ -406,6 +406,17 @@ void SGSampleGroup::update_pos_and_orientation() {
         sample->set_rotation( ec2body );
         sample->set_position( position );
         sample->set_velocity( velocity );
+
+        // Test if a sample is farther away than max distance, if so
+        // stop the sound playback and free it's source.
+        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());
+        }
     }
 }