Beispiel #1
0
 def __handleLevelMgrCreated(self):
     levelMgr = self.getEntity(LevelConstants.LevelMgrEntId)
     self.geom = levelMgr.geom
     self.zoneNum2node = LevelUtil.getZoneNum2Node(self.geom)
     self.zoneNums = self.zoneNum2node.keys()
     self.zoneNums.sort()
     self.zoneNumDict = list2dict(self.zoneNums)
     DistributedLevel.notify.debug('zones from model: %s' % self.zoneNums)
     self.fixupLevelModel()
 def _DistributedLevel__handleLevelMgrCreated(self):
     levelMgr = self.getEntity(LevelConstants.LevelMgrEntId)
     self.geom = levelMgr.geom
     self.zoneNum2node = LevelUtil.getZoneNum2Node(self.geom)
     self.zoneNums = self.zoneNum2node.keys()
     self.zoneNums.sort()
     self.zoneNumDict = list2dict(self.zoneNums)
     DistributedLevel.notify.debug("zones from model: %s" % self.zoneNums)
     self.fixupLevelModel()
Beispiel #3
0
    def __handleLevelMgrCreated(self):
        # as soon as the levelMgr has been created, load up the model
        # and extract zone info. We need to do this before any entities
        # get parented to the level!
        levelMgr = self.getEntity(LevelConstants.LevelMgrEntId)
        self.geom = levelMgr.geom

        # find the zones in the model and fix them up
        self.zoneNum2node = LevelUtil.getZoneNum2Node(self.geom)

        self.zoneNums = self.zoneNum2node.keys()
        self.zoneNums.sort()
        self.zoneNumDict = list2dict(self.zoneNums)
        DistributedLevel.notify.debug('zones from model: %s' % self.zoneNums)

        # give the level a chance to muck with the model before the entities
        # get placed
        self.fixupLevelModel()
Beispiel #4
0
def privUpdateSpec(spec, modelPath, entTypeModule, newZonesGloballyVisible=0):
    """internal: take a spec and update it to match its level model
    If newZonesGloballyVisible is true, any new zones will be added to the
    visibility lists for every zone.
    """
    assert __dev__
    assert type(entTypeModule) is types.ModuleType
    import EntityTypeRegistry
    etr = EntityTypeRegistry.EntityTypeRegistry(entTypeModule)
    spec.setEntityTypeReg(etr)

    if modelPath is None:
        modelPath = spec.getEntitySpec(
            LevelConstants.LevelMgrEntId)['modelFilename']
    else:
        spec.doSetAttrib(LevelConstants.LevelMgrEntId,
                         'modelFilename', modelPath)

    # load the model
    # disable texture loading for speed
    TexturePool.setFakeTextureImage(
        '/i/alpha/player/install/ttmodels/src/fonts/ImpressBT.rgb')
    model = loader.loadModel(modelPath)
    assert model is not None
    TexturePool.clearFakeTextureImage()
    # get the model's zone info
    zoneNum2node = LevelUtil.getZoneNum2Node(model)
    zoneNums = zoneNum2node.keys()

    # what zone entities do we have specs for?
    type2ids = spec.getEntType2ids(spec.getAllEntIds())
    type2ids.setdefault('zone', [])
    zoneEntIds = type2ids['zone']

    def removeZoneEntity(entId, spec=spec, zoneEntIds=zoneEntIds):
        spec.removeEntity(entId)
        zoneEntIds.remove(entId)

    def insertZoneEntity(zoneNum, spec=spec, zoneEntIds=zoneEntIds):
        spec.insertEntity(zoneNum, 'zone', LevelConstants.UberZoneEntId)
        spec.doSetAttrib(zoneNum, 'name', 'zone%s' % zoneNum)
        zoneEntIds.append(zoneNum)

    # prune zone entities that reference zones that no longer exist
    removedZoneNums = []
    for entId in list(zoneEntIds):
        if entId not in zoneNums:
            print 'zone %s no longer exists; removing' % entId
            removeZoneEntity(entId)
            removedZoneNums.append(entId)
            
    # add new zone entities for new zones
    newZoneNums = []
    for zoneNum in zoneNums:
        if zoneNum not in zoneEntIds:
            newZoneNums.append(zoneNum)

            print 'adding new zone entity %s' % zoneNum
            insertZoneEntity(zoneNum)
            # by default, new zone can't see any other zones
            spec.doSetAttrib(zoneNum, 'visibility', [])

    if newZonesGloballyVisible:
        for entId in zoneEntIds:
            visList = list(spec.getEntitySpec(entId)['visibility'])
            visDict = list2dict(visList)
            for zoneNum in newZoneNums:
                visDict[zoneNum] = None
            visList = visDict.keys()
            visList.sort()
            spec.doSetAttrib(entId, 'visibility', visList)

    # make sure none of the zones reference removed zones
    spec.removeZoneReferences(removedZoneNums)