mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
changed sfx player so that now a cutoff distance can be specified on per sound basis as an optional argument to the player
This commit is contained in:
parent
81735f8dee
commit
2f9f3b1b0b
@ -41,7 +41,7 @@ class SfxPlayer:
|
||||
"""Return the curent cutoff distance."""
|
||||
return self.cutoffDistance
|
||||
|
||||
def getLocalizedVolume(self, node, listenerNode = None):
|
||||
def getLocalizedVolume(self, node, listenerNode = None, cutoff = None):
|
||||
"""
|
||||
Get the volume that a sound should be played at if it is
|
||||
localized at this node. We compute this wrt the camera
|
||||
@ -53,7 +53,7 @@ class SfxPlayer:
|
||||
d = node.getDistance(listenerNode)
|
||||
else:
|
||||
d = node.getDistance(base.cam)
|
||||
if d == None or d > self.cutoffDistance:
|
||||
if d == None or d > cutoff:
|
||||
volume = 0
|
||||
else:
|
||||
if SfxPlayer.UseInverseSquare:
|
||||
@ -61,16 +61,20 @@ class SfxPlayer:
|
||||
volume = min(1, 1 / (sd*sd or 1))
|
||||
#print d, sd, volume
|
||||
else:
|
||||
volume = 1 - (d / (self.cutoffDistance or 1))
|
||||
volume = 1 - (d / (cutoff or 1))
|
||||
#print d, volume
|
||||
|
||||
return volume
|
||||
|
||||
def playSfx(
|
||||
self, sfx, looping = 0, interrupt = 1, volume = None,
|
||||
time = 0.0, node=None, listenerNode = None):
|
||||
time = 0.0, node=None, listenerNode = None, cutoff = None):
|
||||
if sfx:
|
||||
self.setFinalVolume(sfx, node, volume, listenerNode)
|
||||
if not cutoff:
|
||||
cutoff = self.cutoffDistance
|
||||
|
||||
self.setFinalVolume(sfx, node, volume, listenerNode, cutoff)
|
||||
|
||||
# dont start over if it's already playing, unless
|
||||
# "interrupt" was specified
|
||||
if interrupt or (sfx.status() != AudioSound.PLAYING):
|
||||
@ -78,13 +82,13 @@ class SfxPlayer:
|
||||
sfx.setLoop(looping)
|
||||
sfx.play()
|
||||
|
||||
def setFinalVolume(self, sfx, node, volume, listenerNode):
|
||||
def setFinalVolume(self, sfx, node, volume, listenerNode, cutoff = None):
|
||||
"""Calculate the final volume based on all contributed factors."""
|
||||
# If we have either a node or a volume, we need to adjust the sfx
|
||||
# The volume passed in multiplies the distance base volume
|
||||
if node or (volume is not None):
|
||||
if node:
|
||||
finalVolume = self.getLocalizedVolume(node, listenerNode)
|
||||
finalVolume = self.getLocalizedVolume(node, listenerNode, cutoff)
|
||||
else:
|
||||
finalVolume = 1
|
||||
if volume is not None:
|
||||
|
@ -1412,9 +1412,9 @@ class ShowBase(DirectObject.DirectObject):
|
||||
|
||||
def playSfx(
|
||||
self, sfx, looping = 0, interrupt = 1, volume = None,
|
||||
time = 0.0, node = None):
|
||||
time = 0.0, node = None, listener = None, cutoff = None):
|
||||
# This goes through a special player for potential localization
|
||||
return self.sfxPlayer.playSfx(sfx, looping, interrupt, volume, time, node)
|
||||
return self.sfxPlayer.playSfx(sfx, looping, interrupt, volume, time, node, listener, cutoff)
|
||||
|
||||
def playMusic(self, music, looping = 0, interrupt = 1, volume = None, time = 0.0):
|
||||
if music:
|
||||
|
Loading…
x
Reference in New Issue
Block a user