changeset 500:5e6ff32a46fb

Added listener position to the soundmanager.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 14 May 2010 20:28:05 +0000
parents 3dff106b945b
children 6614a5446352
files demos/shooter/scripts/scene.py demos/shooter/scripts/weapons.py engine/python/fife/extensions/soundmanager.py
diffstat 3 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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))
 		
--- 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):
--- 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']