Browse Source

fixing cleanup during alt-f4 exit

Dave Schuyler 22 năm trước cách đây
mục cha
commit
8ddf9011d5

+ 20 - 27
direct/src/distributed/ClientRepository.py

@@ -36,6 +36,9 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         # The RelatedObjectMgr helps distributed objects find each
         # other.
         self.relatedObjectMgr = RelatedObjectMgr.RelatedObjectMgr(self)
+    
+    def delete(self):
+        self.relatedObjectMgr.destroy()
 
     def setServerDelta(self, delta):
         """
@@ -131,32 +134,28 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         if cdc.constructor.neverDisable:
             # Create a new distributed object, and put it in the dictionary
             distObj = self.generateWithRequiredOtherFields(cdc, doId, di)
-        return None
 
     def generateWithRequiredFields(self, cdc, doId, di):
-        # Is it in our dictionary? 
         if self.doId2do.has_key(doId):
-            # If so, just update it.
+            # ...it is in our dictionary.
+            # Just update it.
             distObj = self.doId2do[doId]
             distObj.generate()
             distObj.updateRequiredFields(cdc, di)
             # updateRequiredFields calls announceGenerate
-
-        # 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...
+            # ...it is in the cache.
+            # Pull it out of the cache:
             distObj = self.cache.retrieve(doId)
-            # put it in both dictionaries...
+            # put it in both dictionaries:
             self.doId2do[doId] = distObj
             self.doId2cdc[doId] = cdc
             # and update it.
             distObj.generate()
             distObj.updateRequiredFields(cdc, di)
             # updateRequiredFields calls announceGenerate
-
-        # If it is not in the dictionary or the cache, then...
         else:
+            # ...it is not in the dictionary or the cache.
             # Construct a new one
             distObj = cdc.constructor(self)
             # Assign it an Id
@@ -169,33 +168,29 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
             distObj.generate()
             distObj.updateRequiredFields(cdc, di)
             # updateRequiredFields calls announceGenerate
-            
         return distObj
 
     def generateWithRequiredOtherFields(self, cdc, doId, di):
-        # Is it in our dictionary? 
         if self.doId2do.has_key(doId):
-            # If so, just update it.
+            # ...it is in our dictionary.
+            # Just update it.
             distObj = self.doId2do[doId]
             distObj.generate()
             distObj.updateRequiredOtherFields(cdc, di)
             # updateRequiredOtherFields calls announceGenerate
-
-        # 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...
+            # ...it is in the cache.
+            # Pull it out of the cache:
             distObj = self.cache.retrieve(doId)
-            # put it in both dictionaries...
+            # put it in both dictionaries:
             self.doId2do[doId] = distObj
             self.doId2cdc[doId] = cdc
             # and update it.
             distObj.generate()
             distObj.updateRequiredOtherFields(cdc, di)
             # updateRequiredOtherFields calls announceGenerate
-
-        # If it is not in the dictionary or the cache, then...
         else:
+            # ...it is not in the dictionary or the cache.
             # Construct a new one
             if cdc.constructor == None:
                 self.notify.error("Could not create an undefined %s object." % (cdc.name))
@@ -210,7 +205,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
             distObj.generate()
             distObj.updateRequiredOtherFields(cdc, di)
             # updateRequiredOtherFields calls announceGenerate
-            
         return distObj
 
 
@@ -219,7 +213,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         doId = di.getArg(STUint32)
         # disable it.
         self.disableDoId(doId)
-        return None
 
     def disableDoId(self, doId):
          # Make sure the object exists
@@ -239,9 +232,10 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
             else:
                 distObj.deleteOrDelay()
         else:
-            ClientRepository.notify.warning("Disable failed. DistObj " +
-                                            str(doId) +
-                                            " is not in dictionary")
+            ClientRepository.notify.warning(
+                "Disable failed. DistObj "
+                + str(doId) +
+                " is not in dictionary")
 
     def handleDelete(self, di):
         # Get the DO Id
@@ -249,8 +243,7 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         self.deleteObject(doId)
 
     def deleteObject(self, doId):
-        """deleteObject(self, doId)
-
+        """
         Removes the object from the client's view of the world.  This
         should normally not be called except in the case of error
         recovery, since the server will normally be responsible for

+ 11 - 1
direct/src/distributed/RelatedObjectMgr.py

@@ -67,7 +67,15 @@ class RelatedObjectMgr(DirectObject.DirectObject):
         The return value may be saved and passed to a future call to
         abortRequest(), in order to abort a pending request before the
         timeout expires.
-
+        
+        Actually, you should be careful to call abortRequest() if you
+        have made a call to requestObjects() that has not been resolved.
+        To find examples, do a search for abortRequest() to find out 
+        how other code is using it.  A common idiom is to store the 
+        result from requestObjects() and call abortRequest() if delete()
+        or destroy() is called on the requesting object.
+        
+        See Also: abortRequest()
         """
         assert(self.notify.debug("requestObjects(%s, timeout=%s)" % (doIdList, timeout)))
 
