return is_playing;
}
- virtual void update()
- {
- }
-
virtual void set_looping(bool )
{
}
}
}
+void
+SoundManager::register_for_update( StreamSoundSource* sss ){
+ if( sss != NULL ){
+ update_list.push_back( sss );
+ }
+}
+
+void
+SoundManager::remove_from_update( StreamSoundSource* sss ){
+ if( sss != NULL ){
+ StreamSoundSources::iterator i = update_list.begin();
+ while( i != update_list.end() ){
+ if( *i == sss ){
+ i = update_list.erase(i);
+ } else {
+ i++;
+ }
+ }
+ }
+}
+
void
SoundManager::enable_sound(bool enable)
{
alcProcessContext(context);
check_alc_error("Error while processing audio context: ");
}
+
+ //run update() for stream_sound_source
+ StreamSoundSources::iterator s = update_list.begin();
+ while( s != update_list.end() ){
+ (*s)->update();
+ s++;
+ }
}
ALenum
}
void update();
+
+ /*
+ * Tell soundmanager to call update() for stream_sound_source.
+ */
+ void register_for_update( StreamSoundSource* sss );
+ /*
+ * Unsubscribe from updates for stream_sound_source.
+ */
+ void remove_from_update( StreamSoundSource* sss );
private:
friend class OpenALSoundSource;
typedef std::vector<OpenALSoundSource*> SoundSources;
SoundSources sources;
+ typedef std::vector<StreamSoundSource*> StreamSoundSources;
+ StreamSoundSources update_list;
+
StreamSoundSource* music_source;
bool music_enabled;
virtual void play() = 0;
virtual void stop() = 0;
- virtual void update() = 0;
virtual bool playing() = 0;
virtual void set_looping(bool looping) = 0;
{
alGenBuffers(STREAMFRAGMENTS, buffers);
SoundManager::check_al_error("Couldn't allocate audio buffers: ");
+ //add me to update list
+ sound_manager->register_for_update( this );
}
StreamSoundSource::~StreamSoundSource()
{
+ //don't update me any longer
+ sound_manager->remove_from_update( this );
delete file;
stop();
alDeleteBuffers(STREAMFRAGMENTS, buffers);
// if (latency>0.001/distance_factor)
// latency=
-
- if( sound_source != NULL ){
- sound_source->update();
- }
}
void