2
0
Эх сурвалжийг харах

*** empty log message ***

Mike Goslin 25 жил өмнө
parent
commit
6c22ca83d0

+ 4 - 40
direct/src/interval/Interval.py

@@ -2,10 +2,6 @@
 
 from DirectObject import *
 
-PREVIOUS_END = 1
-PREVIOUS_START = 2
-TRACK_START = 3
-
 class Interval(DirectObject):
     """Interval class: Base class for timeline functionality"""
 
@@ -13,20 +9,13 @@ class Interval(DirectObject):
     notify = directNotify.newCategory("Interval")
     #notify.setDebug(1)
 
-    PrevEndRelative = 1
-    PrevStartRelative = 2
-    TrackStartRelative = 3
-
     # special methods
     
-    def __init__(self, name, duration, t0=0.0, type=PREVIOUS_END):
-        """__init__(name, duration, t0, type)
+    def __init__(self, name, duration):
+        """__init__(name, duration)
         """
 	self.name = name
 	self.duration = duration
-	assert(t >= 0.0)
-	self.startTime = t0
-	self.type = type
 
     def getName(self):
 	""" getName()
@@ -38,24 +27,7 @@ class Interval(DirectObject):
 	"""
 	return self.duration
 
-    def getStartTime(self):
-	""" getStartTime()
-	"""
-	return self.startTime
-
-    def setStartTime(self, t, rel=PREVIOUS_END):
-	""" setStartTime()
-	"""
-	assert(t >= 0.0)
-	self.startTime = t
-	self.type = rel
-
-    def getType(self):
-	""" getType()
-	"""
-	return self.type
-
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
@@ -67,12 +39,4 @@ class Interval(DirectObject):
 	space = ''
 	for l in range(indent):
 	    space = space + ' '
-	t = 'UNKNOWN'
-	if (self.type == PREVIOUS_END):
-	    t = 'PREVIOUS_END'
-	elif (self.type == PREVIOUS_START):
-	    t = 'PREVIOUS_START'
-	elif (self.type == TRACK_START):
-	    t = 'TRACK_START'
-	print (space + self.name + ' t0: %.2f dur: %.2f %s' % (
-				self.startTime, self.duration, t))
+	print (space + self.name + ' dur: %.2f' % self.duration)

+ 4 - 4
direct/src/interval/IntervalTest.py

@@ -29,17 +29,17 @@ dockLerp = LerpPosHprInterval('lerp', dock, pos, hpr, 5.0)
 # We need the dock's state to be defined before the lerp
 dockPos = PosHprInterval('dockpos', dock, dock.getPos(), dock.getHpr(), 1.0)
 dockUpTime = BOAT_END - dockLerp.getDuration()
-dockLerp.setStartTime(dockUpTime, TRACK_START)
 hpr2 = Vec3(90.0, 90.0, 90.0)
 dockLerp2 = LerpHprInterval('hpr-lerp', dock, hpr2, 3.0)
-dockLerp2.setStartTime(BOAT_START, TRACK_START)
 dockTrack = Track.Track([dockLerp2, dockPos, dockLerp], 'docktrack')
+dockTrack.setIntervalStartTime('lerp', dockUpTime)
+dockTrack.setIntervalStartTime('hpr-lerp', BOAT_START)
 
 # Start the water sound 5 seconds after the boat starts moving
 waterStartTime = BOAT_START + 5.0
-waterSound = SoundInterval('watersound', sound, loop=1)
-waterSound.setStartTime(waterStartTime, TRACK_START)
+waterSound = SoundInterval('watersound', sound)
 soundTrack = Track.Track([waterSound], 'soundtrack')
+soundTrack.setIntervalStartTime('watersound', waterStartTime)
 
 mtrack = MultiTrack.MultiTrack([boatTrack, dockTrack, soundTrack])
 mtrack.printParams()

+ 34 - 31
direct/src/interval/LerpInterval.py

@@ -7,21 +7,18 @@ class LerpInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, duration, functor, t0=0.0, 
-			type=Interval.PREVIOUS_END, blendType='noBlend'):
-        """__init__(name, duration, functor, t0, type, blendType)
+    def __init__(self, name, duration, functor, blendType='noBlend'):
+        """__init__(name, duration, functor, blendType)
         """
 	self.name = name
 	self.duration = duration
