added PropSpinner

This commit is contained in:
Darren Ranalli 2003-11-18 21:45:32 +00:00
parent b1beff0d5c
commit 20350925e3
5 changed files with 71 additions and 8 deletions

View File

@ -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,
})

View File

@ -52,6 +52,7 @@ class EntityCreatorAI(EntityCreatorBase.EntityCreatorBase):
'model' : nothing,
'nodepath': nothing,
'path': nothing,
'propSpinner': nothing,
'visibilityExtender': nothing,
'zone': Functor(cLE, ZoneEntityAI.ZoneEntityAI),
})

View File

@ -116,3 +116,6 @@ class VisibilityExtender(Entity):
('event', None, 'entId', {'output':'bool'}),
('newZones', [], 'visZoneList'),
)
class PropSpinner(Entity):
type = 'propSpinner'

View File

@ -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])

53
direct/src/level/PropSpinner.py Executable file
View File

@ -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()