comparison engine/python/fife/extensions/soundmanager.py @ 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 872a7a94563e
children 99e3ef63495b
comparison
equal deleted inserted replaced
650:51bbda7676f0 651:2851e232a113
92 self._timer = None 92 self._timer = None
93 93
94 self._position = None 94 self._position = None
95 self._rolloff = 0 95 self._rolloff = 0
96 96
97 def __del__(self):
98 self._soundmanager.unregisterClip(self)
99
97 def play(self): 100 def play(self):
98 self._soundmanager.playClip(self) 101 self._soundmanager.playClip(self)
99 102
100 def stop(self): 103 def stop(self):
101 self._soundmanager.stopClip(self) 104 self._soundmanager.stopClip(self)
198 # basic rolloff used for positional sounds 201 # basic rolloff used for positional sounds
199 self._rolloff = 1 202 self._rolloff = 1
200 203
201 #A dict of fife emitters 204 #A dict of fife emitters
202 self._loadedclips = {} 205 self._loadedclips = {}
206
207 #A list of created clips
208 self._soundclips = []
203 209
204 #A tuple representing the listener position (x,y) 210 #A tuple representing the listener position (x,y)
205 self._listenerposition = None 211 self._listenerposition = None
206 212
207 def createSoundEmitter(self, filename, forceUnique=False, position=None): 213 def createSoundEmitter(self, filename, forceUnique=False, position=None):
243 clip.duration = fifeemitter.getDuration() 249 clip.duration = fifeemitter.getDuration()
244 250
245 if position is not None: 251 if position is not None:
246 clip.position = position 252 clip.position = position
247 clip.rolloff = self.rolloff 253 clip.rolloff = self.rolloff
248 254
255 self._soundclips.append(clip)
256
249 return clip 257 return clip
250 258
251 def playClip(self, clip): 259 def playClip(self, clip):
252 """ 260 """
253 Plays a sound clip. 261 Plays a sound clip.
329 337
330 else: 338 else:
331 clip = self.createSoundEmitter(clip.name) 339 clip = self.createSoundEmitter(clip.name)
332 self.playClip(clip) 340 self.playClip(clip)
333 341
342 def unregisterClip(self, clip):
343 self.stopClip(clip)
344
345 if clip in self._soundclips:
346 self._soundclips.remove(clip)
347
334 def stopClip(self, clip): 348 def stopClip(self, clip):
335 """ 349 """
336 Stops playing the sound clip. Note that this will stop all clips that 350 Stops playing the sound clip. Note that this will stop all clips that
337 use the same FIFE emitter. 351 use the same FIFE emitter.
338 352
345 if clip.timer: 359 if clip.timer:
346 clip.timer.stop() 360 clip.timer.stop()
347 clip.timer = None 361 clip.timer = None
348 362
349 def stopAllSounds(self): 363 def stopAllSounds(self):
350 for emitterlist in self._loadedclips.values(): 364 for clip in self._soundclips:
351 for emitter in emitterlist: 365 self.stopClip(clip)
352 emitter.stop()
353 366
354 def destroy(self): 367 def destroy(self):
355 """ 368 """
356 Releases all instances of L{fife.SoundEmitter}. 369 Releases all instances of L{fife.SoundEmitter}.
357 370