-	self.startTime = t0
-	self.type = type
 	self.lerp = Lerp.Lerp(functor, duration, self.__getBlend(blendType))
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	"""
 	assert(t >= 0.0)
-	if (t > self.duration):
+	if (entry == 1) and (t > self.duration):
 	    self.lerp.setT(self.duration)
 	else:
 	    self.lerp.setT(t)
@@ -46,72 +43,78 @@ class LerpInterval(Interval.Interval):
 
 class LerpPosHprInterval(LerpInterval):
 
-    def __init__(self, name, node, pos, hpr, duration, t0=0.0, 
-		type=Interval.PREVIOUS_END, other=None, blendType='noBlend'):
-	""" __init__(name, node, pos, hpr, duration, t0, type, other, 
-					blendType)
+    def __init__(self, name, node, pos, hpr, duration, startPos=None,
+		startHpr=None, other=None, blendType='noBlend'): 
+	""" __init__(name, node, pos, hpr, duration, other, blendType)
 	"""
         import PosHprLerpFunctor
 
 	assert(not node.isEmpty())
         if (other != None):
             # lerp wrt other
-            startPos = node.getPos(other)
-            startHpr = node.getHpr(other)
+	    if (startPos == None):
+            	startPos = node.getPos(other)
+	    if (startHpr == None):
+            	startHpr = node.getHpr(other)
             functor = PosHprLerpFunctor.PosHprLerpFunctor(
                     node, startPos, pos,
                     startHpr, hpr, other)
         else:
-            startPos = node.getPos()
-            startHpr = node.getHpr()
+	    if (startPos == None):
+            	startPos = node.getPos()
+	    if (startHpr == None):
+            	startHpr = node.getHpr()
             functor = PosHprLerpFunctor.PosHprLerpFunctor(
                     node, startPos, pos,
                     startHpr, hpr)
 
-	LerpInterval.__init__(self, name, duration, functor, t0, 
-						type, blendType)
+	LerpInterval.__init__(self, name, duration, functor, blendType)
 
 
 class LerpPosInterval(LerpInterval):
 
-    def __init__(self, name, node, pos, duration, t0=0.0, 
-		type=Interval.PREVIOUS_END, other=None, blendType='noBlend'):
-	""" __init__(name, node, pos, duration, t0, type, other, blendType)
+    def __init__(self, name, node, pos, duration, startPos=None,
+					other=None, blendType='noBlend'):
+	""" __init__(name, node, pos, duration, other, blendType)
 	"""
         import PosLerpFunctor
 
 	assert(not node.isEmpty())
         if (other != None):
             # lerp wrt other
-            startPos = node.getPos(other)
+	    if (startPos == None):
+                startPos = node.getPos(other)
             functor = PosLerpFunctor.PosLerpFunctor(
                     node, startPos, pos, other)
         else:
-            startPos = node.getPos()
+	    if (startPos == None):
+            	startPos = node.getPos()
             functor = PosLerpFunctor.PosLerpFunctor(
                     node, startPos, pos)
 
-	LerpInterval.__init__(self, name, duration, functor, t0, 
-							type, blendType)
+	LerpInterval.__init__(self, name, duration, functor, blendType) 
 
 class LerpHprInterval(LerpInterval):
 
-    def __init__(self, name, node, hpr, duration, t0=0.0, 
-		type=Interval.PREVIOUS_END, other=None, blendType='noBlend'):
-	""" __init__(name, node, hpr, duration, t0, type, other, blendType)
+    def __init__(self, name, node, hpr, duration, startHpr=None,
+					other=None, blendType='noBlend'):
+	""" __init__(name, node, hpr, duration, other, blendType)
 	"""
         import HprLerpFunctor
 
 	assert(not node.isEmpty())
         if (other != None):
             # lerp wrt other
-            startHpr = node.getHpr(other)
+	    if (startHpr == None):
+                startHpr = node.getHpr(other)
             functor = HprLerpFunctor.HprLerpFunctor(
                     node, startHpr, hpr, other)
         else:
