Browse Source

print object type when DoHierarchy gets an error

Darren Ranalli 19 years ago
parent
commit
00e0c59f0f

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

@@ -192,7 +192,7 @@ class DistributedObjectAI(DistributedObjectBase):
 
 
         oldParentId = self.parentId
         oldParentId = self.parentId
         oldZoneId = self.zoneId
         oldZoneId = self.zoneId
-        self.air.storeObjectLocation(self.doId, parentId, zoneId)
+        self.air.storeObjectLocation(self, parentId, zoneId)
         if ((oldParentId != parentId) or
         if ((oldParentId != parentId) or
             (oldZoneId != zoneId)):
             (oldZoneId != zoneId)):
             messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId])
             messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId])

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

@@ -172,7 +172,7 @@ class DistributedObjectOV(DistributedObjectBase):
         assert self.notify.debugStateCall(self)
         assert self.notify.debugStateCall(self)
         self.activeState = ESGenerating
         self.activeState = ESGenerating
         # this has already been set at this point
         # this has already been set at this point
-        #self.cr.storeObjectLocation(self.doId, self.parentId, self.zoneId)
+        #self.cr.storeObjectLocation(self, self.parentId, self.zoneId)
 
 
     def generateInit(self):
     def generateInit(self):
         """
         """

+ 2 - 2
direct/src/distributed/DistributedObjectUD.py

@@ -179,7 +179,7 @@ class DistributedObjectUD(DistributedObjectBase):
         self.air.sendSetLocation(self, parentId, zoneId)
         self.air.sendSetLocation(self, parentId, zoneId)
 
 
     def setLocation(self, parentId, zoneId):
     def setLocation(self, parentId, zoneId):
-        self.air.storeObjectLocation(self.doId, parentId, zoneId)
+        self.air.storeObjectLocation(self, parentId, zoneId)
 
 
     def getLocation(self):
     def getLocation(self):
         try:
         try:
@@ -330,7 +330,7 @@ class DistributedObjectUD(DistributedObjectBase):
         other networked info in this function.
         other networked info in this function.
         """
         """
         assert self.notify.debugStateCall(self)
         assert self.notify.debugStateCall(self)
-        self.air.storeObjectLocation(self.doId, self.parentId, self.zoneId)
+        self.air.storeObjectLocation(self, self.parentId, self.zoneId)
 
 
     def generateInit(self, repository=None):
     def generateInit(self, repository=None):
         """
         """

+ 41 - 47
direct/src/distributed/DoCollectionManager.py

@@ -191,48 +191,43 @@ class DoCollectionManager:
         else:
         else:
             self.notify.warning('handleSetLocation: object %s not present' % self.getMsgChannel())
             self.notify.warning('handleSetLocation: object %s not present' % self.getMsgChannel())
 
 
-    def storeObjectLocation(self, doId, parentId, zoneId, object=None):
-        if (object == None):
-            object = self.doId2do.get(doId)
-        if object is None:
-            self.notify.warning('storeObjectLocation: object %s not present' % doId)
-        else:
-            oldParentId = object.parentId
-            oldZoneId = object.zoneId
-            if ((None not in (oldParentId, oldZoneId)) and
-                ((oldParentId != parentId) or (oldZoneId != zoneId))):
-                # Remove old location
-                self.deleteObjectLocation(doId, oldParentId, oldZoneId)
-            elif oldParentId == parentId and oldZoneId == zoneId:
-                # object is already at that parent and zone
-                return
-            if (parentId is None) or (zoneId is None):
-                # Do not store null values
-                return
-            # Add to new location
-            self._doHierarchy.storeObjectLocation(doId, parentId, zoneId)
-            # this check doesn't work because of global UD objects;
-            # should they have a location?
-            #assert len(self._doHierarchy) == len(self.doId2do)
-
-            # Set the new parent and zone on the object
-            object.parentId = parentId
-            object.zoneId = zoneId
-
-            if 1:
-                # Do we still need this
-                if oldParentId != parentId:
-                    # Give the parent a chance to run code when a new child
-                    # sets location to it. For example, the parent may want to
-                    # scene graph reparent the child to some subnode it owns.
-                    parentObj = self.doId2do.get(parentId)
-                    if parentObj is not None:
-                        parentObj.handleChildArrive(object, zoneId)
-                    elif parentId not in (0, self.getGameDoId()):
-                        self.notify.warning('storeObjectLocation(%s): parent %s not present' %
-                                            (doId, parentId))
+    def storeObjectLocation(self, object, parentId, zoneId):
+        oldParentId = object.parentId
+        oldZoneId = object.zoneId
+        if ((None not in (oldParentId, oldZoneId)) and
+            ((oldParentId != parentId) or (oldZoneId != zoneId))):
+            # Remove old location
+            self.deleteObjectLocation(object, oldParentId, oldZoneId)
+        elif oldParentId == parentId and oldZoneId == zoneId:
+            # object is already at that parent and zone
+            return
+        if (parentId is None) or (zoneId is None):
+            # Do not store null values
+            return
+        # Add to new location
+        self._doHierarchy.storeObjectLocation(object, parentId, zoneId)
+        # this check doesn't work because of global UD objects;
+        # should they have a location?
+        #assert len(self._doHierarchy) == len(self.doId2do)
+
+        # Set the new parent and zone on the object
+        object.parentId = parentId
+        object.zoneId = zoneId
+
+        if 1:
+            # Do we still need this
+            if oldParentId != parentId:
+                # Give the parent a chance to run code when a new child
+                # sets location to it. For example, the parent may want to
+                # scene graph reparent the child to some subnode it owns.
+                parentObj = self.doId2do.get(parentId)
+                if parentObj is not None:
+                    parentObj.handleChildArrive(object, zoneId)
+                elif parentId not in (0, self.getGameDoId()):
+                    self.notify.warning('storeObjectLocation(%s): parent %s not present' %
+                                        (doId, parentId))
             
             
-    def deleteObjectLocation(self, doId, parentId, zoneId):
+    def deleteObjectLocation(self, object, parentId, zoneId):
         # Do not worry about null values
         # Do not worry about null values
         if (parentId is None) or (zoneId is None):
         if (parentId is None) or (zoneId is None):
             return
             return
