mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -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 PandaModules import *
|
||||||
from DirectNotifyGlobal 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
|
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
|
that only a subset of the interval is played, or the time is
|
||||||
@ -28,6 +29,9 @@ class IndirectInterval(LerpInterval.LerpFunctionInterval):
|
|||||||
duration = None, blendType = 'noBlend', name = None):
|
duration = None, blendType = 'noBlend', name = None):
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
|
||||||
|
self.startAtStart = (startT == 0)
|
||||||
|
self.endAtEnd = (endT == None or endT == interval.getDuration())
|
||||||
|
|
||||||
if endT == None:
|
if endT == None:
|
||||||
endT = interval.getDuration()
|
endT = interval.getDuration()
|
||||||
|
|
||||||
@ -39,10 +43,92 @@ class IndirectInterval(LerpInterval.LerpFunctionInterval):
|
|||||||
IndirectInterval.indirectIntervalNum)
|
IndirectInterval.indirectIntervalNum)
|
||||||
IndirectInterval.indirectIntervalNum += 1
|
IndirectInterval.indirectIntervalNum += 1
|
||||||
|
|
||||||
LerpInterval.LerpFunctionInterval.__init__(
|
self.startT = startT
|
||||||
self, self.__step, fromData = startT, toData = endT,
|
self.endT = endT
|
||||||
duration = duration, blendType = blendType, name = name)
|
self.deltaT = endT - startT
|
||||||
|
self.blendType = LerpBlendHelpers.getBlend(blendType)
|
||||||
|
|
||||||
def __step(self, t):
|
Interval.Interval.__init__(self, name, duration)
|
||||||
self.interval.setT(t)
|
|
||||||
|
|
||||||
|
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.function = function
|
||||||
self.fromData = fromData
|
self.fromData = fromData
|
||||||
self.toData = toData
|
self.toData = toData
|
||||||
self.blendType = self.getBlend(blendType)
|
self.blendType = LerpBlendHelpers.getBlend(blendType)
|
||||||
self.extraArgs = extraArgs
|
self.extraArgs = extraArgs
|
||||||
# Generate unique name if necessary
|
# Generate unique name if necessary
|
||||||
if (name == None):
|
if (name == None):
|
||||||
@ -412,23 +412,6 @@ class LerpFunctionInterval(Interval.Interval):
|
|||||||
self.state = CInterval.SStarted
|
self.state = CInterval.SStarted
|
||||||
self.currT = t
|
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
|
# New interface
|
||||||
class LerpFunc(LerpFunctionInterval):
|
class LerpFunc(LerpFunctionInterval):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
|
@ -11,3 +11,21 @@ easeOut = EaseOutBlendType()
|
|||||||
easeInOut = EaseInOutBlendType()
|
easeInOut = EaseInOutBlendType()
|
||||||
|
|
||||||
noBlend = NoBlendType()
|
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