From 6fcdf375ed526d140682aee44bcf43a8aeacbcb0 Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Tue, 20 Mar 2001 02:26:45 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/distributed/ClientDistUpdate.py | 8 +++++++- direct/src/distributed/ClientRepository.py | 22 ++++++++++++++++++++++ direct/src/showbase/Finder.py | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/direct/src/distributed/ClientDistUpdate.py b/direct/src/distributed/ClientDistUpdate.py index a4bc4f2e22..3725d8f6e3 100644 --- a/direct/src/distributed/ClientDistUpdate.py +++ b/direct/src/distributed/ClientDistUpdate.py @@ -4,6 +4,12 @@ import DirectNotifyGlobal import Datagram from MsgTypes import * +# These are stored here so that the distributed classes we load on the fly +# can be exec'ed in the module namespace as if we imported them normally. +# This is important for redefine to work, and is a good idea anyways. +moduleGlobals = globals() +moduleLocals = locals() + class ClientDistUpdate: notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate") @@ -16,7 +22,7 @@ class ClientDistUpdate: self.divisors = [] self.deriveTypesFromParticle(dcField) # Figure out our function pointer - exec("import " + cdc.name) + exec("import " + cdc.name, moduleGlobals, moduleLocals) try: self.func = eval(cdc.name + "." + cdc.name + "." + self.name) # Only catch name and attribute errors diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index 02f1a58390..f1b4072130 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -304,3 +304,25 @@ class ClientRepository(DirectObject.DirectObject): self.cw.send(datagram, self.tcpConn) return None + + def replaceMethod(self, oldMethod, newFunction): + foundIt = 0 + import new + # Iterate over the ClientDistClasses + for cdc in self.number2cdc.values(): + # Iterate over the ClientDistUpdates + for cdu in cdc.allCDU: + method = cdu.func + # See if this is a match + if (method and (method.im_func == oldMethod)): + # Create a new unbound method out of this new function + newMethod = new.instancemethod(newFunction, + method.im_self, + method.im_class) + # Set the new method on the cdu + cdu.func = newMethod + foundIt = 1 + return foundIt + + + diff --git a/direct/src/showbase/Finder.py b/direct/src/showbase/Finder.py index db6e928562..a27082e1fc 100644 --- a/direct/src/showbase/Finder.py +++ b/direct/src/showbase/Finder.py @@ -133,6 +133,7 @@ def copyFuncs(fromClass, toClass): replaceMessengerFunc(oldFunc, newFunc) replaceTaskMgrFunc(oldFunc, newFunc) replaceStateFunc(oldFunc, newFunc) + replaceTcrFunc(oldFunc, newFunc) toClass.__dict__[key] = newFunc def replaceMessengerFunc(oldFunc, newFunc): @@ -154,3 +155,7 @@ def replaceStateFunc(oldFunc, newFunc): if res: print ('replaced state exit function: ' + newFunc.__name__) +def replaceTcrFunc(oldFunc, newFunc): + res = toonbase.tcr.replaceMethod(oldFunc, newFunc) + if res: + print ('replaced DistributedObject function: ' + newFunc.__name__)