@@ -129,6 +137,8 @@ class RelatedObjectMgr(DirectObject.DirectObject):
         Aborts a previous request.  The parameter is the return value
         from a previous call to requestObjects().  The pending request
         is removed from the queue and no further callbacks will be called.
+        
+        See Also: requestObjects()
         """
         if tuple:
             allCallback, eachCallback, timeoutCallback, doIdsPending, doIdList, doLaterName = tuple

+ 15 - 0
direct/src/level/DistributedLevel.py

@@ -415,6 +415,14 @@ class DistributedLevel(DistributedObject.DistributedObject,
             self.setVisibility(zoneNums)
 
     def toonEnterZone(self, zoneNum, ouchLevel=None):
+        """
+        zoneNum is an int.
+        ouchLevel is a ??.
+        
+        The avatar (and not necessarily the camera) has entered
+        a zone.
+        See camEnterZone()
+        """
         DistributedLevel.notify.debug('toonEnterZone%s' % zoneNum)
 
         if zoneNum != self.lastToonZone:
@@ -423,6 +431,13 @@ class DistributedLevel(DistributedObject.DistributedObject,
             messenger.send("factoryZoneChanged", [zoneNum])
 
     def camEnterZone(self, zoneNum):
+        """
+        zoneNum is an int.
+        
+        The camera (and not necessarily the avatar) has entered
+        a zone.
+        See toonEnterZone()
+        """
         DistributedLevel.notify.debug('camEnterZone%s' % zoneNum)
         self.enterZone(zoneNum)
 

+ 2 - 1
direct/src/showbase/Messenger.py

@@ -238,11 +238,12 @@ class Messenger:
         """
         Compact version of event, acceptor pairs
         """
-        str = "="*64 + "\n"
+        str = "The messenger is currently handling:\n" + "="*64 + "\n"
         keys = self.dict.keys()
         keys.sort()
         for event in keys:
             str += self.__eventRepr(event)
+        str += "="*64 + "\n" + "End of messenger info.\n"
         return str
 
     def detailedRepr(self):

+ 7 - 5
direct/src/task/Task.py

@@ -810,13 +810,14 @@ class TaskManager:
         priorityWidth = 10
         totalDt = 0
         totalAvgDt = 0
-        str = ('taskList'.ljust(taskNameWidth)
+        str = "The taskMgr is handling:\n"
+        str += ('taskList'.ljust(taskNameWidth)
                + 'dt(ms)'.rjust(dtWidth)
                + 'avg'.rjust(dtWidth)
                + 'max'.rjust(dtWidth)
                + 'priority'.rjust(priorityWidth)
                + '\n')
-        str = str + '---------------------------------------------------------------\n'
+        str += '---------------------------------------------------------------\n'
         for taskPriList in self.taskList:
             priority = `taskPriList.getPriority()`
             for task in taskPriList:
@@ -843,9 +844,9 @@ class TaskManager:
                                  + '----'.rjust(dtWidth)
                                  + priority.rjust(priorityWidth)
                                  + '\n')
-        str = str + '---------------------------------------------------------------\n'
-        str = str + ' pendingTasks\n'
-        str = str + '---------------------------------------------------------------\n'
+        str += '---------------------------------------------------------------\n'
+        str += ' pendingTasks\n'
+        str += '---------------------------------------------------------------\n'
         for pri, taskList in self.pendingTaskDict.items():
             for task in taskList:
                 remainingTime = ((task.starttime) - self.currentTime)
@@ -892,6 +893,7 @@ class TaskManager:
                          + '----'.rjust(dtWidth)
                          + '----'.rjust(dtWidth)
                          + '\n')
+        str += "End of taskMgr info\n"
         return str
 
     def resetStats(self):