-            startHpr = node.getHpr()
+	    if (startHpr == None):
+            	startHpr = node.getHpr()
+	    self.fhpr = startHpr
+	    self.thpr = hpr
             functor = HprLerpFunctor.HprLerpFunctor(
                     node, startHpr, hpr)
 
-	LerpInterval.__init__(self, name, duration, functor, t0, 
-							type, blendType)
+	LerpInterval.__init__(self, name, duration, functor, blendType) 

+ 4 - 7
direct/src/interval/MopathInterval.py

@@ -8,23 +8,20 @@ class MopathInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, mopath, node, t0=0.0, 
-				type=Interval.PREVIOUS_END):
-        """__init__(name, mopath, node, t0, type)
+    def __init__(self, name, mopath, node):
+        """__init__(name, mopath, node)
         """
 	self.name = name
 	self.node = node	
 	self.mopath = mopath 
 	self.duration = self.mopath.getMaxT()
-	self.startTime = t0
-	self.type = type
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
 	assert(t >= 0.0)
-	if (t > self.duration):
+	if (entry == 1) and (t > self.duration):
 	    self.mopath.goTo(self.node, self.duration)
 	else:
 	    self.mopath.goTo(self.node, t)

+ 3 - 5
direct/src/interval/MultiTrack.py

@@ -11,7 +11,7 @@ class MultiTrack(Interval.Interval):
 
     # special methods
     
-    def __init__(self, trackList, name = None):
+    def __init__(self, trackList, name=None):
         """__init__(trackList, name)
         """
 	if (name == None):
@@ -21,8 +21,6 @@ class MultiTrack(Interval.Interval):
 	    self.name = name
 	self.tlist = trackList
 	self.duration = self.getDuration()
-	self.startTime = 0.0
-	self.type = Interval.PREVIOUS_END
 	self.clock = ClockObject.ClockObject.getGlobalClock()
 
     def getDuration(self):
@@ -36,7 +34,7 @@ class MultiTrack(Interval.Interval):
 		duration = dur
 	return duration
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
@@ -44,7 +42,7 @@ class MultiTrack(Interval.Interval):
 	    Interval.notify.warning(
 		'MultiTrack.setT(): t = %f > duration' % t)
 	for track in self.tlist:
-	    track.setT(t)
+	    track.setT(t, entry)
 
     def play(self, t0=0.0, duration=0.0):
 	""" play(t0, duration)

+ 15 - 21
direct/src/interval/PosHprInterval.py

@@ -8,62 +8,56 @@ class PosHprInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, node, pos, hpr, duration, t0=0.0,
-				type=Interval.PREVIOUS_END):
-        """__init__(name, node, pos, hpr, duration, t0, type)
+    def __init__(self, name, node, pos, hpr, duration):
+        """__init__(name, node, pos, hpr, duration)
         """
 	self.name = name
 	self.node = node
 	self.pos = pos
 	self.hpr = hpr
 	self.duration = duration
-	self.startTime = t0
-	self.type = type
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
-	self.node.setPosHpr(self.pos, self.hpr)
+	if (entry == 1):
+	    self.node.setPosHpr(self.pos, self.hpr)
 
 class PosInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, node, pos, duration, t0=0.0,
-				type=Interval.PREVIOUS_END):
-        """__init__(name, node, pos, duration, t0, type)
+    def __init__(self, name, node, pos, duration):
+        """__init__(name, node, pos, duration)
         """
 	self.name = name
 	self.node = node
 	self.pos = pos
 	self.duration = duration
-	self.startTime = t0
-	self.type = type
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
-	self.node.setPos(self.pos)
+	if (entry == 1):
+	    self.node.setPos(self.pos)
 
 class HprInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, node, hpr, duration, t0=0.0,
-				type=Interval.PREVIOUS_END):
-        """__init__(name, node, hpr, duration, t0, type)
+    def __init__(self, name, node, hpr, duration):
+        """__init__(name, node, hpr, duration)
         """
 	self.name = name
 	self.node = node
 	self.hpr = hpr 
 	self.duration = duration
-	self.startTime = t0
-	self.type = type
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
-	self.node.setHpr(self.hpr)
+	if (entry == 1):
+	    self.node.setHpr(self.hpr)

+ 5 - 11
direct/src/interval/SoundInterval.py

@@ -9,9 +9,8 @@ class SoundInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, sound, loop=0, t0=0.0, 
-				type=Interval.PREVIOUS_END):
-        """__init__(name, sound, loop, t0, type)
+    def __init__(self, name, sound, loop=0):
+        """__init__(name, sound, loop)
         """
 	self.name = name
 	self.sound = sound
