2
0
Эх сурвалжийг харах

support for multiple levels on single client

Darren Ranalli 21 жил өмнө
parent
commit
ebf7be4920

+ 2 - 1
direct/src/level/DistributedEntityAI.py

@@ -39,4 +39,5 @@ class DistributedEntityAI(DistributedObjectAI.DistributedObjectAI,
             self.parentEntId = parentEntId
             self.parentEntId = parentEntId
             # switch to new zone
             # switch to new zone
             newZoneId = self.getZoneEntity().getZoneId()
             newZoneId = self.getZoneEntity().getZoneId()
-            self.sendSetZone(newZoneId)
+            if newZoneId != self.zoneId:
+                self.sendSetZone(newZoneId)

+ 27 - 12
direct/src/level/EditorGlobals.py

@@ -2,16 +2,22 @@
 
 
 from direct.showbase.PythonUtil import uniqueElements
 from direct.showbase.PythonUtil import uniqueElements
 
 
+# levels should put themselves into the bboard under this posting
+# to assert themselves as the level to be edited by ~edit
+EditTargetPostName = 'inGameEditTarget'
+
 EntIdRange = 10000
 EntIdRange = 10000
 # Once a range has been assigned to a user, please don't change it.
 # Once a range has been assigned to a user, please don't change it.
 username2entIdBase = {
 username2entIdBase = {
-    'darren': 1*EntIdRange,
-    'samir':  2*EntIdRange,
-    'skyler': 3*EntIdRange,
-    'joe':    4*EntIdRange,
-    'DrEvil': 5*EntIdRange,
-    'asad':   6*EntIdRange,
-    'drose':  7*EntIdRange,
+    'darren':   1*EntIdRange,
+    'samir':    2*EntIdRange,
+    'skyler':   3*EntIdRange,
+    'joe':      4*EntIdRange,
+    'DrEvil':   5*EntIdRange,
+    'asad':     6*EntIdRange,
+    'drose':    7*EntIdRange,
+    'pappy':    8*EntIdRange,
+    'patricia': 9*EntIdRange,
     }
     }
 assert uniqueElements(username2entIdBase.values())
 assert uniqueElements(username2entIdBase.values())
 
 
@@ -20,12 +26,21 @@ undefinedUsername = 'UNDEFINED_USERNAME'
 editUsername = config.GetString(usernameConfigVar, undefinedUsername)
 editUsername = config.GetString(usernameConfigVar, undefinedUsername)
 
 
 # call this to make sure things have been set up correctly
 # call this to make sure things have been set up correctly
-def assertReadyToEdit():
-    assert editUsername != undefinedUsername, (
-        "you must config '%s'; see %s.py" % (usernameConfigVar, __name__))
+def checkNotReadyToEdit():
+    # returns error string if not ready, None if ready
+    if editUsername == undefinedUsername:
+        return "you must config '%s'; see %s.py" % (
+            usernameConfigVar, __name__)
     # Feel free to add your name to the table if it's not in there
     # Feel free to add your name to the table if it's not in there
-    assert editUsername in username2entIdBase, (
-        "unknown editor username '%s'; see %s.py" % (editUsername, __name__))
+    if editUsername not in username2entIdBase:
+        return "unknown editor username '%s'; see %s.py" % (
+            editUsername, __name__)
+    return None
+
+def assertReadyToEdit():
+    msg = checkNotReadyToEdit()
+    if msg is not None:
+        assert False, msg
 
 
 def getEditUsername():
 def getEditUsername():
     return editUsername
     return editUsername

+ 7 - 0
direct/src/level/Entity.py

@@ -56,6 +56,13 @@ class Entity(DirectObject):
             entId = self.entId
             entId = self.entId
         return '%s-%s-%s' % (name, self.level.levelId, entId)
         return '%s-%s-%s' % (name, self.level.levelId, entId)
 
 
+    def getParentToken(self):
+        """returns a value that uniquely identifies this entity for purposes
+        of distributed parenting"""
+        # give the level the option of modifying our entId, to handle instances
+        # where there are multiple levels present on the client simultaneously
+        return self.level.getParentTokenForEntity(self.entId)
+
     def getOutputEventName(self, entId=None):
     def getOutputEventName(self, entId=None):
         """returns the event generated by an entity; defaults to this entity"""
         """returns the event generated by an entity; defaults to this entity"""
         if entId is None:
         if entId is None:

+ 7 - 0
direct/src/level/Level.py

@@ -251,6 +251,13 @@ class Level:
         """returns the model zoneNum that corresponds to a network zoneId"""
         """returns the model zoneNum that corresponds to a network zoneId"""
         return self.zoneId2zoneNum[zoneId]
         return self.zoneId2zoneNum[zoneId]
 
 
+    def getParentTokenForEntity(self, entId):
+        """returns a unique parent token for this entity"""
+        # default impl
+        # subclasses can override to allow for multiple levels present
+        # on the client simultaneously
+        return entId
+
     # these events are thrown as the level initializes itself
     # these events are thrown as the level initializes itself
     # LEVEL
     # LEVEL
     def getLevelPreCreateEvent(self):
     def getLevelPreCreateEvent(self):