Browse Source

fixing cleanup during alt-f4 exit

Dave Schuyler 22 years ago
parent
commit
8ddf9011d5

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

@@ -36,6 +36,9 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         # The RelatedObjectMgr helps distributed objects find each
         # The RelatedObjectMgr helps distributed objects find each
         # other.
         # other.
         self.relatedObjectMgr = RelatedObjectMgr.RelatedObjectMgr(self)
         self.relatedObjectMgr = RelatedObjectMgr.RelatedObjectMgr(self)
+    
+    def delete(self):
+        self.relatedObjectMgr.destroy()
 
 
     def setServerDelta(self, delta):
     def setServerDelta(self, delta):
         """
         """
@@ -131,32 +134,28 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         if cdc.constructor.neverDisable:
         if cdc.constructor.neverDisable:
             # Create a new distributed object, and put it in the dictionary
             # Create a new distributed object, and put it in the dictionary
             distObj = self.generateWithRequiredOtherFields(cdc, doId, di)
             distObj = self.generateWithRequiredOtherFields(cdc, doId, di)
-        return None
 
 
     def generateWithRequiredFields(self, cdc, doId, di):
     def generateWithRequiredFields(self, cdc, doId, di):
-        # Is it in our dictionary? 
         if self.doId2do.has_key(doId):
         if self.doId2do.has_key(doId):
-            # If so, just update it.
+            # ...it is in our dictionary.
+            # Just update it.
             distObj = self.doId2do[doId]
             distObj = self.doId2do[doId]
             distObj.generate()
             distObj.generate()
             distObj.updateRequiredFields(cdc, di)
             distObj.updateRequiredFields(cdc, di)
             # updateRequiredFields calls announceGenerate
             # 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):
         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)
             distObj = self.cache.retrieve(doId)
-            # put it in both dictionaries...
+            # put it in both dictionaries:
             self.doId2do[doId] = distObj
             self.doId2do[doId] = distObj
             self.doId2cdc[doId] = cdc
             self.doId2cdc[doId] = cdc
             # and update it.
             # and update it.
             distObj.generate()
             distObj.generate()
             distObj.updateRequiredFields(cdc, di)
             distObj.updateRequiredFields(cdc, di)
             # updateRequiredFields calls announceGenerate
             # updateRequiredFields calls announceGenerate
-
-        # If it is not in the dictionary or the cache, then...
         else:
         else:
+            # ...it is not in the dictionary or the cache.
             # Construct a new one
             # Construct a new one
             distObj = cdc.constructor(self)
             distObj = cdc.constructor(self)
             # Assign it an Id
             # Assign it an Id
@@ -169,33 +168,29 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
             distObj.generate()
             distObj.generate()
             distObj.updateRequiredFields(cdc, di)
             distObj.updateRequiredFields(cdc, di)
             # updateRequiredFields calls announceGenerate
             # updateRequiredFields calls announceGenerate
-            
         return distObj
         return distObj
 
 
     def generateWithRequiredOtherFields(self, cdc, doId, di):
     def generateWithRequiredOtherFields(self, cdc, doId, di):
-        # Is it in our dictionary? 
         if self.doId2do.has_key(doId):
         if self.doId2do.has_key(doId):
-            # If so, just update it.
+            # ...it is in our dictionary.
+            # Just update it.
             distObj = self.doId2do[doId]
             distObj = self.doId2do[doId]
             distObj.generate()
             distObj.generate()
             distObj.updateRequiredOtherFields(cdc, di)
             distObj.updateRequiredOtherFields(cdc, di)
             # updateRequiredOtherFields calls announceGenerate
             # 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):
         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)
             distObj = self.cache.retrieve(doId)
-            # put it in both dictionaries...
+            # put it in both dictionaries:
             self.doId2do[doId] = distObj
             self.doId2do[doId] = distObj
             self.doId2cdc[doId] = cdc
             self.doId2cdc[doId] = cdc
             # and update it.
             # and update it.
             distObj.generate()
             distObj.generate()
             distObj.updateRequiredOtherFields(cdc, di)
             distObj.updateRequiredOtherFields(cdc, di)
             # updateRequiredOtherFields calls announceGenerate
             # updateRequiredOtherFields calls announceGenerate
-
-        # If it is not in the dictionary or the cache, then...
         else:
         else:
+            # ...it is not in the dictionary or the cache.
             # Construct a new one
             # Construct a new one
             if cdc.constructor == None:
             if cdc.constructor == None:
                 self.notify.error("Could not create an undefined %s object." % (cdc.name))
                 self.notify.error("Could not create an undefined %s object." % (cdc.name))
@@ -210,7 +205,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
             distObj.generate()
             distObj.generate()
             distObj.updateRequiredOtherFields(cdc, di)
             distObj.updateRequiredOtherFields(cdc, di)
             # updateRequiredOtherFields calls announceGenerate
             # updateRequiredOtherFields calls announceGenerate
-            
         return distObj
         return distObj
 
 
 
 
@@ -219,7 +213,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         doId = di.getArg(STUint32)
         doId = di.getArg(STUint32)
         # disable it.
         # disable it.
         self.disableDoId(doId)
         self.disableDoId(doId)
-        return None
 
 
     def disableDoId(self, doId):
     def disableDoId(self, doId):
          # Make sure the object exists
          # Make sure the object exists
@@ -239,9 +232,10 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
             else:
             else:
                 distObj.deleteOrDelay()
                 distObj.deleteOrDelay()
         else:
         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):
     def handleDelete(self, di):
         # Get the DO Id
         # Get the DO Id
@@ -249,8 +243,7 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
         self.deleteObject(doId)
         self.deleteObject(doId)
 
 
     def deleteObject(self, doId):
     def deleteObject(self, doId):
-        """deleteObject(self, doId)
-
+        """
         Removes the object from the client's view of the world.  This
         Removes the object from the client's view of the world.  This
         should normally not be called except in the case of error
         should normally not be called except in the case of error
         recovery, since the server will normally be responsible for
         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
         The return value may be saved and passed to a future call to
         abortRequest(), in order to abort a pending request before the
         abortRequest(), in order to abort a pending request before the
         timeout expires.
         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)))
         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
         Aborts a previous request.  The parameter is the return value
         from a previous call to requestObjects().  The pending request
         from a previous call to requestObjects().  The pending request
         is removed from the queue and no further callbacks will be called.
         is removed from the queue and no further callbacks will be called.
+        
+        See Also: requestObjects()
         """
         """
         if tuple:
         if tuple:
             allCallback, eachCallback, timeoutCallback, doIdsPending, doIdList, doLaterName = 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)
             self.setVisibility(zoneNums)
 
 
     def toonEnterZone(self, zoneNum, ouchLevel=None):
     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)
         DistributedLevel.notify.debug('toonEnterZone%s' % zoneNum)
 
 
         if zoneNum != self.lastToonZone:
         if zoneNum != self.lastToonZone:
@@ -423,6 +431,13 @@ class DistributedLevel(DistributedObject.DistributedObject,
             messenger.send("factoryZoneChanged", [zoneNum])
             messenger.send("factoryZoneChanged", [zoneNum])
 
 
     def camEnterZone(self, 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)
         DistributedLevel.notify.debug('camEnterZone%s' % zoneNum)
         self.enterZone(zoneNum)
         self.enterZone(zoneNum)
 
 

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

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

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

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