From ec3bb127cdf0aa4337c2067150ad9a3ee6bd5285 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 5 Feb 2004 23:59:44 +0000 Subject: [PATCH] fixed door-not-opening bug --- direct/src/level/DistributedLevel.py | 75 ++++++++++++++------------- direct/src/level/VisibilityBlocker.py | 24 ++++++--- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/direct/src/level/DistributedLevel.py b/direct/src/level/DistributedLevel.py index 559905b888..7daba0f7e3 100755 --- a/direct/src/level/DistributedLevel.py +++ b/direct/src/level/DistributedLevel.py @@ -23,7 +23,6 @@ class DistributedLevel(DistributedObject.DistributedObject, notify = DirectNotifyGlobal.directNotify.newCategory('DistributedLevel') WantVisibility = config.GetBool('level-visibility', 1) - HideZones = config.GetBool('level-hidezones', 1) # set this to true to get all distrib objs when showing hidden zones ColorZonesAllDOs = 0 @@ -435,7 +434,7 @@ class DistributedLevel(DistributedObject.DistributedObject, self.curZoneNum = None self.visChangedThisFrame = 0 - self.sentFirstSetZone = 0 + self.fForceSetZoneThisFrame = 0 # listen for camera-ray/floor collision events def handleCameraRayFloorCollision(collEntry, self=self): @@ -457,6 +456,8 @@ class DistributedLevel(DistributedObject.DistributedObject, if not DistributedLevel.WantVisibility: zoneNums = list(self.zoneNums) zoneNums.remove(LevelConstants.UberZoneEntId) + # make sure a setZone goes out on the first frame + self.forceSetZoneThisFrame() self.setVisibility(zoneNums) # send out any zone changes at the end of the frame, just before @@ -579,45 +580,43 @@ class DistributedLevel(DistributedObject.DistributedObject, # this flag will prevent a network msg from being sent if # the list of visible zones has not changed vizZonesChanged = 1 - if DistributedLevel.HideZones: - # figure out which zones are new and which are going invisible - # use dicts because it's faster to use dict.has_key(x) - # than 'x in list' - addedZoneNums = [] - removedZoneNums = [] - allVZ = dict(visibleZoneNums) - allVZ.update(self.curVisibleZoneNums) - for vz,dummy in allVZ.items(): - new = vz in visibleZoneNums - old = vz in self.curVisibleZoneNums - if new and old: - continue - if new: - addedZoneNums.append(vz) - else: - removedZoneNums.append(vz) - - if (not addedZoneNums) and (not removedZoneNums): - DistributedLevel.notify.info( - 'visible zone list has not changed') - vizZonesChanged = 0 + # figure out which zones are new and which are going invisible + # use dicts because 'x in dict' is faster than 'x in list' + addedZoneNums = [] + removedZoneNums = [] + allVZ = dict(visibleZoneNums) + allVZ.update(self.curVisibleZoneNums) + for vz,dummy in allVZ.items(): + new = vz in visibleZoneNums + old = vz in self.curVisibleZoneNums + if new and old: + continue + if new: + addedZoneNums.append(vz) else: - # show the new, hide the old - DistributedLevel.notify.info('showing zones %s' % - addedZoneNums) - for az in addedZoneNums: - self.showZone(az) - DistributedLevel.notify.info('hiding zones %s' % - removedZoneNums) - for rz in removedZoneNums: - self.hideZone(rz) + removedZoneNums.append(vz) + + if (not addedZoneNums) and (not removedZoneNums): + DistributedLevel.notify.info( + 'visible zone list has not changed') + vizZonesChanged = 0 + else: + # show the new, hide the old + DistributedLevel.notify.info('showing zones %s' % + addedZoneNums) + for az in addedZoneNums: + self.showZone(az) + DistributedLevel.notify.info('hiding zones %s' % + removedZoneNums) + for rz in removedZoneNums: + self.hideZone(rz) # it's important for us to send a setZone request on the first # frame, whether or not the visibility is different from what # we already have - if vizZonesChanged or not self.sentFirstSetZone: + if vizZonesChanged or self.fForceSetZoneThisFrame: self.setVisibility(visibleZoneNums.keys()) - self.sentFirstSetZone = 1 + self.fForceSetZoneThisFrame = 0 self.curZoneNum = zoneNum self.curVisibleZoneNums = visibleZoneNums @@ -660,10 +659,14 @@ class DistributedLevel(DistributedObject.DistributedObject, Level.Level.handleVisChange(self) self.visChangedThisFrame = 1 + def forceSetZoneThisFrame(self): + # call this to ensure that a setZone call will be generated this frame + self.fForceSetZoneThisFrame = 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: + if self.visChangedThisFrame or self.fForceSetZoneThisFrame: self.updateVisibility() self.visChangedThisFrame = 0 return Task.cont diff --git a/direct/src/level/VisibilityBlocker.py b/direct/src/level/VisibilityBlocker.py index 8bf9a2af11..135b249fd4 100755 --- a/direct/src/level/VisibilityBlocker.py +++ b/direct/src/level/VisibilityBlocker.py @@ -22,21 +22,31 @@ class VisibilityBlocker: will be called when it's safe to show the new zones.""" if self.__nextSetZoneDoneEvent is None: self.__nextSetZoneDoneEvent = self.level.cr.getNextSetZoneDoneEvent() - self.accept(self.__nextSetZoneDoneEvent, self.okToUnblockVis) + self.acceptOnce(self.__nextSetZoneDoneEvent, self.okToUnblockVis) + # make sure that a setZone is sent this frame, even if the + # visibility list doesn't change + self.level.forceSetZoneThisFrame() def cancelUnblockVis(self): - """derived class should call this if they have called requestUnblockVis, - but no longer need that service. For example the user could have canceled - the request that started the visibility change.""" + """ + derived class should call this if they have called + requestUnblockVis, but no longer need that service. For example + the user could have canceled the request that started the + visibility change. + """ if self.__nextSetZoneDoneEvent is not None: self.ignore(self.__nextSetZoneDoneEvent) self.__nextSetZoneDoneEvent = None def isWaitingForUnblockVis(self): - """returns a boolean for whether there is a requestUnblockVis() pending.""" + """ + returns a boolean for whether there is a requestUnblockVis() pending. + """ return self.__nextSetZoneDoneEvent is not None def okToUnblockVis(self): - """derived class should override this func and do the vis unblock - (i.e. open the door, etc.)""" + """ + derived class should override this func and do the vis unblock + (i.e. open the door, etc.) + """ self.cancelUnblockVis()