From 20350925e384db12827b8f1bf7e31e6a541f6e99 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Tue, 18 Nov 2003 21:45:32 +0000 Subject: [PATCH] added PropSpinner --- direct/src/level/EntityCreator.py | 2 ++ direct/src/level/EntityCreatorAI.py | 1 + direct/src/level/EntityTypes.py | 3 ++ direct/src/level/Level.py | 20 ++++++----- direct/src/level/PropSpinner.py | 53 +++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100755 direct/src/level/PropSpinner.py diff --git a/direct/src/level/EntityCreator.py b/direct/src/level/EntityCreator.py index 06b278a749..c52c2bc7bb 100755 --- a/direct/src/level/EntityCreator.py +++ b/direct/src/level/EntityCreator.py @@ -12,6 +12,7 @@ import ZoneEntity import ModelEntity import PathEntity import VisibilityExtender +import PropSpinner # some useful constructor functions # ctor functions must take (level, entId) @@ -39,6 +40,7 @@ class EntityCreator(EntityCreatorBase.EntityCreatorBase): 'model' : ModelEntity.ModelEntity, 'nodepath': BasicEntities.NodePathEntity, 'path' : PathEntity.PathEntity, + 'propSpinner' : PropSpinner.PropSpinner, 'visibilityExtender': VisibilityExtender.VisibilityExtender, 'zone': ZoneEntity.ZoneEntity, }) diff --git a/direct/src/level/EntityCreatorAI.py b/direct/src/level/EntityCreatorAI.py index c7eeb81848..7cf01498f7 100755 --- a/direct/src/level/EntityCreatorAI.py +++ b/direct/src/level/EntityCreatorAI.py @@ -52,6 +52,7 @@ class EntityCreatorAI(EntityCreatorBase.EntityCreatorBase): 'model' : nothing, 'nodepath': nothing, 'path': nothing, + 'propSpinner': nothing, 'visibilityExtender': nothing, 'zone': Functor(cLE, ZoneEntityAI.ZoneEntityAI), }) diff --git a/direct/src/level/EntityTypes.py b/direct/src/level/EntityTypes.py index 69b41a9c7a..2e1991fa82 100755 --- a/direct/src/level/EntityTypes.py +++ b/direct/src/level/EntityTypes.py @@ -116,3 +116,6 @@ class VisibilityExtender(Entity): ('event', None, 'entId', {'output':'bool'}), ('newZones', [], 'visZoneList'), ) + +class PropSpinner(Entity): + type = 'propSpinner' diff --git a/direct/src/level/Level.py b/direct/src/level/Level.py index d4efc43c2d..29754468d9 100755 --- a/direct/src/level/Level.py +++ b/direct/src/level/Level.py @@ -49,10 +49,6 @@ class Level: # create some handy tables - # entity type -> list of entIds - self.entType2ids = self.levelSpec.getEntType2ids( - self.levelSpec.getAllEntIds()) - # entranceId to entrance entity self.entranceId2entity = {} @@ -65,9 +61,18 @@ class Level: # get an entity creator object self.entityCreator = self.createEntityCreator() + + # entity type -> list of entIds + self.entType2ids = self.levelSpec.getEntType2ids( + self.levelSpec.getAllEntIds()) + # create empty list for any entity types that are not represented + # in the spec + for entType in self.entityCreator.getEntityTypes(): + self.entType2ids.setdefault(entType, []) + # create all the entities # TODO: maybe we should leave this to a subclass or the level user - self.createAllEntities(priorityTypes=['levelMgr','zone']) + self.createAllEntities(priorityTypes=['levelMgr','zone','propSpinner']) # check on the singleton entities # we make our own references to them rather than expect them to @@ -116,7 +121,7 @@ class Level: self.entities = {} # get list of all entity types we need to create - entTypes = self.entType2ids.keys() + entTypes = self.entityCreator.getEntityTypes() self.onLevelPreCreate() @@ -149,7 +154,7 @@ class Level: def createAllEntitiesOfType(self, entType): """creates all entities of a given type""" - assert entType in self.entType2ids + assert entType in self.entityCreator.getEntityTypes() self.onEntityTypePreCreate(entType) @@ -357,7 +362,6 @@ class Level: def handleEntityInsert(self, entId): # update our local type->entId table - self.entType2ids.setdefault(self.getEntityType(entId), []) self.entType2ids[self.getEntityType(entId)].append(entId) self.createEntity(entId) messenger.send(self.getInsertEntityEventName(), [entId]) diff --git a/direct/src/level/PropSpinner.py b/direct/src/level/PropSpinner.py new file mode 100755 index 0000000000..0d77e4e3cc --- /dev/null +++ b/direct/src/level/PropSpinner.py @@ -0,0 +1,53 @@ +from IntervalGlobal import * +import Entity + +class PropSpinner(Entity.Entity): + def __init__(self, level, entId): + Entity.Entity.__init__(self, level, entId) + self.initProps() + + def destroy(self): + self.destroyProps() + Entity.Entity.destroy(self) + + def initProps(self): + topNode = self.getZoneNode() + props = topNode.findAllMatches("**/Prop_*").asList() + spinTracks = Parallel() + for prop in props: + name = prop.getName() + nameParts = name.split('_') + # ['Prop', 'Rotate', 'Y', '15', 'Gear2'] + axis = nameParts[2] + rate = 0 + neg = (string.upper(nameParts[3][0]) == 'N') + if neg: + nameParts[3] = nameParts[3][1:] + try: + rate = int(nameParts[3]) + except: + print 'invalid prop rotate string: %s' % name + if neg: + rate = -rate + prop.setHpr(0,0,0) + if axis == "X": + hpr = Vec3(0, rate*360, 0) + elif axis == "Y": + hpr = Vec3(rate*360, 0, 0) + elif axis == "Z": + hpr = Vec3(0, 0, rate*360) + else: + print 'error', axis + spinTracks.append(LerpHprInterval(prop, 60, hpr)) + spinTracks.loop() + self.spinTracks = spinTracks + + def destroyProps(self): + if hasattr(self, 'spinTracks'): + self.spinTracks.pause() + del self.spinTracks + + if __debug__: + def attribChanged(self, *args): + self.destroyProps() + self.initProps()