浏览代码

*** empty log message ***

Joe Shochet 25 年之前
父节点
当前提交
d249ff24e5
共有 2 个文件被更改,包括 29 次插入2 次删除
  1. 8 2
      direct/src/showbase/Finder.py
  2. 21 0
      direct/src/task/Task.py

+ 8 - 2
direct/src/showbase/Finder.py

@@ -125,10 +125,12 @@ def copyFuncs(fromClass, toClass):
             newFunc = value
             newFunc = value
             # See if we already have a function with this name
             # See if we already have a function with this name
             if toClass.__dict__.has_key(key):
             if toClass.__dict__.has_key(key):
-                # Look in the messenger to see if this old function pointer
-                # is stored, and update it to the new function pointer
+                # Look in the messenger and taskMgr to see if this
+                # old function pointer is stored there,
+                # and update it to the new function pointer
                 oldFunc = toClass.__dict__[key]
                 oldFunc = toClass.__dict__[key]
                 replaceMessengerFunc(oldFunc, newFunc)
                 replaceMessengerFunc(oldFunc, newFunc)
+                replaceTaskMgrFunc(oldFunc, newFunc)
             toClass.__dict__[key] = newFunc
             toClass.__dict__[key] = newFunc
 
 
 def replaceMessengerFunc(oldFunc, newFunc):
 def replaceMessengerFunc(oldFunc, newFunc):
@@ -136,3 +138,7 @@ def replaceMessengerFunc(oldFunc, newFunc):
     if res:
     if res:
         print ('replaced messenger function: ' + newFunc.__name__)
         print ('replaced messenger function: ' + newFunc.__name__)
 
 
+def replaceTaskMgrFunc(oldFunc, newFunc):
+    res = taskMgr.replaceMethod(oldFunc, newFunc)
+    if res:
+        print ('replaced taskMgr function: ' + newFunc.__name__)

+ 21 - 0
direct/src/task/Task.py

@@ -290,6 +290,27 @@ class TaskManager:
         # Set a flag so we will stop before beginning next frame
         # Set a flag so we will stop before beginning next frame
         self.running = 0
         self.running = 0
 
 
+    def replaceMethod(self, oldMethod, newFunction):
+        import new
+        for task in self.taskList:
+            method = task.__call__
+            if (type(method) == types.MethodType):
+                function = method.im_func
+            else:
+                function = method
+            #print ('function: ' + `function` + '\n' +
+            #       'method: ' + `method` + '\n' +
+            #       'oldMethod: ' + `oldMethod` + '\n' +
+            #       'newFunction: ' + `newFunction` + '\n')
+            if (function == oldMethod):
+                newMethod = new.instancemethod(newFunction,
+                                               method.im_self,
+                                               method.im_class)
+                task.__call__ = newMethod
+                # Found it retrun true
+                return 1
+        return 0
+
     def __repr__(self):
     def __repr__(self):
         str = ''
         str = ''
         str = str + 'taskList\n'
         str = str + 'taskList\n'