diff --git a/direct/src/cluster/ClusterClient.py b/direct/src/cluster/ClusterClient.py index 2908cee1b9..44bbc0f860 100644 --- a/direct/src/cluster/ClusterClient.py +++ b/direct/src/cluster/ClusterClient.py @@ -122,9 +122,10 @@ class ClusterClient(DirectObject.DirectObject): taskMgr.add(self.synchronizeTimeTask, "synchronizeTimeTask", -40) def synchronizeTimeTask(self, task): - frameCount = globalClock.getFrameCount() - frameTime = globalClock.getFrameTime() - dt = globalClock.getDt() + clock = ClockObject.getGlobalClock() + frameCount = clock.getFrameCount() + frameTime = clock.getFrameTime() + dt = clock.dt for server in self.serverList: server.sendTimeData(frameCount, frameTime, dt) return Task.cont diff --git a/direct/src/cluster/ClusterServer.py b/direct/src/cluster/ClusterServer.py index 943bbb129c..5a0b948c8a 100644 --- a/direct/src/cluster/ClusterServer.py +++ b/direct/src/cluster/ClusterServer.py @@ -52,7 +52,7 @@ class ClusterServer(DirectObject.DirectObject): self.startSwapCoordinator() base.graphicsEngine.setAutoFlip(0) # Set global clock mode to slave mode - globalClock.setMode(ClockObject.MSlave) + ClockObject.getGlobalClock().setMode(ClockObject.MSlave) # Send verification of startup to client self.daemon = DirectD() @@ -335,9 +335,10 @@ class ClusterServer(DirectObject.DirectObject): """ Update cameraJig position to reflect latest position """ (frameCount, frameTime, dt) = self.msgHandler.parseTimeDataDatagram(dgi) # Use frame time from client for both real and frame time - globalClock.setFrameCount(frameCount) - globalClock.setFrameTime(frameTime) - globalClock.setDt(dt) + clock = ClockObject.getGlobalClock() + clock.setFrameCount(frameCount) + clock.setFrameTime(frameTime) + clock.dt = dt def handleCommandString(self, dgi): """ Handle arbitrary command string from client """ diff --git a/direct/src/directbase/TestStart.py b/direct/src/directbase/TestStart.py index b89526b210..0fd3905721 100755 --- a/direct/src/directbase/TestStart.py +++ b/direct/src/directbase/TestStart.py @@ -13,7 +13,7 @@ base.camera.setPosHpr(0, -10.0, 0, 0, 0, 0) base.camLens.setFov(52.0) base.camLens.setNearFar(1.0, 10000.0) -globalClock.setMaxDt(0.2) +base.clock.setMaxDt(0.2) base.enableParticles() # Force the screen to update: diff --git a/direct/src/directbase/ThreeUpStart.py b/direct/src/directbase/ThreeUpStart.py index a9fc95a1f0..8a5ddce584 100644 --- a/direct/src/directbase/ThreeUpStart.py +++ b/direct/src/directbase/ThreeUpStart.py @@ -15,7 +15,7 @@ base.camera.setPosHpr(0, -10.0, 0, 0, 0, 0) base.camLens.setFov(52.0) base.camLens.setNearFar(1.0, 10000.0) -globalClock.setMaxDt(0.2) +base.clock.setMaxDt(0.2) base.enableParticles() base.addAngularIntegrator() diff --git a/direct/src/directdevices/DirectJoybox.py b/direct/src/directdevices/DirectJoybox.py index 75bb83cbd6..ef4ba82a36 100644 --- a/direct/src/directdevices/DirectJoybox.py +++ b/direct/src/directdevices/DirectJoybox.py @@ -5,6 +5,8 @@ from direct.directtools.DirectUtil import * from direct.gui import OnscreenText from direct.task import Task from direct.task.TaskManagerGlobal import taskMgr +from panda3d.core import ClockObject + import math #TODO: Handle interaction between widget, followSelectedTask and updateTask @@ -58,7 +60,7 @@ class DirectJoybox(DirectObject): R_TWIST, L_TWIST, NULL_AXIS] self.modifier = [1, 1, 1, -1, -1, 0] # Initialize time - self.lastTime = globalClock.getFrameTime() + self.lastTime = ClockObject.getGlobalClock().getFrameTime() # Record node path self.nodePath = nodePath self.headingNP = headingNP @@ -148,7 +150,7 @@ class DirectJoybox(DirectObject): def updateVals(self): # Update delta time - cTime = globalClock.getFrameTime() + cTime = ClockObject.getGlobalClock().getFrameTime() self.deltaTime = cTime - self.lastTime self.lastTime = cTime # Update analogs @@ -164,7 +166,7 @@ class DirectJoybox(DirectObject): def updateValsUnrolled(self): # Update delta time - cTime = globalClock.getFrameTime() + cTime = ClockObject.getGlobalClock().getFrameTime() self.deltaTime = cTime - self.lastTime self.lastTime = cTime # Update analogs diff --git a/direct/src/directtools/DirectCameraControl.py b/direct/src/directtools/DirectCameraControl.py index 66d3aa0928..115f2f613d 100644 --- a/direct/src/directtools/DirectCameraControl.py +++ b/direct/src/directtools/DirectCameraControl.py @@ -129,8 +129,8 @@ class DirectCameraControl(DirectObject): # Hide the marker for this kind of motion self.coaMarker.hide() # Record time of start of mouse interaction - self.startT= globalClock.getFrameTime() - self.startF = globalClock.getFrameCount() + self.startT = base.clock.getFrameTime() + self.startF = base.clock.getFrameCount() # If the cam is orthogonal, spawn differentTask if hasattr(base.direct, "manipulationControl") and base.direct.manipulationControl.fMultiView and\ base.direct.camera.getName() != 'persp': @@ -169,8 +169,8 @@ class DirectCameraControl(DirectObject): # Hide the marker for this kind of motion self.coaMarker.hide() # Record time of start of mouse interaction - self.startT= globalClock.getFrameTime() - self.startF = globalClock.getFrameCount() + self.startT = base.clock.getFrameTime() + self.startF = base.clock.getFrameCount() # Start manipulation # If the cam is orthogonal, spawn differentTask if hasattr(base.direct, "manipulationControl") and base.direct.manipulationControl.fMultiView and\ @@ -186,8 +186,8 @@ class DirectCameraControl(DirectObject): # Hide the marker for this kind of motion self.coaMarker.hide() # Record time of start of mouse interaction - self.startT= globalClock.getFrameTime() - self.startF = globalClock.getFrameCount() + self.startT = base.clock.getFrameTime() + self.startF = base.clock.getFrameCount() # Start manipulation self.spawnXZTranslateOrHPanYZoom() # END MOUSE IN CENTRAL REGION @@ -204,9 +204,9 @@ class DirectCameraControl(DirectObject): def mouseFlyStop(self): self.__stopManipulateCamera() - stopT = globalClock.getFrameTime() + stopT = base.clock.getFrameTime() deltaT = stopT - self.startT - stopF = globalClock.getFrameCount() + stopF = base.clock.getFrameCount() deltaF = stopF - self.startF ## No reason this shouldn't work with Maya cam on # if not self.useMayaCamControls and (deltaT <= 0.25) or (deltaF <= 1): diff --git a/direct/src/directtools/DirectUtil.py b/direct/src/directtools/DirectUtil.py index 1d7cc60015..df5b75e378 100644 --- a/direct/src/directtools/DirectUtil.py +++ b/direct/src/directtools/DirectUtil.py @@ -36,7 +36,7 @@ def lerpBackgroundColor(r, g, b, duration): Function to lerp background color to a new value """ def lerpColor(state): - dt = globalClock.getDt() + dt = base.clock.getDt() state.time += dt sf = state.time / state.duration if sf >= 1.0: diff --git a/direct/src/directutil/Mopath.py b/direct/src/directutil/Mopath.py index 08a9363211..7661ea1da6 100644 --- a/direct/src/directutil/Mopath.py +++ b/direct/src/directutil/Mopath.py @@ -2,7 +2,8 @@ from direct.showbase.DirectObject import DirectObject from direct.showbase.MessengerGlobal import messenger from direct.directtools.DirectGeometry import * -from panda3d.core import NodePath, LineSegs +from panda3d.core import NodePath, LineSegs, ClockObject + class Mopath(DirectObject): @@ -152,13 +153,13 @@ class Mopath(DirectObject): self.stop() t = taskMgr.add(self.__playTask, self.name + '-play') t.currentTime = time - t.lastTime = globalClock.getFrameTime() + t.lastTime = ClockObject.getGlobalClock().getFrameTime() def stop(self): taskMgr.remove(self.name + '-play') def __playTask(self, task): - time = globalClock.getFrameTime() + time = ClockObject.getGlobalClock().getFrameTime() dTime = time - task.lastTime task.lastTime = time if self.loop: diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index e0866af4b7..9d8e219fa3 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -6,7 +6,7 @@ from direct.showbase.MessengerGlobal import messenger from .MsgTypesCMU import * from .PyDatagram import PyDatagram from .PyDatagramIterator import PyDatagramIterator -from panda3d.core import UniqueIdAllocator, Notify +from panda3d.core import UniqueIdAllocator, Notify, ClockObject class ClientRepository(ClientRepositoryBase): @@ -281,7 +281,7 @@ class ClientRepository(ClientRepositoryBase): datagram.addUint16(CLIENT_HEARTBEAT_CMU) # Send it! self.send(datagram) - self.lastHeartbeat = globalClock.getRealTime() + self.lastHeartbeat = ClockObject.getGlobalClock().getRealTime() # This is important enough to consider flushing immediately # (particularly if we haven't run readerPollTask recently). self.considerFlush() diff --git a/direct/src/distributed/ClientRepositoryBase.py b/direct/src/distributed/ClientRepositoryBase.py index 850dbf4582..e6a957e279 100644 --- a/direct/src/distributed/ClientRepositoryBase.py +++ b/direct/src/distributed/ClientRepositoryBase.py @@ -186,7 +186,7 @@ class ClientRepositoryBase(ConnectionRepository): self.doGenerate(*args) if deferrable: - self.lastGenerate = globalClock.getFrameTime() + self.lastGenerate = ClockObject.getGlobalClock().getFrameTime() for dg, di in updates: # non-DC updates that need to be played back in-order are @@ -207,7 +207,7 @@ class ClientRepositoryBase(ConnectionRepository): """ This is the task that generates an object on the deferred queue. """ - now = globalClock.getFrameTime() + now = ClockObject.getGlobalClock().getFrameTime() while self.deferredGenerates: if now - self.lastGenerate < self.deferInterval: # Come back later. @@ -539,7 +539,7 @@ class ClientRepositoryBase(ConnectionRepository): self.notify.debug("Heartbeats not started; not sending.") return - elapsed = globalClock.getRealTime() - self.lastHeartbeat + elapsed = ClockObject.getGlobalClock().getRealTime() - self.lastHeartbeat if elapsed < 0 or elapsed > self.heartbeatInterval: # It's time to send the heartbeat again (or maybe someone # reset the clock back). diff --git a/direct/src/distributed/DistributedSmoothNode.py b/direct/src/distributed/DistributedSmoothNode.py index 3d9371d8c3..7489dea06c 100644 --- a/direct/src/distributed/DistributedSmoothNode.py +++ b/direct/src/distributed/DistributedSmoothNode.py @@ -187,7 +187,7 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, reflect the node's current position """ if self.stopped: - currTime = globalClock.getFrameTime() + currTime = ClockObject.getGlobalClock().getFrameTime() now = currTime - self.smoother.getExpectedBroadcastPeriod() last = self.smoother.getMostRecentTimestamp() if now > last: @@ -348,6 +348,7 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, self.smoother.setPhonyTimestamp() self.smoother.markPosition() else: + globalClock = ClockObject.getGlobalClock() now = globalClock.getFrameTime() local = globalClockDelta.networkToLocalTime(timestamp, now) realTime = globalClock.getRealTime() diff --git a/direct/src/distributed/DoInterestManager.py b/direct/src/distributed/DoInterestManager.py index 382abc48dd..ca17e774be 100755 --- a/direct/src/distributed/DoInterestManager.py +++ b/direct/src/distributed/DoInterestManager.py @@ -157,7 +157,7 @@ class DoInterestManager(DirectObject.DirectObject): """ assert DoInterestManager.notify.debugCall() handle = self._getNextHandle() - # print 'base.cr.addInterest(',description,',',handle,'):',globalClock.getFrameCount() + # print 'base.cr.addInterest(',description,',',handle,'):',base.clock.getFrameCount() if self._noNewInterests: DoInterestManager.notify.warning( "addInterest: addingInterests on delete: %s" % (handle)) @@ -229,7 +229,7 @@ class DoInterestManager(DirectObject.DirectObject): """ Stop looking in a (set of) zone(s) """ - # print 'base.cr.removeInterest(',handle,'):',globalClock.getFrameCount() + # print 'base.cr.removeInterest(',handle,'):',base.clock.getFrameCount() assert DoInterestManager.notify.debugCall() assert isinstance(handle, InterestHandle) @@ -567,7 +567,7 @@ class DoInterestManager(DirectObject.DirectObject): def checkMoreInterests(): # if there are new interests, cancel this delayed callback, another # will automatically be scheduled when all interests complete - # print 'checkMoreInterests(',self._completeEventCount.num,'):',globalClock.getFrameCount() + # print 'checkMoreInterests(',self._completeEventCount.num,'):',base.clock.getFrameCount() return self._completeEventCount.num > 0 def sendEvent(): messenger.send(self.getAllInterestsCompleteEvent()) diff --git a/direct/src/distributed/TimeManager.py b/direct/src/distributed/TimeManager.py index 8b5d228c79..cb29b0a8ac 100644 --- a/direct/src/distributed/TimeManager.py +++ b/direct/src/distributed/TimeManager.py @@ -6,6 +6,7 @@ from direct.distributed import DistributedObject from direct.directnotify import DirectNotifyGlobal from direct.distributed.ClockDelta import globalClockDelta + class TimeManager(DistributedObject.DistributedObject): """ This DistributedObject lives on the AI and on the client side, and @@ -128,7 +129,7 @@ class TimeManager(DistributedObject.DistributedObject): The return value is true if the attempt is made, or false if it is too soon since the last attempt. """ - now = globalClock.getRealTime() + now = ClockObject.getGlobalClock().getRealTime() if now - self.lastAttempt < self.minWait: self.notify.debug("Not resyncing (too soon): %s" % (description)) @@ -157,7 +158,8 @@ class TimeManager(DistributedObject.DistributedObject): determine the clock delta between the AI and the client machines. """ - end = globalClock.getRealTime() + clock = ClockObject.getGlobalClock() + end = clock.getRealTime() if context != self.thisContext: self.notify.info("Ignoring TimeManager response for old context %d" % (context)) @@ -177,7 +179,7 @@ class TimeManager(DistributedObject.DistributedObject): if globalClockDelta.getUncertainty() > self.maxUncertainty: if self.attemptCount < self.maxAttempts: self.notify.info("Uncertainty is too high, trying again.") - self.start = globalClock.getRealTime() + self.start = clock.getRealTime() self.sendUpdate("requestServerTime", [self.thisContext]) return self.notify.info("Giving up on uncertainty requirement.") diff --git a/direct/src/interval/IntervalTest.py b/direct/src/interval/IntervalTest.py index d6b747df46..c89ea26e9d 100644 --- a/direct/src/interval/IntervalTest.py +++ b/direct/src/interval/IntervalTest.py @@ -137,22 +137,22 @@ if __name__ == "__main__": startTime = 0.0 def printStart(): global startTime - startTime = globalClock.getFrameTime() + startTime = base.clock.getFrameTime() print('Start') def printPreviousStart(): global startTime - currTime = globalClock.getFrameTime() + currTime = base.clock.getFrameTime() print('PREVIOUS_END %0.2f' % (currTime - startTime)) def printPreviousEnd(): global startTime - currTime = globalClock.getFrameTime() + currTime = base.clock.getFrameTime() print('PREVIOUS_END %0.2f' % (currTime - startTime)) def printTrackStart(): global startTime - currTime = globalClock.getFrameTime() + currTime = base.clock.getFrameTime() print('TRACK_START %0.2f' % (currTime - startTime)) def printArguments(a, b, c): diff --git a/direct/src/leveleditor/LevelEditorBase.py b/direct/src/leveleditor/LevelEditorBase.py index 6afc4600f0..646be9e86e 100755 --- a/direct/src/leveleditor/LevelEditorBase.py +++ b/direct/src/leveleditor/LevelEditorBase.py @@ -8,6 +8,7 @@ Refer LevelEditor.py for example. from direct.showbase.DirectObject import * from direct.directtools.DirectUtil import * from direct.gui.DirectGui import * +from panda3d.core import ClockObject from .CurveEditor import * from .FileMgr import * @@ -385,7 +386,7 @@ class LevelEditorBase(DirectObject): alreadyExists = True break if not alreadyExists: - time = globalClock.getRealTime() + 15 + time = ClockObject.getGlobalClock().getRealTime() + 15 self.statusLines.append([time,status,color]) # update display of new status lines @@ -407,7 +408,7 @@ class LevelEditorBase(DirectObject): def updateStatusReadoutTimeouts(self,task=None): removalList = [] for currLine in self.statusLines: - if globalClock.getRealTime() >= currLine[0]: + if ClockObject.getGlobalClock().getRealTime() >= currLine[0]: removalList.append(currLine) for currRemoval in removalList: self.statusLines.remove(currRemoval) diff --git a/direct/src/showbase/JobManager.py b/direct/src/showbase/JobManager.py index 01567c7462..609d6f09c4 100755 --- a/direct/src/showbase/JobManager.py +++ b/direct/src/showbase/JobManager.py @@ -150,9 +150,10 @@ class JobManager: self._useOverflowTime = ConfigVariableBool('job-use-overflow-time', 1).value if len(self._pri2jobId2job) > 0: + clock = ClockObject.getGlobalClock() #assert self.notify.debugCall() # figure out how long we can run - endT = globalClock.getRealTime() + (self.getTimeslice() * .9) + endT = clock.getRealTime() + (self.getTimeslice() * .9) while True: if self._jobIdGenerator is None: # round-robin the jobs, giving high-priority jobs more timeslices @@ -173,7 +174,7 @@ class JobManager: # check if there's overflow time that we need to make up for if self._useOverflowTime: overflowTime = self._jobId2overflowTime[jobId] - timeLeft = endT - globalClock.getRealTime() + timeLeft = endT - clock.getRealTime() if overflowTime >= timeLeft: self._jobId2overflowTime[jobId] = max(0., overflowTime-timeLeft) # don't run any more jobs this frame, this makes up @@ -184,7 +185,7 @@ class JobManager: if __debug__: job._pstats.start() job.resume() - while globalClock.getRealTime() < endT: + while clock.getRealTime() < endT: try: result = next(gen) except StopIteration: @@ -210,9 +211,9 @@ class JobManager: break else: # we've run out of time - #assert self.notify.debug('timeslice end: %s, %s' % (endT, globalClock.getRealTime())) + #assert self.notify.debug('timeslice end: %s, %s' % (endT, clock.getRealTime())) job.suspend() - overflowTime = globalClock.getRealTime() - endT + overflowTime = clock.getRealTime() - endT if overflowTime > self.getTimeslice(): self._jobId2overflowTime[jobId] += overflowTime if __debug__: diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index de49761c21..178cfa6bca 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -43,7 +43,7 @@ import functools __report_indent = 3 -from panda3d.core import ConfigVariableBool +from panda3d.core import ConfigVariableBool, ClockObject ## with one integer positional arg, this uses about 4/5 of the memory of the Functor class below @@ -2053,6 +2053,7 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara if prefixes: outStr = '%%s %s' % (outStr,) + globalClock = ClockObject.getGlobalClock() if 'module' in types: outStr = '%s {M:%s}' % (outStr, f.__module__.split('.')[-1]) @@ -2264,9 +2265,10 @@ if __debug__: # at the time that PythonUtil is loaded if not ConfigVariableBool("profile-debug", False): #dumb timings - st=globalClock.getRealTime() - f(*args,**kArgs) - s=globalClock.getRealTime()-st + clock = ClockObject.getGlobalClock() + st = clock.getRealTime() + f(*args, **kArgs) + s = clock.getRealTime() - st print("Function %s.%s took %s seconds"%(f.__module__, f.__name__,s)) else: import profile as prof, pstats diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index c7edea715e..22e38aab8b 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -384,18 +384,19 @@ class ShowBase(DirectObject.DirectObject): # Get a pointer to Panda's global ClockObject, used for # synchronizing events between Python and C. - globalClock = ClockObject.getGlobalClock() + clock = ClockObject.getGlobalClock() + self.clock = clock # Since we have already started up a TaskManager, and probably # a number of tasks; and since the TaskManager had to use the # TrueClock to tell time until this moment, make sure the # globalClock object is exactly in sync with the TrueClock. trueClock = TrueClock.getGlobalPtr() - globalClock.setRealTime(trueClock.getShortTime()) - globalClock.tick() + clock.setRealTime(trueClock.getShortTime()) + clock.tick() - # Now we can make the TaskManager start using the new globalClock. - taskMgr.globalClock = globalClock + # Now we can make the TaskManager start using the new clock. + taskMgr.globalClock = clock # client CPU affinity is determined by, in order: # - client-cpu-affinity-mask config @@ -444,7 +445,7 @@ class ShowBase(DirectObject.DirectObject): builtins.ostream = Notify.out() builtins.directNotify = directNotify builtins.giveNotify = giveNotify - builtins.globalClock = globalClock + builtins.globalClock = clock builtins.vfs = vfs builtins.cpMgr = ConfigPageManager.getGlobalPtr() builtins.cvMgr = ConfigVariableManager.getGlobalPtr() @@ -1899,7 +1900,7 @@ class ShowBase(DirectObject.DirectObject): return self.physicsMgrEnabled def updateManagers(self, state): - dt = globalClock.getDt() + dt = self.clock.dt if self.particleMgrEnabled: self.particleMgr.doParticles(dt) if self.physicsMgrEnabled: @@ -2927,14 +2928,15 @@ class ShowBase(DirectObject.DirectObject): Returns: A `~direct.task.Task` that can be awaited. """ - globalClock.setMode(ClockObject.MNonRealTime) - globalClock.setDt(1.0/float(fps)) + clock = self.clock + clock.mode = ClockObject.MNonRealTime + clock.dt = 1.0 / fps t = self.taskMgr.add(self._movieTask, namePrefix + '_task') t.frameIndex = 0 # Frame 0 is not captured. t.numFrames = int(duration * fps) t.source = source t.outputString = namePrefix + '_%0' + repr(sd) + 'd.' + format - t.setUponDeath(lambda state: globalClock.setMode(ClockObject.MNormal)) + t.setUponDeath(lambda state: clock.setMode(ClockObject.MNormal)) return t def _movieTask(self, state): diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index a52cb9d325..31888e0d60 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -33,6 +33,7 @@ ostream = Notify.out() #: The clock object used by default for rendering and animation, obtained using #: :meth:`panda3d.core.ClockObject.getGlobalClock()`. +#: @deprecated Use `base.clock` instead. globalClock = ClockObject.getGlobalClock() #: See :meth:`panda3d.core.ConfigPageManager.getGlobalPtr()`. diff --git a/direct/src/showbase/TaskThreaded.py b/direct/src/showbase/TaskThreaded.py index 75a52b7ad5..cb664c6c09 100755 --- a/direct/src/showbase/TaskThreaded.py +++ b/direct/src/showbase/TaskThreaded.py @@ -5,6 +5,7 @@ __all__ = ['TaskThreaded', 'TaskThread'] from direct.directnotify.DirectNotifyGlobal import directNotify from direct.task import Task from direct.task.TaskManagerGlobal import taskMgr +from panda3d.core import ClockObject from .PythonUtil import SerialNumGen, Functor @@ -89,14 +90,14 @@ class TaskThreaded: def _doCallback(self, callback, taskName, task): assert self.notify.debugCall() self.__taskNames.remove(taskName) - self._taskStartTime = globalClock.getRealTime() + self._taskStartTime = ClockObject.getGlobalClock().getRealTime() callback() self._taskStartTime = None return Task.done def _doThreadCallback(self, thread, taskName, task): assert self.notify.debugCall() - self._taskStartTime = globalClock.getRealTime() + self._taskStartTime = ClockObject.getGlobalClock().getRealTime() thread.run() self._taskStartTime = None if thread.isFinished(): @@ -114,7 +115,7 @@ class TaskThreaded: # we must not be in a task callback, we must be running in non-threaded # mode return True - return (globalClock.getRealTime() - self._taskStartTime) < self.__timeslice + return (ClockObject.getGlobalClock().getRealTime() - self._taskStartTime) < self.__timeslice class TaskThread: # derive and override these four funcs diff --git a/direct/src/task/FrameProfiler.py b/direct/src/task/FrameProfiler.py index 6520db26bf..e037c9292d 100755 --- a/direct/src/task/FrameProfiler.py +++ b/direct/src/task/FrameProfiler.py @@ -1,4 +1,4 @@ -from panda3d.core import ConfigVariableBool +from panda3d.core import ConfigVariableBool, ClockObject from direct.directnotify.DirectNotifyGlobal import directNotify from direct.fsm.StatePush import FunctionCall from direct.showbase.PythonUtil import formatTimeExact, normalDistrib, serialNum @@ -59,7 +59,7 @@ class FrameProfiler: def _setEnabled(self, enabled): if enabled: self.notify.info('frame profiler started') - self._startTime = globalClock.getFrameTime() + self._startTime = ClockObject.getGlobalClock().getFrameTime() self._profileCounter = 0 self._jitter = None self._period2aggregateProfile = {} @@ -110,7 +110,7 @@ class FrameProfiler: self._analyzeResults, sessionId)) # schedule the next profile - delay = max(time - globalClock.getFrameTime(), 0.) + delay = max(time - ClockObject.getGlobalClock().getFrameTime(), 0.) self._task = taskMgr.doMethodLater(delay, self._scheduleNextProfileDoLater, 'FrameProfiler-%s' % serialNum()) diff --git a/direct/src/task/Timer.py b/direct/src/task/Timer.py index 0746aff26f..eeedfe3851 100644 --- a/direct/src/task/Timer.py +++ b/direct/src/task/Timer.py @@ -2,6 +2,8 @@ __all__ = ['Timer'] +from panda3d.core import ClockObject + from . import Task from .TaskManagerGlobal import taskMgr @@ -25,7 +27,7 @@ class Timer: self.callback = None self.finalT = t self.name = name - self.startT = globalClock.getFrameTime() + self.startT = ClockObject.getGlobalClock().getFrameTime() self.currT = 0.0 taskMgr.add(self.__timerTask, self.name + '-run') self.started = 1 @@ -35,7 +37,7 @@ class Timer: self.stop() self.callback = callback self.finalT = t - self.startT = globalClock.getFrameTime() + self.startT = ClockObject.getGlobalClock().getFrameTime() self.currT = 0.0 taskMgr.add(self.__timerTask, self.name + '-run') self.started = 1 @@ -71,7 +73,7 @@ class Timer: return self.finalT - self.currT def __timerTask(self, task): - t = globalClock.getFrameTime() + t = ClockObject.getGlobalClock().getFrameTime() te = t - self.startT self.currT = te if te >= self.finalT: diff --git a/direct/src/tkpanels/AnimPanel.py b/direct/src/tkpanels/AnimPanel.py index 16d7a3283f..93f221c2c3 100644 --- a/direct/src/tkpanels/AnimPanel.py +++ b/direct/src/tkpanels/AnimPanel.py @@ -5,7 +5,7 @@ __all__ = ['AnimPanel', 'ActorControl'] ### SEE END OF FILE FOR EXAMPLE USEAGE ### # Import Tkinter, Pmw, and the floater code from this directory tree. -from panda3d.core import Filename, getModelPath +from panda3d.core import Filename, getModelPath, ClockObject from direct.tkwidgets.AppShell import * from direct.showbase.TkGlobal import * from direct.task import Task @@ -294,7 +294,7 @@ class AnimPanel(AppShell): def playActorControls(self): self.stopActorControls() - self.lastT = globalClock.getFrameTime() + self.lastT = ClockObject.getGlobalClock().getFrameTime() self.playList = self.actorControlList[:] taskMgr.add(self.play, self.id + '_UpdateTask') @@ -302,7 +302,7 @@ class AnimPanel(AppShell): if not self.playList: return Task.done fLoop = self.loopVar.get() - currT = globalClock.getFrameTime() + currT = ClockObject.getGlobalClock().getFrameTime() deltaT = currT - self.lastT self.lastT = currT for actorControl in self.playList: diff --git a/direct/src/tkpanels/MopathRecorder.py b/direct/src/tkpanels/MopathRecorder.py index a3b57052ff..3d258e2911 100644 --- a/direct/src/tkpanels/MopathRecorder.py +++ b/direct/src/tkpanels/MopathRecorder.py @@ -983,7 +983,7 @@ class MopathRecorder(AppShell, DirectObject): # Start new task t = taskMgr.add( self.recordTask, self.name + '-recordTask') - t.startTime = globalClock.getFrameTime() + t.startTime = ClockObject.getGlobalClock().getFrameTime() else: if self.samplingMode == 'Continuous': # Kill old task @@ -1016,7 +1016,7 @@ class MopathRecorder(AppShell, DirectObject): def recordTask(self, state): # Record raw data point time = self.recordStart + ( - globalClock.getFrameTime() - state.startTime) + ClockObject.getGlobalClock().getFrameTime() - state.startTime) self.recordPoint(time) return Task.cont @@ -1281,7 +1281,7 @@ class MopathRecorder(AppShell, DirectObject): t = taskMgr.add( self.playbackTask, self.name + '-playbackTask') t.currentTime = self.playbackTime - t.lastTime = globalClock.getFrameTime() + t.lastTime = ClockObject.getGlobalClock().getFrameTime() def setSpeedScale(self, value): self.speedScale.set(math.log10(value)) @@ -1291,7 +1291,7 @@ class MopathRecorder(AppShell, DirectObject): self.speedVar.set('%0.2f' % self.playbackSF) def playbackTask(self, state): - time = globalClock.getFrameTime() + time = ClockObject.getGlobalClock().getFrameTime() dTime = self.playbackSF * (time - state.lastTime) state.lastTime = time if self.loopPlayback: diff --git a/direct/src/tkwidgets/Dial.py b/direct/src/tkwidgets/Dial.py index 457563b6b9..a67730636c 100644 --- a/direct/src/tkwidgets/Dial.py +++ b/direct/src/tkwidgets/Dial.py @@ -8,6 +8,7 @@ __all__ = ['Dial', 'AngleDial', 'DialWidget'] from direct.showbase.TkGlobal import * from .Valuator import Valuator, VALUATOR_MINI, VALUATOR_FULL from direct.task import Task +from panda3d.core import ClockObject import math import operator import Pmw @@ -335,11 +336,11 @@ class DialWidget(Pmw.MegaWidget): self._onButtonPress() self.knobSF = 0.0 self.updateTask = taskMgr.add(self.updateDialTask, 'updateDial') - self.updateTask.lastTime = globalClock.getFrameTime() + self.updateTask.lastTime = ClockObject.getGlobalClock().getFrameTime() def updateDialTask(self, state): # Update value - currT = globalClock.getFrameTime() + currT = ClockObject.getGlobalClock().getFrameTime() dt = currT - state.lastTime self.set(self.value + self.knobSF * dt) state.lastTime = currT diff --git a/direct/src/tkwidgets/Floater.py b/direct/src/tkwidgets/Floater.py index 73bde3271e..61a2d028e8 100644 --- a/direct/src/tkwidgets/Floater.py +++ b/direct/src/tkwidgets/Floater.py @@ -8,6 +8,7 @@ __all__ = ['Floater', 'FloaterWidget', 'FloaterGroup'] from direct.showbase.TkGlobal import * from .Valuator import Valuator, VALUATOR_MINI, VALUATOR_FULL from direct.task import Task +from panda3d.core import ClockObject import math import Pmw @@ -149,14 +150,14 @@ class FloaterWidget(Pmw.MegaWidget): self.velocitySF = 0.0 self.updateTask = taskMgr.add(self.updateFloaterTask, 'updateFloater') - self.updateTask.lastTime = globalClock.getFrameTime() + self.updateTask.lastTime = ClockObject.getGlobalClock().getFrameTime() def updateFloaterTask(self, state): """ Update floaterWidget value based on current scaleFactor Adjust for time to compensate for fluctuating frame rates """ - currT = globalClock.getFrameTime() + currT = ClockObject.getGlobalClock().getFrameTime() dt = currT - state.lastTime self.set(self.value + self.velocitySF * dt) state.lastTime = currT