Browse Source

support Task object for doMethodLater

David Rose 20 years ago
parent
commit
6a4debc517
1 changed files with 16 additions and 8 deletions
  1. 16 8
      direct/src/task/Task.py

+ 16 - 8
direct/src/task/Task.py

@@ -411,23 +411,31 @@ class TaskManager:
             # TaskManager.notify.debug("filtered %s removed doLaters" % numRemoved)
             # TaskManager.notify.debug("filtered %s removed doLaters" % numRemoved)
         return cont
         return cont
 
 
-    def doMethodLater(self, delayTime, func, taskName, extraArgs=None, uponDeath=None, appendTask=False):
-        task = Task(func)
+    def doMethodLater(self, delayTime, funcOrTask, name, extraArgs=None, priority=0, uponDeath=None, appendTask=False):
+        if isinstance(funcOrTask, Task):
+            task = funcOrTask
+        elif callable(funcOrTask):
+            task = Task(funcOrTask, priority)
+        else:
+            self.notify.error('add: Tried to add a task that was not a Task or a func')
+        task.setPriority(priority)
+        task.name = name
+        task.extraArgs = extraArgs
+        if uponDeath:
+            task.uponDeath = uponDeath
+
         # if told to, append the task object to the extra args list so the method
         # if told to, append the task object to the extra args list so the method
         # called will be able to access any properties on the task
         # called will be able to access any properties on the task
         if (appendTask == True and extraArgs != None):
         if (appendTask == True and extraArgs != None):
             extraArgs.append(task)
             extraArgs.append(task)
-        task.name = taskName
-        task.extraArgs = extraArgs
-        if uponDeath:
-            task.uponDeath = uponDeath
+
         # TaskManager.notify.debug('spawning doLater: %s' % (task))
         # TaskManager.notify.debug('spawning doLater: %s' % (task))
         # Add this task to the nameDict
         # Add this task to the nameDict
-        nameList = self.nameDict.get(taskName)
+        nameList = self.nameDict.get(name)
         if nameList:
         if nameList:
             nameList.append(task)
             nameList.append(task)
         else:
         else:
-            self.nameDict[taskName] = [task]
+            self.nameDict[name] = [task]
         # be sure to ask the globalClock for the current frame time
         # be sure to ask the globalClock for the current frame time
         # rather than use a cached value; globalClock's frame time may
         # rather than use a cached value; globalClock's frame time may
         # have been synced since the start of this frame
         # have been synced since the start of this frame