# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1273868885 0 # Node ID 5e6ff32a46fba96add4a4564327ba64d1444df1d # Parent 3dff106b945b98056c59e3c09e56e5da6e099872 Added listener position to the soundmanager. diff -r 3dff106b945b -r 5e6ff32a46fb demos/shooter/scripts/scene.py --- a/demos/shooter/scripts/scene.py Fri May 14 17:37:42 2010 +0000 +++ b/demos/shooter/scripts/scene.py Fri May 14 20:28:05 2010 +0000 @@ -377,6 +377,9 @@ loc.setExactLayerCoordinates(exactloc) self._camera.setLocation(loc) + #update the listener position + self._soundmanager.listenerposition = (exactloc.x, exactloc.y) + topleft = self._camera.toMapCoordinates(fife.ScreenPoint(0,0)) bottomright = self._camera.toMapCoordinates(fife.ScreenPoint(1024,768)) diff -r 3dff106b945b -r 5e6ff32a46fb demos/shooter/scripts/weapons.py --- a/demos/shooter/scripts/weapons.py Fri May 14 17:37:42 2010 +0000 +++ b/demos/shooter/scripts/weapons.py Fri May 14 20:28:05 2010 +0000 @@ -181,6 +181,8 @@ self._lastfired = self._scene.time self._scene.addObjectToScene(pjctl) if self._soundclip: + location = self._ship.location.getExactLayerCoordinates() + self._soundclip.position = (location.x, location.y) self._soundclip.play() class FireBall(Weapon): diff -r 3dff106b945b -r 5e6ff32a46fb engine/python/fife/extensions/soundmanager.py --- a/engine/python/fife/extensions/soundmanager.py Fri May 14 17:37:42 2010 +0000 +++ b/engine/python/fife/extensions/soundmanager.py Fri May 14 20:28:05 2010 +0000 @@ -194,10 +194,13 @@ self._fifesoundmanager.init() # basic rolloff used for positional sounds - self._rolloff = 1.9 + self._rolloff = 1 #A dict of fife emitters self._loadedclips = {} + + #A tuple representing the listener position (x,y) + self._listenerposition = None def createSoundEmitter(self, filename, forceUnique=False, position=None): """ @@ -240,6 +243,7 @@ if position is not None: clip.position = position clip.rolloff = self.rolloff + return clip def playClip(self, clip): @@ -280,7 +284,7 @@ repeat = 1 clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat) - #clip.timer.start() + else: if clip.looping: def real_callback(e, g): @@ -290,17 +294,21 @@ clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain) clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) - #clip.timer.start() - clip.fifeemitter.setGain(float(clip.gain)/255.0) - if clip.position is not None: + + if self.listenerposition and clip.position: # Use 1 as z coordinate, no need to specify it clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) clip.fifeemitter.setRolloff(clip.rolloff) + elif self.listenerposition and not clip.position: + clip.fifeemitter.setPosition(self.listenerposition[0], self.listenerposition[1], 1) + clip.fifeemitter.setRolloff(self.rolloff) + clip.fifeemitter.play() if clip.timer: clip.timer.start() + else: clip = self.createSoundEmitter(clip.name) self.playClip(clip) @@ -344,7 +352,15 @@ def _setRolloff(self, rolloff): self._rolloff = rolloff + + def _getListenerPosition(self): + return self._listenerposition + + def _setListenerPosition(self, position): + self._listenerposition = position + self._fifesoundmanager.setListenerPosition(self._listenerposition[0], self._listenerposition[1], 1) rolloff = property(_getRolloff, _setRolloff) + listenerposition = property(_getListenerPosition, _setListenerPosition) __all__ = ['SoundEmitter','SoundManager']