From c1daa929b82103f90a55e7c6d992b064fba1a639 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 4 Dec 2003 01:21:00 +0000 Subject: [PATCH] only one setZoneMsg per frame --- direct/src/level/DistributedLevel.py | 32 +++++++++++++++++++++++----- direct/src/level/Level.py | 8 +++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/direct/src/level/DistributedLevel.py b/direct/src/level/DistributedLevel.py index 146da5f994..7da6d72b42 100755 --- a/direct/src/level/DistributedLevel.py +++ b/direct/src/level/DistributedLevel.py @@ -26,6 +26,7 @@ class DistributedLevel(DistributedObject.DistributedObject, FloorCollPrefix = 'zoneFloor' OuchTaskName = 'ouchTask' + VisChangeTaskName = 'visChange' def __init__(self, cr): DistributedObject.DistributedObject.__init__(self, cr) @@ -291,6 +292,7 @@ class DistributedLevel(DistributedObject.DistributedObject, if hasattr(self, 'geom'): del self.geom + self.shutdownVisibility() self.destroyLevel() DistributedObject.DistributedObject.disable(self) self.ignoreAll() @@ -393,6 +395,8 @@ class DistributedLevel(DistributedObject.DistributedObject, # we have not entered any zone yet self.curZoneNum = None + self.visChangedThisFrame = 0 + # listen for camera-ray/floor collision events def handleCameraRayFloorCollision(collEntry, self=self): name = collEntry.getIntoNode().getName() @@ -414,6 +418,15 @@ class DistributedLevel(DistributedObject.DistributedObject, zoneNums.remove(LevelConstants.UberZoneNum) self.setVisibility(zoneNums) + # send out any zone changes at the end of the frame, just before + # rendering + taskMgr.add(self.visChangeTask, + self.uniqueName(DistributedLevel.VisChangeTaskName), + priority=49) + + def shutdownVisibility(self): + taskMgr.remove(self.uniqueName(DistributedLevel.VisChangeTaskName)) + def toonEnterZone(self, zoneNum, ouchLevel=None): """ zoneNum is an int. @@ -464,6 +477,7 @@ class DistributedLevel(DistributedObject.DistributedObject, def updateVisibility(self, zoneNum=None): """update the visibility assuming that we're in the specified zone; don't check to see if it's the zone we're already in""" + #print 'updateVisibility %s' % globalClock.getFrameCount() if zoneNum is None: zoneNum = self.curZoneNum @@ -535,6 +549,19 @@ class DistributedLevel(DistributedObject.DistributedObject, # Redo visibility using current zone num self.updateVisibility() + def handleVisChange(self): + """the zone visibility lists have changed on-the-fly""" + Level.Level.handleVisChange(self) + self.visChangedThisFrame = 1 + + def visChangeTask(self, task): + # this runs just before igloop; if viz lists have changed + # this frame, updates the visibility and sends out a setZoneMsg + if self.visChangedThisFrame: + self.updateVisibility() + self.visChangedThisFrame = 0 + return Task.cont + if __debug__: # level editing stuff def setAttribChange(self, entId, attribName, valueStr, username): @@ -543,11 +570,6 @@ class DistributedLevel(DistributedObject.DistributedObject, value = eval(valueStr) self.levelSpec.setAttribChange(entId, attribName, value, username) - def handleVisChange(self): - """the zone visibility lists have changed""" - Level.Level.handleVisChange(self) - self.updateVisibility() - def spawnTitleText(self): def getDescription(zoneId, self=self): entId = self.zoneNum2entId.get(zoneId) diff --git a/direct/src/level/Level.py b/direct/src/level/Level.py index 0b67cf6a10..bac4de0213 100755 --- a/direct/src/level/Level.py +++ b/direct/src/level/Level.py @@ -341,6 +341,10 @@ class Level: # with an editor self.createdEntIds.remove(entId) + def handleVisChange(self): + """the zone visibility lists have changed""" + pass + if __debug__: # the level generates these events when the spec changes def getAttribChangeEventName(self): @@ -380,7 +384,3 @@ class Level: entity.destroy() # update our local type->entId table self.entType2ids[self.getEntityType(entId)].remove(entId) - - def handleVisChange(self): - """the zone visibility lists have changed""" - pass