@@ -22,10 +21,8 @@ class SoundInterval(Interval.Interval):
 	self.duration = 1.0
 	self.loop = loop
 	self.isPlaying = 0
-	self.startTime = t0
-	self.type = type
 
-    def setT(self, t):
+    def setT(self, t, entry=0):
 	""" setT(t)
 	    Go to time t
 	"""
@@ -35,11 +32,8 @@ class SoundInterval(Interval.Interval):
 		self.isPlaying = 0
 	    return
 	assert(t >= 0)
-	if (t == 0):
+	if (entry == 1):
+	    self.isPlaying = 1
 	    AudioManager.play(self.sound)
 	    if (self.loop):
 		AudioManager.setLoop(self.sound, 1)
-	elif (self.loop) and (self.isPlaying == 0):
-	    AudioManager.play(self.sound)
-	    AudioManager.setLoop(self.sound, 1)
-	    self.isPlaying = 1

+ 67 - 25
direct/src/interval/Track.py

@@ -3,6 +3,10 @@
 import Interval
 import types
 
+PREVIOUS_END = 1
+PREVIOUS_START = 2
+TRACK_START = 3
+
 class Track(Interval.Interval):
 
     trackNum = 1
@@ -18,10 +22,14 @@ class Track(Interval.Interval):
 	else:
 	    self.name = name
 
-	self.ilist = intervalList
+	self.__buildIlist(intervalList)
 	self.duration = self.__computeDuration(len(self.ilist))
-	self.startTime = 0.0
-	self.type = Interval.PREVIOUS_END
+	self.currentInterval = None
+
+    def __buildIlist(self, intervalList):
+	self.ilist = []
+	for i in intervalList:
+	    self.ilist.append((i, 0.0, PREVIOUS_END))
 
     def __computeDuration(self, length):
 	""" __computeDuration(length)
@@ -30,16 +38,17 @@ class Track(Interval.Interval):
 	duration = 0.0
 	prev = None
 	for i in self.ilist[0:length]:
-	    type = i.getType()
-	    t0 = i.getStartTime()
+	    ival = i[0]
+	    t0 = i[1]
+	    type = i[2]
 	    assert(t0 >= 0.0)
 	    fillTime = t0 
-	    if (type == Interval.PREVIOUS_END):
+	    if (type == PREVIOUS_END):
 		pass
-	    elif (type == Interval.PREVIOUS_START):
+	    elif (type == PREVIOUS_START):
 		if (prev != None):
 		    fillTime = t0 - prev.getDuration()
-	    elif (type == Interval.TRACK_START):
+	    elif (type == TRACK_START):
 		fillTime = t0 - duration
 	    else:
 		Interval.notify.error(
@@ -47,16 +56,34 @@ class Track(Interval.Interval):
 	    if (fillTime < 0.0):
 		Interval.notify.error(
 			'Track.__computeDuration(): overlap detected')
-	    duration = duration + fillTime + i.getDuration()
-	    prev = i
+	    duration = duration + fillTime + ival.getDuration()
+	    prev = ival
 	return duration
 
+    def setIntervalStartTime(self, name, t0, type=TRACK_START):
+	""" setIntervalStartTime(name, t0, type)
+	"""
+	length = len(self.ilist)
+	found = 0
+	for i in range(length):
+	    if (self.ilist[i][0].getName() == name):
+		newi = (self.ilist[i][0], t0, type)	
+		self.ilist[i] = newi
+		found = 1
+		break;
+	if (found):
+	    self.duration = self.__computeDuration(length)	
+	else:
+	    Interval.notify.warning(
+		'Track.setIntervalStartTime(): no Interval named: %s' % name)
+
     def getIntervalStartTime(self, name):
 	""" getIntervalStartTime(name)
 	"""
 	for i in range(len(self.ilist)):
-	    if (self.ilist[i].getName() == name):	
-		return self.__computeDuration(i+1) - self.ilist[i].getDuration()
+	    if (self.ilist[i][0].getName() == name):	
+		return (self.__computeDuration(i+1) - 
+				self.ilist[i][0].getDuration())
 	Interval.notify.warning(
 		'Track.getIntervalStartTime(): no Interval named: %s' % name)
 	return 0.0
@@ -64,56 +91,71 @@ class Track(Interval.Interval):
     def __getIntervalStartTime(self, interval):
 	""" __getIntervalStartTime(interval)
 	"""
-	return (self.__computeDuration(self.ilist.index(interval)+1) -
-			interval.getDuration())
+	for i in range(len(self.ilist)):
+	    if (self.ilist[i][0] == interval):
+		return (self.__computeDuration(i+1) - interval.getDuration())
+	Interval.notify.warning(
+		'Track.__getIntervalStartTime(): Interval not found')
+	return 0.0
 
     def getIntervalEndTime(self, name):
 	""" getIntervalEndTime(name)
 	"""
 	for i in range(len(self.ilist)):
-	    if (self.ilist[i].getName() == name):	
+	    if (self.ilist[i][0].getName() == name):	
 		return self.__computeDuration(i+1)
 	Interval.notify.warning(
 		'Track.getIntervalEndTime(): no Interval named: %s' % name)
 	return 0.0
 
-    def setT(self, t):
-	""" setT(t)
+    def setT(self, t, entry=0):
+	""" setT(t, entry)
 	    Go to time t
 	"""
