浏览代码

better entTypeReg hash

Darren Ranalli 22 年之前
父节点
当前提交
8a061a7f81

+ 1 - 1
direct/src/level/DistributedLevel.py

@@ -136,7 +136,7 @@ class DistributedLevel(DistributedObject.DistributedObject,
             self.candidateSpec = levelSpec
             self.sendUpdate('requestCurrentLevelSpec',
                             [hash(levelSpec),
-                             hash(levelSpec.entTypeReg)])
+                             levelSpec.entTypeReg.getHashStr()])
         else:
             self.privGotSpec(levelSpec)
 

+ 5 - 1
direct/src/level/DistributedLevelAI.py

@@ -180,10 +180,14 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
         def requestCurrentLevelSpec(self, specHash, entTypeRegHash):
             senderId = self.air.msgSender
 
+            self.notify.info('av %s: specHash %s, entTypeRegHash %s' %
+                             (senderId, specHash, entTypeRegHash))
+
             # first check the typeReg hash -- if it doesn't match, the
             # client should not be connecting. Their entityTypeRegistry
             # is different from ours.
-            srvHash = hash(self.levelSpec.entTypeReg)
+            srvHash = self.levelSpec.entTypeReg.getHashStr()
+            self.notify.info('srv entTypeRegHash %s' % srvHash)
             if srvHash != entTypeRegHash:
                 self.sendUpdateToAvatarId(
                     senderId, 'setSpecDeny',

+ 19 - 0
direct/src/level/EntityTypeRegistry.py

@@ -1,5 +1,6 @@
 """EntityTypeRegistry module: contains the EntityTypeRegistry class"""
 
+from PandaModules import *
 import DirectNotifyGlobal
 import types
 import AttribDesc
@@ -12,6 +13,19 @@ class EntityTypeRegistry:
     def __init__(self, entityTypeModule):
         """pass in a module that contains EntityTypeDesc classes"""
         self.entTypeModule = entityTypeModule
+
+        # compute the hash of the source modules as of the time of creation
+        hv = HashVal()
+        import EntityTypes
+        reload(EntityTypes)
+        reload(self.entTypeModule)
+        hv.hashFile(Filename.fromOsSpecific(EntityTypes.__file__))
+        s = str(hv.asHex())
+        s += '.'
+        hv.hashFile(Filename.fromOsSpecific(self.entTypeModule.__file__))
+        s += str(hv.asHex())
+        self.hashStr = s
+
         # get a list of the EntityTypeDesc classes in the type module
         classes = []
         for key, value in entityTypeModule.__dict__.items():
@@ -92,7 +106,12 @@ class EntityTypeRegistry:
     def getPermanentTypeNames(self):
         return self.permanentTypeNames
 
+    def getHashStr(self):
+        return self.hashStr
+
     def __hash__(self):
+        # THIS IS NOT GUARANTEED TO PRODUCE THE SAME VALUE ACROSS DIFFERENT
+        # MACHINES; use getHashStr instead
         return hash(repr(self))
     def __repr__(self):
         # this is used to produce a hash value