Browse Source

woo! make a copy of the cursed set to use durring update. so there!

Cary Sandvig 25 years ago
parent
commit
4b6fc4dba0

+ 4 - 1
panda/src/audio/audio_manager.I

@@ -21,7 +21,10 @@ INLINE void AudioManager::play(AudioSound* sound, float start_time) {
 INLINE void AudioManager::update(void) {
 INLINE void AudioManager::update(void) {
   if (!audio_is_active)
   if (!audio_is_active)
     return;
     return;
-  mutex_lock l(_manager_mutex);
+  {
+    mutex_lock l(_manager_mutex);
+    get_ptr()->copy_loopset();
+  }
   if (_update_func != (UpdateFunc*)0L)
   if (_update_func != (UpdateFunc*)0L)
     (*_update_func)();
     (*_update_func)();
   get_ptr()->ns_update();
   get_ptr()->ns_update();

+ 16 - 3
panda/src/audio/audio_manager.cxx

@@ -15,6 +15,7 @@ mutex AudioManager::_manager_mutex;
 bool* AudioManager::_quit = (bool*)0L;
 bool* AudioManager::_quit = (bool*)0L;
 thread* AudioManager::_spawned = (thread*)0L;
 thread* AudioManager::_spawned = (thread*)0L;
 AudioManager::LoopSet* AudioManager::_loopset = (AudioManager::LoopSet*)0L;
 AudioManager::LoopSet* AudioManager::_loopset = (AudioManager::LoopSet*)0L;
+AudioManager::LoopSet* AudioManager::_loopcopy = (AudioManager::LoopSet*)0L;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: AudioManager::destructor
 //     Function: AudioManager::destructor
@@ -39,6 +40,19 @@ void AudioManager::set_update_func(AudioManager::UpdateFunc* func) {
   _update_func = func;
   _update_func = func;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: AudioManager::copy_loopset
+//       Access: Public, Static
+//  Description: make a copy of the loopset to use for the rest of
+//               update
+////////////////////////////////////////////////////////////////////
+void AudioManager::copy_loopset(void) {
+  if (_loopcopy == (LoopSet*)0L)
+    _loopcopy = new LoopSet;
+  if (_loopset != (LoopSet*)0L)
+    *_loopcopy = *_loopset;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: AudioManager::ns_update
 //     Function: AudioManager::ns_update
 //       Access: Public, Static
 //       Access: Public, Static
@@ -46,10 +60,9 @@ void AudioManager::set_update_func(AudioManager::UpdateFunc* func) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void AudioManager::ns_update(void) {
 void AudioManager::ns_update(void) {
   // handle looping
   // handle looping
-  if (_loopset != (LoopSet*)0L)
-    for (LoopSet::iterator i=_loopset->begin(); i!=_loopset->end();) {
+  if (_loopcopy != (LoopSet*)0L)
+    for (LoopSet::iterator i=_loopcopy->begin(); i!=_loopcopy->end(); ++i) {
       AudioSound* sound = *i;
       AudioSound* sound = *i;
-      ++i;  // because the sound may be removed from the set durring this
       if (sound->status() == AudioSound::READY) {
       if (sound->status() == AudioSound::READY) {
 	if (audio_cat->is_debug())
 	if (audio_cat->is_debug())
 	  audio_cat->debug() << "AudioManager::ns_update looping '"
 	  audio_cat->debug() << "AudioManager::ns_update looping '"

+ 2 - 0
panda/src/audio/audio_manager.h

@@ -18,6 +18,7 @@ class EXPCL_PANDA AudioManager {
 private:
 private:
   INLINE AudioManager(void);
   INLINE AudioManager(void);
 
 
+  void copy_loopset(void);
   void ns_play(AudioSound*, float);
   void ns_play(AudioSound*, float);
   void ns_stop(AudioSound*);
   void ns_stop(AudioSound*);
   void ns_set_loop(AudioSound*, bool);
   void ns_set_loop(AudioSound*, bool);
@@ -41,6 +42,7 @@ private:
   static bool* _quit;
   static bool* _quit;
   static thread* _spawned;
   static thread* _spawned;
   static LoopSet* _loopset;
   static LoopSet* _loopset;
+  static LoopSet* _loopcopy;
 public:
 public:
   virtual ~AudioManager(void);
   virtual ~AudioManager(void);