changeset 651:2851e232a113

* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 14 Oct 2010 15:52:43 +0000
parents 51bbda7676f0
children da9c4cfe8f8e
files demos/shooter/scripts/ships/enemies.py engine/python/fife/extensions/soundmanager.py
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/demos/shooter/scripts/ships/enemies.py	Thu Oct 14 15:32:09 2010 +0000
+++ b/demos/shooter/scripts/ships/enemies.py	Thu Oct 14 15:52:43 2010 +0000
@@ -45,7 +45,7 @@
 		super(BossActionListener, self).onInstanceActionFinished(instance, action)
 
 		if action.getId() == 'explode':
-			self.delayed = fife_timer.delayCall(1000,self._ship.endLevel())
+			self.delayed = fife_timer.delayCall(5000,self._ship.endLevel())
 
 				
 class Saucer1(Ship):
--- a/engine/python/fife/extensions/soundmanager.py	Thu Oct 14 15:32:09 2010 +0000
+++ b/engine/python/fife/extensions/soundmanager.py	Thu Oct 14 15:52:43 2010 +0000
@@ -93,6 +93,9 @@
 
 		self._position = None
 		self._rolloff = 0
+
+	def __del__(self):
+		self._soundmanager.unregisterClip(self)
 
 	def play(self):
 		self._soundmanager.playClip(self)
@@ -201,6 +204,9 @@
 		#A dict of fife emitters
 		self._loadedclips = {}
 		
+		#A list of created clips
+		self._soundclips = []
+		
 		#A tuple representing the listener position (x,y)
 		self._listenerposition = None
 
@@ -245,7 +251,9 @@
 		if position is not None:
 			clip.position = position
 			clip.rolloff = self.rolloff
-			
+		
+		self._soundclips.append(clip)
+		
 		return clip
 
 	def playClip(self, clip):
@@ -330,6 +338,12 @@
 		else:
 			clip = self.createSoundEmitter(clip.name)
 			self.playClip(clip)
+
+	def unregisterClip(self, clip):
+		self.stopClip(clip)
+		
+		if clip in self._soundclips:
+			self._soundclips.remove(clip)
 
 	def stopClip(self, clip):
 		"""
@@ -347,9 +361,8 @@
 			clip.timer = None
 
 	def stopAllSounds(self):
-		for emitterlist in self._loadedclips.values():
-			for emitter in emitterlist:
-				emitter.stop()
+		for clip in self._soundclips:
+			self.stopClip(clip)
 
 	def destroy(self):
 		"""
@@ -364,7 +377,7 @@
 				self._fifesoundmanager.releaseEmitter(emitter.getId())
 				emitter = None
 
-		self._loadedclips.clear()
+		self._loadedclips.clear()
 
	def _getRolloff(self):
 		return self._rolloff