mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
fix IndirectInterval not to start/stop sounds repeatedly
This commit is contained in:
parent
11af84dec4
commit
b0e3667dbe
@ -2,9 +2,10 @@
|
||||
|
||||
from PandaModules import *
|
||||
from DirectNotifyGlobal import *
|
||||
import LerpInterval
|
||||
import Interval
|
||||
import LerpBlendHelpers
|
||||
|
||||
class IndirectInterval(LerpInterval.LerpFunctionInterval):
|
||||
class IndirectInterval(Interval.Interval):
|
||||
"""
|
||||
This class can be used to play samples of another interval, so
|
||||
that only a subset of the interval is played, or the time is
|
||||
@ -27,6 +28,9 @@ class IndirectInterval(LerpInterval.LerpFunctionInterval):
|
||||
startT = 0, endT = None, playRate = 1,
|
||||
duration = None, blendType = 'noBlend', name = None):
|
||||
self.interval = interval
|
||||
|
||||
self.startAtStart = (startT == 0)
|
||||
self.endAtEnd = (endT == None or endT == interval.getDuration())
|
||||
|
||||
if endT == None:
|
||||
endT = interval.getDuration()
|
||||
@ -39,10 +43,92 @@ class IndirectInterval(LerpInterval.LerpFunctionInterval):
|
||||
IndirectInterval.indirectIntervalNum)
|
||||
IndirectInterval.indirectIntervalNum += 1
|
||||
|
||||
LerpInterval.LerpFunctionInterval.__init__(
|
||||
self, self.__step, fromData = startT, toData = endT,
|
||||
duration = duration, blendType = blendType, name = name)
|
||||
self.startT = startT
|
||||
self.endT = endT
|
||||
self.deltaT = endT - startT
|
||||
self.blendType = LerpBlendHelpers.getBlend(blendType)
|
||||
|
||||
def __step(self, t):
|
||||
self.interval.setT(t)
|
||||
|
||||
Interval.Interval.__init__(self, name, duration)
|
||||
|
||||
def __calcT(self, t):
|
||||
return self.startT + self.deltaT * self.blendType(t / self.duration)
|
||||
|
||||
def privInitialize(self, t):
|
||||
state = self.interval.getState()
|
||||
if state == CInterval.SInitial or state == CInterval.SFinal:
|
||||
self.interval.privInitialize(self.__calcT(t))
|
||||
else:
|
||||
self.interval.privStep(self.__calcT(t))
|
||||
self.currT = t
|
||||
self.state = CInterval.SStarted
|
||||
self.interval.privPostEvent()
|
||||
|
||||
def privInstant(self):
|
||||
state = self.interval.getState()
|
||||
if (state == CInterval.SInitial or state == CInterval.SFinal) and \
|
||||
self.endAtEnd:
|
||||
self.interval.privInstant()
|
||||
self.currT = self.getDuration()
|
||||
self.interval.privPostEvent()
|
||||
self.intervalDone()
|
||||
else:
|
||||
if state == CInterval.SInitial or state == CInterval.SFinal:
|
||||
self.interval.privInitialize(self.startT)
|
||||
else:
|
||||
self.interval.privStep(self.startT)
|
||||
self.privFinalize()
|
||||
|
||||
def privStep(self, t):
|
||||
self.interval.privStep(self.__calcT(t))
|
||||
self.currT = t
|
||||
self.state = CInterval.SStarted
|
||||
self.interval.privPostEvent()
|
||||
|
||||
def privFinalize(self):
|
||||
if self.endAtEnd:
|
||||
self.interval.privFinalize()
|
||||
else:
|
||||
self.interval.privStep(self.endT)
|
||||
self.interval.privInterrupt()
|
||||
self.currT = self.getDuration()
|
||||
self.state = CInterval.SFinal
|
||||
self.interval.privPostEvent()
|
||||
self.intervalDone()
|
||||
|
||||
def privReverseInitialize(self, t):
|
||||
state = self.interval.getState()
|
||||
if state == CInterval.SInitial or state == CInterval.SFinal:
|
||||
self.interval.privReverseInitialize(self.__calcT(t))
|
||||
else:
|
||||
self.interval.privStep(self.__calcT(t))
|
||||
self.currT = t
|
||||
self.state = CInterval.SStarted
|
||||
self.interval.privPostEvent()
|
||||
|
||||
def privReverseInstant(self):
|
||||
state = self.interval.getState()
|
||||
if (state == CInterval.SInitial or state == CInterval.SFinal) and \
|
||||
self.startAtStart:
|
||||
self.interval.privReverseInstant()
|
||||
self.currT = 0
|
||||
self.interval.privPostEvent()
|
||||
else:
|
||||
if state == CInterval.SInitial or state == CInterval.SFinal:
|
||||
self.interval.privReverseInitialize(self.endT)
|
||||
else:
|
||||
self.interval.privStep(self.endT)
|
||||
self.privReverseFinalize()
|
||||
|
||||
def privReverseFinalize(self):
|
||||
if self.startAtStart:
|
||||
self.interval.privReverseFinalize()
|
||||
else:
|
||||
self.interval.privStep(self.endT)
|
||||
self.interval.privInterrupt()
|
||||
self.currT = 0
|
||||
self.state = CInterval.SInitial
|
||||
self.interval.privPostEvent()
|
||||
|
||||
def privInterrupt(self):
|
||||
self.interval.privInterrupt()
|
||||
self.interval.privPostEvent()
|
||||
|
@ -383,7 +383,7 @@ class LerpFunctionInterval(Interval.Interval):
|
||||
self.function = function
|
||||
self.fromData = fromData
|
||||
self.toData = toData
|
||||
self.blendType = self.getBlend(blendType)
|
||||
self.blendType = LerpBlendHelpers.getBlend(blendType)
|
||||
self.extraArgs = extraArgs
|
||||
# Generate unique name if necessary
|
||||
if (name == None):
|
||||
@ -411,23 +411,6 @@ class LerpFunctionInterval(Interval.Interval):
|
||||
self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))
|
||||
self.state = CInterval.SStarted
|
||||
self.currT = t
|
||||
|
||||
def getBlend(self, blendType):
|
||||
"""__getBlend(self, string)
|
||||
Return the C++ blend class corresponding to blendType string
|
||||
"""
|
||||
# Note, this is temporary until blend functions get exposed
|
||||
if (blendType == "easeIn"):
|
||||
return LerpBlendHelpers.easeIn
|
||||
elif (blendType == "easeOut"):
|
||||
return LerpBlendHelpers.easeOut
|
||||
elif (blendType == "easeInOut"):
|
||||
return LerpBlendHelpers.easeInOut
|
||||
elif (blendType == "noBlend"):
|
||||
return LerpBlendHelpers.noBlend
|
||||
else:
|
||||
raise Exception(
|
||||
'Error: LerpInterval.__getBlend: Unknown blend type')
|
||||
|
||||
# New interface
|
||||
class LerpFunc(LerpFunctionInterval):
|
||||
|
@ -11,3 +11,21 @@ easeOut = EaseOutBlendType()
|
||||
easeInOut = EaseInOutBlendType()
|
||||
|
||||
noBlend = NoBlendType()
|
||||
|
||||
|
||||
def getBlend(blendType):
|
||||
"""__getBlend(string)
|
||||
Return the C++ blend class corresponding to blendType string
|
||||
"""
|
||||
# Note, this is temporary until blend functions get exposed
|
||||
if (blendType == "easeIn"):
|
||||
return easeIn
|
||||
elif (blendType == "easeOut"):
|
||||
return easeOut
|
||||
elif (blendType == "easeInOut"):
|
||||
return easeInOut
|
||||
elif (blendType == "noBlend"):
|
||||
return noBlend
|
||||
else:
|
||||
raise Exception(
|
||||
'Error: LerpInterval.__getBlend: Unknown blend type')
|
||||
|
Loading…
x
Reference in New Issue
Block a user