+	if (entry == 1):
+	    self.currentInterval = None
 	if (len(self.ilist) == 0):
 	    Interval.notify.warning('Track.setT(): track has no intervals')
 	    return
-	elif (t > self.duration):
+	elif (entry == 1) and (t > self.duration):
 	    # Anything beyond the end of the track is assumed to be the 
 	    # final state of the last Interval on the track
-	    self.ilist[len(self.ilist)-1].setT(t)
+	    self.ilist[len(self.ilist)-1][0].setT(t, entry=1)
 	else:
 	    # Find out which Interval applies
 	    prev = None
 	    for i in self.ilist:
 		# Calculate the track relative start time for the interval
-		t0 = self.__getIntervalStartTime(i)
+		ival = i[0]
+		t0 = self.__getIntervalStartTime(ival)
 
 		# Determine if the Interval is applicable
 		if (t < t0):
 		    if (prev != None):
 			# Gaps between Intervals take the final state of
 			# the previous Interval
-			prev.setT(t)
+			if (self.currentInterval != prev):
+			    prev.setT(t, entry=1)
+			    self.currentInterval = prev
+			else:
+			    prev.setT(t)
 			return
 		    else:
 			#Interval.Interval.notify.warning(
 			#	'Track.setT(): state undefined at t: %f' % t)
 			return
-		elif (t0 <= t) and (t <= t0 + i.getDuration()):
-		    i.setT(t - t0)
+		elif (t0 <= t) and (t <= t0 + ival.getDuration()):
+		    if (self.currentInterval != ival):
+		        ival.setT(t - t0, entry=1)
+			self.currentInterval = ival
+		    else:
+		    	ival.setT(t - t0)
 		    return
-		prev = i
+		prev = ival
 
     def printParams(self, indent=0):
 	""" printParams(indent)
 	"""
 	Interval.Interval.printParams(self, indent)
 	for i in self.ilist:	
-	    i.printParams(indent+1)
+	    i[0].printParams(indent+1)

+ 1 - 4
direct/src/interval/WaitInterval.py

@@ -10,8 +10,7 @@ class Wait(Interval.Interval):
 
     # special methods
     
-    def __init__(self, duration, name=None, t0=0.0,
-				type=Interval.PREVIOUS_END):
+    def __init__(self, duration, name=None):
         """__init__(duration, name, t0, type)
         """
 	if (name == None):
@@ -20,5 +19,3 @@ class Wait(Interval.Interval):
 	else:
 	    self.name = name
 	self.duration = duration 
-	self.startTime = 0.0
-	self.type = type