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);
}
}
}
_playing(false),
_changed(true),
_static_changed(true),
+ _out_of_range(false),
_is_file(false)
{
}
_playing(false),
_changed(true),
_static_changed(true),
+ _out_of_range(false),
_is_file(true)
{
SGPath p = simgear::ResourceManager::instance()->findPath(file, currentDir);
_playing(false),
_changed(true),
_static_changed(true),
+ _out_of_range(false),
_is_file(false)
{
SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" );
_playing(false),
_changed(true),
_static_changed(true),
+ _out_of_range(false),
_is_file(false)
{
SG_LOG( SG_SOUND, SG_DEBUG, "In memory sounds sample" );
*/
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.
bool _playing;
bool _changed;
bool _static_changed;
+ bool _out_of_range;
bool _is_file;
string random_string();