@@ -241,11 +236,10 @@ class DoCollectionManager:
 
 
             # notify any existing parent that we're moving away
             # notify any existing parent that we're moving away
             oldParentObj = self.doId2do.get(parentId)
             oldParentObj = self.doId2do.get(parentId)
-            obj = self.doId2do.get(doId)
-            if oldParentObj is not None and obj is not None:
-                oldParentObj.handleChildLeave(obj, zoneId)
+            if oldParentObj is not None:
+                oldParentObj.handleChildLeave(object, zoneId)
 
 
-        self._doHierarchy.deleteObjectLocation(doId, parentId, zoneId)
+        self._doHierarchy.deleteObjectLocation(object, parentId, zoneId)
 
 
     def addDOToTables(self, do, location=None, ownerView=False):
     def addDOToTables(self, do, location=None, ownerView=False):
         assert self.notify.debugStateCall(self)
         assert self.notify.debugStateCall(self)
@@ -270,7 +264,7 @@ class DoCollectionManager:
 
 
         if not ownerView:
         if not ownerView:
             if self.isValidLocationTuple(location):
             if self.isValidLocationTuple(location):
-                self.storeObjectLocation(do.doId, location[0], location[1])
+                self.storeObjectLocation(do, location[0], location[1])
                 ##assert do.doId not in self.zoneId2doIds.get(location, {})
                 ##assert do.doId not in self.zoneId2doIds.get(location, {})
                 ##self.zoneId2doIds.setdefault(location, {})
                 ##self.zoneId2doIds.setdefault(location, {})
                 ##self.zoneId2doIds[location][do.doId]=do
                 ##self.zoneId2doIds[location][do.doId]=do
@@ -289,7 +283,7 @@ class DoCollectionManager:
         assert self.notify.debugStateCall(self)
         assert self.notify.debugStateCall(self)
         #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
         #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
         #assert do.doId in self.doId2do
         #assert do.doId in self.doId2do
-        self.deleteObjectLocation(do.doId, do.parentId, do.zoneId)
+        self.deleteObjectLocation(do, do.parentId, do.zoneId)
         ## location = do.getLocation()
         ## location = do.getLocation()
         ## if location is not None:
         ## if location is not None:
         ##     if location not in self.zoneId2doIds:
         ##     if location not in self.zoneId2doIds:

+ 12 - 4
direct/src/distributed/DoHierarchy.py

@@ -58,17 +58,25 @@ class DoHierarchy:
             r = a
             r = a
         return r
         return r
 
 
-    def storeObjectLocation(self, doId, parentId, zoneId):
+    def storeObjectLocation(self, do, parentId, zoneId):
         assert self.notify.debugCall()
         assert self.notify.debugCall()
-        assert doId not in self._allDoIds
+        doId = do.doId
+        if doId in self._allDoIds:
+            self.notify.error(
+                'storeObjectLocation(%s %s) already in _allDoIds' % (
+                do.__class__.__name__, do.doId))
         parentZoneDict = self._table.setdefault(parentId, {})
         parentZoneDict = self._table.setdefault(parentId, {})
         zoneDoSet = parentZoneDict.setdefault(zoneId, set())
         zoneDoSet = parentZoneDict.setdefault(zoneId, set())
         zoneDoSet.add(doId)
         zoneDoSet.add(doId)
         self._allDoIds.add(doId)
         self._allDoIds.add(doId)
 
 
-    def deleteObjectLocation(self, doId, parentId, zoneId):
+    def deleteObjectLocation(self, do, parentId, zoneId):
         assert self.notify.debugCall()
         assert self.notify.debugCall()
-        #assert doId in self._allDoIds
+        doId = do.doId
+        if doId not in self._allDoIds:
+            self.notify.warning(
+                'deleteObjectLocation(%s %s) not in _allDoIds' % (
+                do.__class__.__name__, do.doId))
         # jbutler: temp hack to get by the assert, this will be fixed soon
         # jbutler: temp hack to get by the assert, this will be fixed soon
         if (doId not in self._allDoIds):
         if (doId not in self._allDoIds):
             return
             return