Add an out_of_range property to sound samples. If set the sound is set to non playing (which allows the OpenAL sound the be free'd)
This commit is contained in:
parent
f377c75dbd
commit
b57b223a59
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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" );
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user