def __lerp(self, functorFunc, duration, blendType, taskName=None): """ __lerp(self, functorFunc, float, string, string) Basic lerp functionality used by other lerps. Fire off a lerp. Make it a task if taskName given. """ # functorFunc is a function which can be called to create a functor. # functor creation is defered so initial state (sampled in functorFunc) # will be appropriate for the time the lerp is spawned from panda3d.direct.task import Task from panda3d.direct.showbase import LerpBlendHelpers from panda3d.direct.task.TaskManagerGlobal import taskMgr # upon death remove the functorFunc def lerpUponDeath(task): # Try to break circular references try: del task.functorFunc except: pass try: del task.lerp except: pass # make the task function def lerpTaskFunc(task): from panda3d.pandac.Lerp import Lerp from panda3d.pandac.ClockObject import ClockObject from panda3d.direct.task.Task import Task, cont, done if task.init == 1: # make the lerp functor = task.functorFunc() task.lerp = Lerp(functor, task.duration, task.blendType) task.init = 0 dt = globalClock.getDt() task.lerp.setStepSize(dt) task.lerp.step() if (task.lerp.isDone()): # Reset the init flag, in case the task gets re-used task.init = 1 return (done) else: return (cont) # make the lerp task lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 lerpTask.functorFunc = functorFunc lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) lerpTask.setUponDeath(lerpUponDeath) if (taskName == None): # don't spawn a task, return one instead return lerpTask else: # spawn the lerp task taskMgr.add(lerpTask, taskName) return lerpTask
def __lerp(self, functorFunc, duration, blendType, taskName=None): """ __lerp(self, functorFunc, float, string, string) Basic lerp functionality used by other lerps. Fire off a lerp. Make it a task if taskName given. """ # functorFunc is a function which can be called to create a functor. # functor creation is defered so initial state (sampled in functorFunc) # will be appropriate for the time the lerp is spawned from panda3d.direct.task import Task from panda3d.direct.showbase import LerpBlendHelpers from panda3d.direct.task.TaskManagerGlobal import taskMgr # upon death remove the functorFunc def lerpUponDeath(task): # Try to break circular references try: del task.functorFunc except: pass try: del task.lerp except: pass # make the task function def lerpTaskFunc(task): from panda3d.pandac.Lerp import Lerp from panda3d.pandac.ClockObject import ClockObject from panda3d.direct.task.Task import Task, cont, done if task.init == 1: # make the lerp functor = task.functorFunc() task.lerp = Lerp(functor, task.duration, task.blendType) task.init = 0 dt = globalClock.getDt() task.lerp.setStepSize(dt) task.lerp.step() if (task.lerp.isDone()): # Reset the init flag, in case the task gets re-used task.init = 1 return(done) else: return(cont) # make the lerp task lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 lerpTask.functorFunc = functorFunc lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) lerpTask.setUponDeath(lerpUponDeath) if (taskName == None): # don't spawn a task, return one instead return lerpTask else: # spawn the lerp task taskMgr.add(lerpTask, taskName) return lerpTask
def restart(self): if None in (EventManager.EventQueue, EventManager.EventHandler): from panda3d.pandac import EventQueue, EventHandler EventManager.EventQueue = EventQueue EventManager.EventHandler = EventHandler if self.eventQueue == None: self.eventQueue = EventManager.EventQueue.getGlobalEventQueue() if self.eventHandler == None: if self.eventQueue == EventManager.EventQueue.getGlobalEventQueue(): # If we are using the global event queue, then we also # want to use the global event handler. self.eventHandler = EventManager.EventHandler.getGlobalEventHandler() else: # Otherwise, we need our own event handler. self.eventHandler = EventManager.EventHandler(self.eventQueue) # Should be safe to import the global taskMgr by now. from panda3d.direct.task.TaskManagerGlobal import taskMgr taskMgr.add(self.eventLoopTask, 'eventManager')
def restart(self): if None in (EventManager.EventQueue, EventManager.EventHandler): from panda3d.pandac import EventQueue, EventHandler EventManager.EventQueue = EventQueue EventManager.EventHandler = EventHandler if self.eventQueue == None: self.eventQueue = EventManager.EventQueue.getGlobalEventQueue() if self.eventHandler == None: if self.eventQueue == EventManager.EventQueue.getGlobalEventQueue( ): # If we are using the global event queue, then we also # want to use the global event handler. self.eventHandler = EventManager.EventHandler.getGlobalEventHandler( ) else: # Otherwise, we need our own event handler. self.eventHandler = EventManager.EventHandler(self.eventQueue) # Should be safe to import the global taskMgr by now. from panda3d.direct.task.TaskManagerGlobal import taskMgr taskMgr.add(self.eventLoopTask, 'eventManager')
def add(self, job): pri = job.getPriority() jobId = job._getJobId() # store the job in the main table self._pri2jobId2job.setdefault(pri, {}) self._pri2jobId2job[pri][jobId] = job # and also store a direct mapping from the job's ID to its priority self._jobId2pri[jobId] = pri # add the jobId onto the end of the list of jobIds for this priority self._pri2jobIds.setdefault(pri, []) self._pri2jobIds[pri].append(jobId) # record the job's relative timeslice count self._jobId2timeslices[jobId] = pri # init the overflow time tracking self._jobId2overflowTime[jobId] = 0. # reset the jobId round-robin self._jobIdGenerator = None if len(self._jobId2pri) == 1: taskMgr.add(self._process, JobManager.TaskName) self._highestPriority = pri elif pri > self._highestPriority: self._highestPriority = pri self.notify.debug('added job: %s' % job.getJobName())