diff --git a/direct/src/showbase/Finder.py b/direct/src/showbase/Finder.py index f9d159c5ea..62ea8083b8 100644 --- a/direct/src/showbase/Finder.py +++ b/direct/src/showbase/Finder.py @@ -125,10 +125,12 @@ def copyFuncs(fromClass, toClass): newFunc = value # See if we already have a function with this name 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] replaceMessengerFunc(oldFunc, newFunc) + replaceTaskMgrFunc(oldFunc, newFunc) toClass.__dict__[key] = newFunc def replaceMessengerFunc(oldFunc, newFunc): @@ -136,3 +138,7 @@ def replaceMessengerFunc(oldFunc, newFunc): if res: print ('replaced messenger function: ' + newFunc.__name__) +def replaceTaskMgrFunc(oldFunc, newFunc): + res = taskMgr.replaceMethod(oldFunc, newFunc) + if res: + print ('replaced taskMgr function: ' + newFunc.__name__) diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index c9fdec8ff8..c10b0f1a30 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -290,6 +290,27 @@ class TaskManager: # Set a flag so we will stop before beginning next frame 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): str = '' str = str + 'taskList\n'