support for multiple levels on single client

This commit is contained in:
Darren Ranalli 2004-12-04 01:49:16 +00:00
parent fde6bcf1ad
commit ebf7be4920
4 changed files with 43 additions and 13 deletions

View File

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

View File

@ -2,16 +2,22 @@
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
# Once a range has been assigned to a user, please don't change it.
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())
@ -20,12 +26,21 @@ undefinedUsername = 'UNDEFINED_USERNAME'
editUsername = config.GetString(usernameConfigVar, undefinedUsername)
# 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
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():
return editUsername

View File

@ -56,6 +56,13 @@ class Entity(DirectObject):
entId = self.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):
"""returns the event generated by an entity; defaults to this entity"""
if entId is None:

View File

@ -251,6 +251,13 @@ class Level:
"""returns the model zoneNum that corresponds to a network 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
# LEVEL
def getLevelPreCreateEvent(self):