From 68d3a0e64f4e2d43fff01bb959ef86248df1cb8a Mon Sep 17 00:00:00 2001 From: Mike Goslin Date: Mon, 26 Feb 2001 23:10:25 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/interval/IntervalPlayer.py | 48 +++++++++++++++++++++++++++ direct/src/interval/IntervalTest.py | 28 +++++++++++++--- direct/src/interval/MultiTrack.py | 21 ++++++++---- direct/src/interval/PosHprInterval.py | 27 +++++++++++++++ direct/src/interval/Track.py | 19 +++++++---- direct/src/interval/WaitInterval.py | 21 ++++++++++++ 6 files changed, 145 insertions(+), 19 deletions(-) create mode 100644 direct/src/interval/IntervalPlayer.py create mode 100644 direct/src/interval/PosHprInterval.py create mode 100644 direct/src/interval/WaitInterval.py diff --git a/direct/src/interval/IntervalPlayer.py b/direct/src/interval/IntervalPlayer.py new file mode 100644 index 0000000000..56477fc95e --- /dev/null +++ b/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 diff --git a/direct/src/interval/IntervalTest.py b/direct/src/interval/IntervalTest.py index f05000d129..32b5b98c70 100644 --- a/direct/src/interval/IntervalTest.py +++ b/direct/src/interval/IntervalTest.py @@ -1,25 +1,43 @@ from PandaModules import * from DirectSessionGlobal import * from LerpInterval import * +from WaitInterval import * import Mopath import MopathInterval import SoundInterval import Track +import MultiTrack +import IntervalPlayer 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.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') -si = SoundInterval.SoundInterval('watersound', sound) +waterSound = SoundInterval.SoundInterval('watersound', sound) pos = Point3(0, 0, -5) 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) diff --git a/direct/src/interval/MultiTrack.py b/direct/src/interval/MultiTrack.py index c9f255d791..4d10732bc7 100644 --- a/direct/src/interval/MultiTrack.py +++ b/direct/src/interval/MultiTrack.py @@ -5,24 +5,31 @@ import Track class MultiTrack(Interval.Interval): + multiTrackNum = 1 + # 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.getDuration() def getDuration(self): """ 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() 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 def setT(self, t): diff --git a/direct/src/interval/PosHprInterval.py b/direct/src/interval/PosHprInterval.py new file mode 100644 index 0000000000..52948e88f4 --- /dev/null +++ b/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) diff --git a/direct/src/interval/Track.py b/direct/src/interval/Track.py index 440c8fef18..16e2134bd6 100644 --- a/direct/src/interval/Track.py +++ b/direct/src/interval/Track.py @@ -4,25 +4,30 @@ import Interval class Track(Interval.Interval): + trackNum = 1 + # 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.dlist = [] - self.getDuration() + self.computeDuration() - def getDuration(self): - """ getDuration() + def computeDuration(self): + """ computeDuration() """ self.duration = 0.0 for i in self.ilist: dur = i.getDuration() self.duration = self.duration + dur self.dlist.append(dur) - return self.duration def getStartTimeOf(self, name): """ getStartTimeOf(name) diff --git a/direct/src/interval/WaitInterval.py b/direct/src/interval/WaitInterval.py new file mode 100644 index 0000000000..f3eda04e36 --- /dev/null +++ b/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