From a6864e69a9eda8a902dfaa9712093206f17e508d Mon Sep 17 00:00:00 2001 From: Wolfgang Becker Date: Fri, 30 Jun 2006 22:31:42 +0000 Subject: [PATCH] Ambient sound loops again, Part III. A more global solution of the problem. SVN-Revision: 3816 --- src/audio/dummy_sound_source.cpp | 4 ---- src/audio/sound_manager.cpp | 28 ++++++++++++++++++++++++++++ src/audio/sound_manager.hpp | 12 ++++++++++++ src/audio/sound_source.hpp | 1 - src/audio/stream_sound_source.cpp | 4 ++++ src/object/ambient_sound.cpp | 4 ---- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/audio/dummy_sound_source.cpp b/src/audio/dummy_sound_source.cpp index 4e4d99981..0ca6392ff 100644 --- a/src/audio/dummy_sound_source.cpp +++ b/src/audio/dummy_sound_source.cpp @@ -43,10 +43,6 @@ public: return is_playing; } - virtual void update() - { - } - virtual void set_looping(bool ) { } diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index cc10db7ce..3976eb6b5 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -200,6 +200,27 @@ SoundManager::manage_source(SoundSource* source) } } +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) { @@ -322,6 +343,13 @@ SoundManager::update() 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 diff --git a/src/audio/sound_manager.hpp b/src/audio/sound_manager.hpp index a715d9976..153bf3643 100644 --- a/src/audio/sound_manager.hpp +++ b/src/audio/sound_manager.hpp @@ -74,6 +74,15 @@ public: } 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; @@ -95,6 +104,9 @@ private: typedef std::vector SoundSources; SoundSources sources; + typedef std::vector StreamSoundSources; + StreamSoundSources update_list; + StreamSoundSource* music_source; bool music_enabled; diff --git a/src/audio/sound_source.hpp b/src/audio/sound_source.hpp index 75469c3e9..3824c3c1d 100644 --- a/src/audio/sound_source.hpp +++ b/src/audio/sound_source.hpp @@ -34,7 +34,6 @@ public: virtual void play() = 0; virtual void stop() = 0; - virtual void update() = 0; virtual bool playing() = 0; virtual void set_looping(bool looping) = 0; diff --git a/src/audio/stream_sound_source.cpp b/src/audio/stream_sound_source.cpp index 0cf75b234..3569ecdee 100644 --- a/src/audio/stream_sound_source.cpp +++ b/src/audio/stream_sound_source.cpp @@ -33,10 +33,14 @@ StreamSoundSource::StreamSoundSource() { 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); diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index 1287391b7..6893054e7 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -197,10 +197,6 @@ AmbientSound::update(float deltat) // if (latency>0.001/distance_factor) // latency= - - if( sound_source != NULL ){ - sound_source->update(); - } } void -- 2.11.0