From e25ab93820f83b6b37f9f2efb7afef94e118ec2c Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Fri, 9 Jan 2004 23:39:12 +0000 Subject: [PATCH] added VisibilityBlocker --- direct/src/level/DistributedLevel.py | 37 --------------------------- direct/src/level/VisibilityBlocker.py | 31 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 37 deletions(-) create mode 100755 direct/src/level/VisibilityBlocker.py diff --git a/direct/src/level/DistributedLevel.py b/direct/src/level/DistributedLevel.py index c8e061c77c..99c83991ff 100755 --- a/direct/src/level/DistributedLevel.py +++ b/direct/src/level/DistributedLevel.py @@ -63,9 +63,6 @@ class DistributedLevel(DistributedObject.DistributedObject, ) self.zonesEnteredList = [] self.fColorZones = 0 - # we use these to track setZone requests - self.setZonesRequested = 0 - self.setZonesReceived = 0 def generate(self): DistributedLevel.notify.debug('generate') @@ -446,10 +443,6 @@ class DistributedLevel(DistributedObject.DistributedObject, self.camEnterZone(zoneNum) self.accept('on-floor', handleCameraRayFloorCollision) - # register our datagram handler to listen for setZone msgs - self.oldTcrHandler = toonbase.tcr.handler - toonbase.tcr.handler = self.handleDatagram - # if no viz, listen to all the zones if not DistributedLevel.WantVisibility: zoneNums = list(self.zoneNums) @@ -465,35 +458,6 @@ class DistributedLevel(DistributedObject.DistributedObject, def shutdownVisibility(self): taskMgr.remove(self.uniqueName(DistributedLevel.VisChangeTaskName)) - if toonbase.tcr.handler == self.handleDatagram: - toonbase.tcr.handler = self.oldTcrHandler - del self.oldTcrHandler - - def getSetZoneCompleteEvent(self, num): - return self.uniqueName('setZoneComplete-%s' % num) - - def getNextSetZoneCompleteEvent(self): - return self.uniqueName('setZoneComplete-%s' % self.setZonesRequested) - - def handleDatagram(self, msgType, di): - if msgType == CLIENT_DONE_SET_ZONE_RESP: - # snoop to see what zone we're talking about - di2 = DatagramIterator(di) - zone = di2.getUint32() - if zone != self.levelZone: - self.notify.warning('got setZoneComplete for unknown zone %s' % - zone) - else: - self.notify.info('setZone #%s complete' % self.setZonesReceived) - messenger.send(self.getSetZoneCompleteEvent( - self.setZonesReceived)) - self.setZonesReceived += 1 - - if self.oldTcrHandler is None: - toonbase.tcr.handleUnexpectedMsgType(msgType, di) - else: - self.oldTcrHandler(msgType, di) - def toonEnterZone(self, zoneNum, ouchLevel=None): """ zoneNum is an int. @@ -628,7 +592,6 @@ class DistributedLevel(DistributedObject.DistributedObject, self.hideZone(rz) self.setVisibility(visibleZoneNums.keys()) - self.setZonesRequested += 1 self.curZoneNum = zoneNum self.curVisibleZoneNums = visibleZoneNums diff --git a/direct/src/level/VisibilityBlocker.py b/direct/src/level/VisibilityBlocker.py new file mode 100755 index 0000000000..ad53cf322a --- /dev/null +++ b/direct/src/level/VisibilityBlocker.py @@ -0,0 +1,31 @@ +"""VisibilityBlocker module: contains the VisibilityBlocker class""" + +import Entity + +class VisibilityBlocker: + """This is a mixin class for level entities (see Entity.py) that in some + way 'block' visibility (such as doors) -- entities that can completely + obscure what's behind them. It provides the blocker with a mechanism + whereby they are informed of when it is safe for them to 'unblock' the + visibility and show what's behind them. Without this mechanism, the + blocker might show what's behind it before all of the distributed objects + behind it have been generated.""" + def __init__(self): + # this may do something in the future; please call down to it + pass + + def destroy(self): + self.ignoreAll() + + def requestUnblockVis(self): + """derived class should call this before the end of the frame in which + they cause the visibility to be extended. okToUnblockVis (see below) + will be called when it's safe to show the new zones.""" + self.accept(self.level.tcr.getNextSetZoneDoneEvent(), + self.okToUnblockVis) + + def okToUnblockVis(self): + """derived class should override this func and do the vis unblock + (i.e. open the door, etc.)""" + # this may do something in the future; please call down to it + pass