From 6c57da8086a63cdd65e5babe07841d5953fe19ee Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 25 May 2006 23:19:59 +0000 Subject: [PATCH] added bboard removal tracking --- direct/src/showbase/BulletinBoard.py | 4 +++ direct/src/showbase/BulletinBoardWatcher.py | 40 ++++++++++++--------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/direct/src/showbase/BulletinBoard.py b/direct/src/showbase/BulletinBoard.py index d2ace45e33..c57101f119 100755 --- a/direct/src/showbase/BulletinBoard.py +++ b/direct/src/showbase/BulletinBoard.py @@ -19,6 +19,9 @@ class BulletinBoard: def getEvent(self, postName): return 'bboard-%s' % postName + def getRemoveEvent(self, postName): + return 'bboard-remove-%s' % postName + def post(self, postName, value=None): if postName in self._dict: BulletinBoard.notify.warning('changing %s from %s to %s' % ( @@ -35,6 +38,7 @@ class BulletinBoard: def remove(self, postName): if postName in self._dict: del self._dict[postName] + messenger.send(self.getRemoveEvent(postName)) def removeIfEqual(self, postName, value): # only remove the post if its value is a particular value diff --git a/direct/src/showbase/BulletinBoardWatcher.py b/direct/src/showbase/BulletinBoardWatcher.py index 5d7933a1dd..677b7406be 100755 --- a/direct/src/showbase/BulletinBoardWatcher.py +++ b/direct/src/showbase/BulletinBoardWatcher.py @@ -1,27 +1,33 @@ from direct.directnotify import DirectNotifyGlobal -from direct.showbase.PythonUtil import Functor +from direct.showbase.PythonUtil import Functor, makeList from direct.showbase import DirectObject class BulletinBoardWatcher(DirectObject.DirectObject): - """This class allows you to wait for a set of posts to be made to the - bulletin board, and give you a notification when all posts have been - made. Values of posts are not examined.""" + """ This class allows you to wait for a set of posts to be made to (or + removed from) the bulletin board, and gives you a notification when all + posts have been made. Values of posts are not examined.""" notify = DirectNotifyGlobal.directNotify.newCategory('BulletinBoardWatcher') - def __init__(self, name, postNames, callback): + def __init__(self, name, postNames, callback, removeNames=None): self.notify.debug('__init__: %s, %s, %s' % (name, postNames, callback)) + if removeNames is None: + removeNames = [] self.name = name - if type(postNames) == type(''): - postNames = [postNames] - self.postNames = postNames + self.postNames = makeList(postNames) + self.removeNames = makeList(removeNames) self.callback = callback - self.waitingOn = {} - for name in postNames: + self.waitingOn = set() + for name in self.postNames: if not bboard.has(name): eventName = bboard.getEvent(name) - self.acceptOnce(eventName, Functor(self.handlePost, eventName)) - self.waitingOn[eventName] = None - self.checkDone() + self.waitingOn.add(eventName) + self.acceptOnce(eventName, Functor(self._handleEvent, eventName)) + for name in self.removeNames: + if bboard.has(name): + eventName = bboard.getRemoveEvent(name) + self.waitingOn.add(eventName) + self.acceptOnce(eventName, Functor(self._handleEvent, eventName)) + self._checkDone() def destroy(self): self.ignoreAll() @@ -31,13 +37,13 @@ class BulletinBoardWatcher(DirectObject.DirectObject): def isDone(self): return len(self.waitingOn) == 0 - def checkDone(self): + def _checkDone(self): if self.isDone(): self.notify.debug('%s: done' % self.name) self.callback() - def handlePost(self, eventName): + def _handleEvent(self, eventName): self.notify.debug('%s: handlePost(%s)' % (self.name, eventName)) assert eventName in self.waitingOn - del self.waitingOn[eventName] - self.checkDone() + self.waitingOn.remove(eventName) + self._checkDone()