瀏覽代碼

make sure we dont do setLocation work if unnecessary

Samir Naik 21 年之前
父節點
當前提交
7e8448cff2
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10 3
      direct/src/distributed/DistributedObjectAI.py

+ 10 - 3
direct/src/distributed/DistributedObjectAI.py

@@ -20,6 +20,9 @@ class DistributedObjectAI(DirectObject.DirectObject):
             self.accountName=''
             # Record the repository
             self.air = air
+            # Record our parentId and zoneId
+            self.__location = None
+            
             # Record our distributed class
             className = self.__class__.__name__
             self.dclass = self.air.dclassesByName[className]
@@ -140,9 +143,13 @@ class DistributedObjectAI(DirectObject.DirectObject):
             self.air.addInterest(self.getDoId(), zoneId, note, event)
 
         def setLocation(self, parentId, zoneId):
-            # The store must run first so we know the old location
-            self.air.sendSetLocation(self, parentId, zoneId)
-            self.__location = (parentId, zoneId)
+            if self.__location:
+                # Make sure our parentId and/or zoneId are actually changing before doing any work
+                oldParentId, oldZoneId = self.__location
+                if oldParentId != parentId or oldZoneId != zoneId:
+                    # The store must run first so we know the old location
+                    self.air.sendSetLocation(self, parentId, zoneId)
+                    self.__location = (parentId, zoneId)
 
         def getLocation(self):
             return self.__location