Browse Source

*** empty log message ***

Mike Goslin 25 years ago
parent
commit
68d3a0e64f

+ 48 - 0
direct/src/interval/IntervalPlayer.py

@@ -0,0 +1,48 @@
+"""IntervalPlayer module: contains the IntervalPlayer class"""
+
+from DirectObject import *
+
+import Interval
+import Task
+
+class IntervalPlayer(DirectObject):
+    """IntervalPlayer class: Plays back Intervals (like a taskMgr)"""
+
+    # special methods
+    
+    def __init__(self, clock):
+        """__init__(clock)
+        """
+	self.clock = clock
+	self.intervals = []
+
+    def addInterval(self, interval):
+	""" addInterval(interval)
+	"""
+	self.intervals.append(interval)
+
+    def removeInterval(self, interval):
+	""" removeInterval(interval)
+	"""	
+	self.intervals.remove(interval)
+
+    def play(self):
+	""" play()
+	"""
+	self.duration = 0.0
+	for i in self.intervals:
+	    dur = i.getDuration()
+	    if (dur > self.duration):
+		self.duration = dur		
+	self.startT = self.clock.getFrameTime()
+	taskMgr.spawnMethodNamed(self.__playTask, 'interval-player')
+
+    def __playTask(self, task):
+	t = self.clock.getFrameTime()	
+	te = t - self.startT
+	if (te <= self.duration):	
+	    for i in self.intervals:
+	    	i.setT(te)	
+	    return Task.cont
+	else:
+	    return Task.done

+ 23 - 5
direct/src/interval/IntervalTest.py

@@ -1,25 +1,43 @@
 from PandaModules import *
 from PandaModules import *
 from DirectSessionGlobal import *
 from DirectSessionGlobal import *
 from LerpInterval import *
 from LerpInterval import *
+from WaitInterval import *
 
 
 import Mopath
 import Mopath
 import MopathInterval
 import MopathInterval
 import SoundInterval
 import SoundInterval
 import Track
 import Track
+import MultiTrack
+import IntervalPlayer
 
 
 AudioManager.spawnUpdate()
 AudioManager.spawnUpdate()
 
 
-smiley = loader.loadModel('models/directmodels/smiley')
-smiley.reparentTo(render)
+boat = loader.loadModel('models/directmodels/smiley')
+boat.reparentTo(render)
+
+dock = loader.loadModel('models/directmodels/smiley')
+dock.reparentTo(render)
 
 
 mp = Mopath.Mopath()
 mp = Mopath.Mopath()
 mp.loadFile(Filename('phase_6/paths/dd-e-w'))
 mp.loadFile(Filename('phase_6/paths/dd-e-w'))
 
 
-mpi = MopathInterval.MopathInterval('boatpath', mp, smiley)
+boatMopath = MopathInterval.MopathInterval('boatpath', mp, boat)
 
 
 sound = loader.loadSound('phase_6/audio/sfx/SZ_DD_waterlap.mp3')
 sound = loader.loadSound('phase_6/audio/sfx/SZ_DD_waterlap.mp3')
-si = SoundInterval.SoundInterval('watersound', sound)
+waterSound = SoundInterval.SoundInterval('watersound', sound)
 
 
 pos = Point3(0, 0, -5)
 pos = Point3(0, 0, -5)
 hpr = Vec3(0, 0, 0)
 hpr = Vec3(0, 0, 0)
-li = LerpPosHprInterval('lerp', smiley, pos, hpr, 5.0)
+dockLerp = LerpPosHprInterval('lerp', dock, pos, hpr, 5.0)
+
+boatTrack = Track.Track([boatMopath])
+dockWaitTime = boatMopath.getDuration() - dockLerp.getDuration()
+dockTrack = Track.Track([Wait(dockWaitTime), dockLerp])
+postSoundWaitTime = 3.0
+preSoundWaitTime = boatMopath.getDuration() - (waterSound.getDuration() + postSoundWaitTime)
+soundTrack = Track.Track([Wait(preSoundWaitTime), waterSound, Wait(postSoundWaitTime)])
+
+mtrack = MultiTrack.MultiTrack([boatTrack, dockTrack, soundTrack])
+
+player = IntervalPlayer.IntervalPlayer(globalClock)
+player.addInterval(mtrack)

