ソースを参照

*** empty log message ***

Jesse Schell 25 年 前
コミット
bd9709a8a4

+ 1 - 1
direct/src/distributed/ClientDistClass.py

@@ -45,7 +45,7 @@ class ClientDistClass:
         for i in allCDU:
             atom = i.field.asAtomicField()
             if atom:
-                if atom.isRequired():
+                if (atom.isRequired() and atom.isBroadcast()):
                     requiredCDU.append(i)
         return requiredCDU
 

+ 10 - 16
direct/src/distributed/ClientDistUpdate.py

@@ -36,23 +36,17 @@ class ClientDistUpdate:
         return None
 
     def updateField(self, cdc, do, di):
-        # Look up the class
-        #aClass = eval(cdc.name + "." + cdc.name)
-        # Look up the function
-        #assert(aClass.__dict__.has_key(self.name))
-        #func = aClass.__dict__[self.name]
 
-        # HACK HACK HACK HACK!!!!!
-        try:
-            do.LocalToon_initialized
-        except:
-            func = eval(cdc.name + "." + cdc.name + "." + self.name)
-            print("Calling: " + cdc.name + "." + cdc.name + "." + self.name +
-                  " for do " + str(do.getDoId()))
-            # Get the arguments into a list
-            args = self.extractArgs(di)
-            # Apply the function to the object with the arguments
-            apply(func, [do] + args)
+        func = eval(cdc.name + "." + cdc.name + "." + self.name)
+        #print("Calling: " + cdc.name + "." + cdc.name + "." + self.name +
+        #      " for do " + str(do.getDoId()))
+
+        # Get the arguments into a list
+        args = self.extractArgs(di)
+
+        # Apply the function to the object with the arguments
+        apply(func, [do] + args)
+
         return None
 
     def extractArgs(self, di):

+ 57 - 11
direct/src/distributed/ClientRepository.py

@@ -45,10 +45,15 @@ class ClientRepository(DirectObject.DirectObject):
         self.qcm=QueuedConnectionManager()
         self.tcpConn = self.qcm.openTCPClientConnection(
             serverName, serverPort, 1000)
-        self.qcr=QueuedConnectionReader(self.qcm, 0)
-        self.qcr.addConnection(self.tcpConn)
-        self.cw=ConnectionWriter(self.qcm, 0)
-        self.startReaderPollTask()
+        # Test for bad connection
+        if self.tcpConn == None:
+            return None
+        else:
+            self.qcr=QueuedConnectionReader(self.qcm, 0)
+            self.qcr.addConnection(self.tcpConn)
+            self.cw=ConnectionWriter(self.qcm, 0)
+            self.startReaderPollTask()
+            return self.tcpConn
 
     def startReaderPollTask(self):
         task = Task.Task(self.readerPollUntilEmpty)
@@ -92,14 +97,22 @@ class ClientRepository(DirectObject.DirectObject):
                                                   doId, di)
         return None
 
-    def generateWithRequiredFields(self, cdc, constructor, doId, di):
-        # Someday, this function will look in a cache of old distributed
-        # objects to see if this object is in there, and pull it
-        # out if necessary. For now, we'll just check to see if
-        # it is in the standard dictionary, and ignore this update
-        # if it is there. The right thing to do would be to update
-        # all the required fields, but that will come later, too.
+    def handleGenerateWithRequiredOther(self, di):
+        # Get the class Id
+        classId = di.getArg(STUint16);
+        # Get the DO Id
+        doId = di.getArg(STUint32)
+        # Look up the cdc
+        cdc = self.number2cdc[classId]
+        # Create a new distributed object, and put it in the dictionary
+        distObj = self.generateWithRequiredOtherFields(cdc,
+                                                       eval(cdc.name + \
+                                                            "." + \
+                                                            cdc.name),
+                                                       doId, di)
+        return None
 
+    def generateWithRequiredFields(self, cdc, constructor, doId, di):
         # Is it in our dictionary? 
         if self.doId2do.has_key(doId):
             # If so, just update it.
@@ -131,6 +144,39 @@ class ClientRepository(DirectObject.DirectObject):
             
         return distObj
 
+    def generateWithRequiredOtherFields(self, cdc, constructor, doId, di):
+        # Is it in our dictionary? 
+        if self.doId2do.has_key(doId):
+            # If so, just update it.
+            distObj = self.doId2do[doId]
+            distObj.updateRequiredOtherFields(cdc, di)
+
+        # Is it in the cache? If so, pull it out, put it in the dictionaries,
+        # and update it.
+        elif self.cache.contains(doId):
+            # If so, pull it out of the cache...
+            distObj = self.cache.retrieve(doId)
+            # put it in both dictionaries...
+            self.doId2do[doId] = distObj
+            self.doId2cdc[doId] = cdc
+            # and update it.
+            distObj.updateRequiredOtherFields(cdc, di)
+
+        # If it is not in the dictionary or the cache, then...
+        else:
+            # Construct a new one
+            distObj = constructor(self)
+            # Assign it an Id
+            distObj.doId = doId
+            # Update the required fields
+            distObj.updateRequiredOtherFields(cdc, di)
+            # Put the new do in both dictionaries
+            self.doId2do[doId] = distObj
+            self.doId2cdc[doId] = cdc
+            
+        return distObj
+
+
     def handleDisable(self, di):
         # Get the DO Id
         doId = di.getArg(STUint32)

+ 5 - 1
direct/src/distributed/DistributedNode.py

@@ -16,9 +16,13 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
         return None
 
     def disable(self):
-        self.reparent(hidden)
+        self.reparentTo(hidden)
         DistributedObject.DistributedObject.disable(self)
 
+    def delete(self):
+        self.reparentTo(hidden)
+        DistributedObject.DistributedObject.delete(self)
+
     def d_setPos(self, x, y, z):
         self.sendUpdate("setPos", [x, y, z])
 

+ 11 - 0
direct/src/distributed/DistributedObject.py

@@ -35,6 +35,17 @@ class DistributedObject(PandaObject):
         for i in cdc.allRequiredCDU:
             i.updateField(cdc, self, di)
 
+    def updateRequiredOtherFields(self, cdc, di):
+        # First, update the required fields
+        for i in cdc.allRequiredCDU:
+            i.updateField(cdc, self, di)
+        # Determine how many other fields there are
+        numberOfOtherFields = di.getArg(STUint16)
+        # Update each of the other fields
+        for i in range(numberOfOtherFields):
+            cdc.updateField(self, di)
+        return None
+
     def sendUpdate(self, fieldName, args):
         self.cr.sendUpdate(self, fieldName, args)