Browse Source

moving parent zone stuff to collection manager

Dave Schuyler 20 years ago
parent
commit
c28e3a500b

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

@@ -381,35 +381,8 @@ class DistributedObject(PandaObject):
         self.cr.sendSetLocation(self.doId, parentId, zoneId)
 
     def setLocation(self, parentId, zoneId):
-        # Prevent Duplicate SetLocations for being Called
-        if (self.parentId == parentId) and (self.zoneId == zoneId):
-            return
-
-        #self.notify.info("setLocation: %s parentId: %s zoneId: %s" % (self.doId, parentId, zoneId))
-        # parentId can be 'None', e.g. when an object is being disabled
-        oldParentId = self.parentId
-        oldZoneId = self.zoneId
-        parentIsNew = (oldParentId != parentId)
-
-        # notify any existing parent that we're moving away
-        if (oldParentId is not None) and parentIsNew:
-            oldParentObj = self.cr.doId2do.get(oldParentId)
-            if oldParentObj:
-                oldParentObj.handleChildLeave(self, oldZoneId)
-
-        # The store must run first so we know the old location
-        self.parentId = parentId
-        self.zoneId = zoneId
         self.cr.storeObjectLocation(self.doId, parentId, zoneId)
 
-        # 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.
-        if (self.parentId is not None) and parentIsNew:
-            parentObj = self.cr.doId2do.get(parentId)
-            if parentObj:
-                parentObj.handleChildArrive(self, zoneId)
-
     def getLocation(self):
         try:
             if self.parentId == 0 and self.zoneId == 0:

+ 28 - 8
direct/src/distributed/DistributedObjectAI.py

@@ -192,12 +192,9 @@ class DistributedObjectAI(DirectObject):
 
         oldParentId = self.parentId
         oldZoneId = self.zoneId
+        self.air.storeObjectLocation(self.doId, parentId, zoneId)
         if ((oldParentId != parentId) or
             (oldZoneId != zoneId)):
-            #print "%s location is now %s, %s (%s)"%(self.doId, parentId, zoneId, self)
-            self.zoneId = zoneId
-            self.parentId = parentId
-            self.air.changeDOZoneInTables(self, parentId, zoneId, oldParentId, oldZoneId)
             messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId])
             # if we are not going into the quiet zone, send a 'logical' zone
             # change message
@@ -207,7 +204,6 @@ class DistributedObjectAI(DirectObject):
                     lastLogicalZone = self.lastNonQuietZone
                 self.handleLogicalZoneChange(zoneId, lastLogicalZone)
                 self.lastNonQuietZone = zoneId
-        self.air.storeObjectLocation(self.doId, parentId, zoneId)
 
     def getLocation(self):
         try:
@@ -220,6 +216,30 @@ class DistributedObjectAI(DirectObject):
         except AttributeError:
             return None
 
+    def handleChildArrive(self, childObj, zoneId):
+        self.notify.debugCall()
+        # A new child has just setLocation beneath us.  Give us a
+        # chance to run code when a new child sets location to us. For
+        # example, we may want to scene graph reparent the child to
+        # some subnode we own.
+        ## zone=self.children.setdefault(zoneId, {})
+        ## zone[childObj.doId]=childObj
+
+        # Inheritors should override
+        pass
+
+    def handleChildLeave(self, childObj, zoneId):
+        self.notify.debugCall()
+        # A child is about to setLocation away from us.  Give us a
+        # chance to run code just before a child sets location away from us.
+        ## zone=self.children[zoneId]
+        ## del zone[childObj.doId]
+        ## if not len(zone):
+        ##     del self.children[zoneId]
+
+        # Inheritors should override
+        pass
+
     def updateRequiredFields(self, dclass, di):
         dclass.receiveUpdateBroadcastRequired(self, di)
         self.announceGenerate()
@@ -355,9 +375,9 @@ class DistributedObjectAI(DirectObject):
         # Send a generate message
         self.sendGenerateWithRequired(self.air, parentId, zoneId, optionalFields)
 