+ 14 - 7
direct/src/interval/MultiTrack.py

@@ -5,24 +5,31 @@ import Track
 
 
 class MultiTrack(Interval.Interval):
 class MultiTrack(Interval.Interval):
 
 
+    multiTrackNum = 1
+
     # special methods
     # special methods
     
     
-    def __init__(self, name, trackList):
-        """__init__(name, trackList)
+    def __init__(self, trackList, name = None):
+        """__init__(trackList, name)
         """
         """
-	self.name = name
+	if (name == None):
+	    self.name = 'MultiTrack-%d' % self.multiTrackNum
+	    self.multiTrackNum = self.multiTrackNum + 1
+	else:
+	    self.name = name
 	self.tlist = trackList
 	self.tlist = trackList
 	self.getDuration()
 	self.getDuration()
 
 
     def getDuration(self):
     def getDuration(self):
 	""" getDuration()
 	""" getDuration()
 	"""
 	"""
-	if (len(self.tlist == 0):
-	    Interval.notify.warning('MultiTrack.getDuration(): no Tracks')
-	    return 0.0
+	#if (len(self.tlist == 0)):
+	#    Interval.notify.warning('MultiTrack.getDuration(): no Tracks')
+	#    return 0.0
 	self.duration = self.tlist[0].getDuration()
 	self.duration = self.tlist[0].getDuration()
 	for t in self.tlist:
 	for t in self.tlist:
-	    assert(self.duration = t.getDuration())
+	    if (self.duration != t.getDuration()):
+		Interval.Interval.notify.warning('MultiTrack.getDuration(): tracks not all same duration')
 	return self.duration
 	return self.duration
 
 
     def setT(self, t):
     def setT(self, t):

+ 27 - 0
direct/src/interval/PosHprInterval.py

@@ -0,0 +1,27 @@
+"""PosHprInterval module: contains the PosHprInterval class"""
+
+from PandaModules import *
+
+import Interval
+
+class PosHprInterval(Interval.Interval):
+
+    # special methods
+    
+    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
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	if (t > self.duration):
+	    return
+	assert(t >= 0)
+	self.node.setPosHpr(self.pos, self.hpr)

+ 12 - 7
direct/src/interval/Track.py

@@ -4,25 +4,30 @@ import Interval
 
 
 class Track(Interval.Interval):
 class Track(Interval.Interval):
 
 
+    trackNum = 1
+
     # special methods
     # special methods
     
     
-    def __init__(self, name, intervalList):
-        """__init__(name, intervalList)
+    def __init__(self, intervalList, name = None):
+        """__init__(intervalList, name)
         """
         """
-	self.name = name
+	if (name == None):
+	    self.name = 'Track-%d' % self.trackNum
+	    self.trackNum = self.trackNum + 1
+	else:
+	    self.name = name
 	self.ilist = intervalList
 	self.ilist = intervalList
 	self.dlist = []
 	self.dlist = []
-	self.getDuration()
+	self.computeDuration()
 
 
-    def getDuration(self):
-	""" getDuration()
+    def computeDuration(self):
+	""" computeDuration()
 	"""
 	"""
 	self.duration = 0.0
 	self.duration = 0.0
 	for i in self.ilist:
 	for i in self.ilist:
 	    dur = i.getDuration()
 	    dur = i.getDuration()
 	    self.duration = self.duration + dur
 	    self.duration = self.duration + dur
 	    self.dlist.append(dur)
 	    self.dlist.append(dur)
-	return self.duration
 
 
     def getStartTimeOf(self, name):
     def getStartTimeOf(self, name):
 	""" getStartTimeOf(name)
 	""" getStartTimeOf(name)

+ 21 - 0
direct/src/interval/WaitInterval.py

@@ -0,0 +1,21 @@
+"""WaitInterval module: contains the Wait class"""
+
+from PandaModules import *
+
+import Interval
+
+class Wait(Interval.Interval):
+
+    waitNum = 1 
+
+    # special methods
+    
+    def __init__(self, duration, name = None):
+        """__init__(duration, name)
+        """
+	if (name == None):
+	    self.name = 'wait-%d' % self.waitNum
+	    self.waitNum = self.waitNum + 1
+	else:
+	    self.name = name
+	self.duration = duration