mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
task replacement now looks for doLaters and pending tasks
This commit is contained in:
parent
6c5a9f0309
commit
7fefe01e6a
@ -875,29 +875,42 @@ 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):
|
def __tryReplaceTaskMethod(self, task, oldMethod, newFunction):
|
||||||
import new
|
import new
|
||||||
|
if (task is None) or task.isRemoved():
|
||||||
|
return 0
|
||||||
|
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 a match
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def replaceMethod(self, oldMethod, newFunction):
|
||||||
|
numFound = 0
|
||||||
|
# Look through the regular tasks
|
||||||
for taskPriList in self.taskList:
|
for taskPriList in self.taskList:
|
||||||
for task in taskPriList:
|
for task in taskPriList:
|
||||||
if (task is None) or (task.isRemoved()):
|
numFound += self.__tryReplaceTaskMethod(task, oldMethod, newFunction)
|
||||||
break
|
# Look through the pending tasks
|
||||||
method = task.__call__
|
for pri, taskList in self.pendingTaskDict.items():
|
||||||
if (type(method) == types.MethodType):
|
for task in taskList:
|
||||||
function = method.im_func
|
numFound += self.__tryReplaceTaskMethod(task, oldMethod, newFunction)
|
||||||
else:
|
# Look through the doLaters
|
||||||
function = method
|
for task in self.__doLaterList:
|
||||||
#print ('function: ' + `function` + '\n' +
|
numFound += self.__tryReplaceTaskMethod(task, oldMethod, newFunction)
|
||||||
# 'method: ' + `method` + '\n' +
|
return numFound
|
||||||
# 'oldMethod: ' + `oldMethod` + '\n' +
|
|
||||||
# 'newFunction: ' + `newFunction` + '\n')
|
|
||||||
if (function == oldMethod):
|
|
||||||
newMethod = new.instancemethod(newFunction,
|
|
||||||
method.im_self,
|
|
||||||
method.im_class)
|
|
||||||
task.__call__ = newMethod
|
|
||||||
# Found it return true
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
taskNameWidth = 32
|
taskNameWidth = 32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user