-        assert not hasattr(self, 'parentId') or self.parentId is None
-        self.parentId = parentId
-        self.zoneId = zoneId
+        ## assert not hasattr(self, 'parentId') or self.parentId is None
+        ## self.parentId = parentId
+        ## self.zoneId = zoneId
         self.generate()
         self.announceGenerate()
 

+ 45 - 22
direct/src/distributed/DoCollectionManager.py

@@ -202,11 +202,34 @@ class DoCollectionManager:
             parentZoneDict = self.__doHierarchy.setdefault(parentId, {})
             zoneDoSet = parentZoneDict.setdefault(zoneId, set())
             zoneDoSet.add(doId)
+            
+            # Set the new parent and zone on the object
+            obj.parentId = parentId
+            obj.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(obj, zoneId)
 
     def deleteObjectLocation(self, doId, parentId, zoneId):
         # Do not worry about null values
         if (parentId is None) or (zoneId is None):
             return
+        if 1:
+            # Do we still need this
+            
+            # notify any existing parent that we're moving away
+            oldParentObj = self.doId2do.get(parentId)
+            obj = self.doId2do.get(doId)
+            if oldParentObj is not None and obj is not None:
+                oldParentObj.handleChildLeave(obj, zoneId)
+
         parentZoneDict = self.__doHierarchy.get(parentId)
         if parentZoneDict is not None:
             zoneDoSet = parentZoneDict.get(zoneId)
@@ -277,28 +300,28 @@ class DoCollectionManager:
         if do.doId in self.doId2do:
             del self.doId2do[do.doId]
         
-    def changeDOZoneInTables(self, do, newParentId, newZoneId, oldParentId, oldZoneId):
-        if 1:
-            self.storeObjectLocation(do.doId, newParentId, newZoneId)
-        else:
-            #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
-            oldLocation = (oldParentId, oldZoneId)
-            newLocation = (newParentId, newZoneId)
-            # HACK: DistributedGuildMemberUD starts in -1,-1, which isnt ever put in the
-            # zoneId2doIds table
-            if self.isValidLocationTuple(oldLocation):
-                assert self.notify.debugStateCall(self)
-                assert oldLocation in self.zoneId2doIds
-                assert do.doId in self.zoneId2doIds[oldLocation]
-                assert do.doId not in self.zoneId2doIds.get(newLocation,{})
-                # remove from old zone
-                del(self.zoneId2doIds[oldLocation][do.doId])
-                if len(self.zoneId2doIds[oldLocation]) == 0:
-                    del self.zoneId2doIds[oldLocation]
-            if self.isValidLocationTuple(newLocation):
-                # add to new zone
-                self.zoneId2doIds.setdefault(newLocation, {})
-                self.zoneId2doIds[newLocation][do.doId]=do
+    ## def changeDOZoneInTables(self, do, newParentId, newZoneId, oldParentId, oldZoneId):
+    ##     if 1:
+    ##         self.storeObjectLocation(do.doId, newParentId, newZoneId)
+    ##     else:
+    ##         #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
+    ##         oldLocation = (oldParentId, oldZoneId)
+    ##         newLocation = (newParentId, newZoneId)
+    ##         # HACK: DistributedGuildMemberUD starts in -1,-1, which isnt ever put in the
+    ##         # zoneId2doIds table
+    ##         if self.isValidLocationTuple(oldLocation):
+    ##             assert self.notify.debugStateCall(self)
+    ##             assert oldLocation in self.zoneId2doIds
+    ##             assert do.doId in self.zoneId2doIds[oldLocation]
+    ##             assert do.doId not in self.zoneId2doIds.get(newLocation,{})
+    ##             # remove from old zone
+    ##             del(self.zoneId2doIds[oldLocation][do.doId])
+    ##             if len(self.zoneId2doIds[oldLocation]) == 0:
+    ##                 del self.zoneId2doIds[oldLocation]
+    ##         if self.isValidLocationTuple(newLocation):
+    ##             # add to new zone
+    ##             self.zoneId2doIds.setdefault(newLocation, {})
+    ##             self.zoneId2doIds[newLocation][do.doId]=do
 
     ## def getObjectsInZone(self, parentId, zoneId):
     ##     """ call this to get a dict of doId:distObj for a zone.