mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
factory cleans up when toons leave
This commit is contained in:
parent
9488551370
commit
766fb18472
@ -188,6 +188,13 @@ class DistributedLevel(DistributedObject.DistributedObject,
|
||||
self.initVisibility()
|
||||
self.placeLocalToon()
|
||||
|
||||
self.acceptOnce('leavingFactory', self.announceLeaving)
|
||||
|
||||
def announceLeaving(self):
|
||||
"""call this just before leaving the level; this may result in
|
||||
the factory being destroyed on the AI"""
|
||||
self.doneBarrier()
|
||||
|
||||
def placeLocalToon(self):
|
||||
# the entrancePoint entities register themselves with us
|
||||
if self.entranceId not in self.entranceId2entity:
|
||||
@ -414,7 +421,7 @@ class DistributedLevel(DistributedObject.DistributedObject,
|
||||
|
||||
if zoneNum != self.lastToonZone:
|
||||
self.lastToonZone = zoneNum
|
||||
print "made zone transition to %s" % zoneNum
|
||||
print "toon is standing in zone %s" % zoneNum
|
||||
messenger.send("factoryZoneChanged", [zoneNum])
|
||||
self.smallTitleText.hide()
|
||||
self.spawnTitleText()
|
||||
|
@ -7,6 +7,7 @@ import Level
|
||||
import DirectNotifyGlobal
|
||||
import EntityCreatorAI
|
||||
import WeightedChoice
|
||||
from PythonUtil import Functor
|
||||
|
||||
class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
||||
Level.Level):
|
||||
@ -25,6 +26,8 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
||||
assert None not in avIds
|
||||
self.avIdList = avIds
|
||||
self.numPlayers = len(self.avIdList)
|
||||
# this is the list of avatars that are actually present
|
||||
self.presentAvIds = list(self.avIdList)
|
||||
self.notify.debug("expecting avatars: %s" % str(self.avIdList))
|
||||
|
||||
if __debug__:
|
||||
@ -57,6 +60,7 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
||||
if __debug__:
|
||||
self.removeAutosaveTask()
|
||||
self.destroyLevel()
|
||||
self.ignoreAll()
|
||||
DistributedObjectAI.DistributedObjectAI.delete(self)
|
||||
|
||||
def initializeLevel(self, levelSpec):
|
||||
@ -78,6 +82,34 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
||||
# listen for requests to save the spec
|
||||
self.accept(self.editMgrEntity.getSpecSaveEvent(), self.saveSpec)
|
||||
|
||||
# listen for avatar disconnects
|
||||
for avId in self.avIdList:
|
||||
self.acceptOnce(self.air.getAvatarExitEvent(avId),
|
||||
Functor(self.handleAvatarDisconnect, avId))
|
||||
|
||||
# set up a barrier that will clear when all avs have left or
|
||||
# disconnected
|
||||
self.allToonsGoneBarrier = self.beginBarrier(
|
||||
'allToonsGone', self.avIdList, 3*24*60*60, self.allToonsGone)
|
||||
|
||||
def handleAvatarDisconnect(self, avId):
|
||||
try:
|
||||
self.presentAvIds.remove(avId)
|
||||
DistributedLevelAI.notify.warning('av %s has disconnected' % avId)
|
||||
except:
|
||||
DistributedLevelAI.notify.warning(
|
||||
'got disconnect for av %s, not in list' % avId)
|
||||
if not self.presentAvIds:
|
||||
self.allToonsGone([])
|
||||
|
||||
def allToonsGone(self, toonsThatCleared):
|
||||
print 'allToonsGone'
|
||||
if hasattr(self, 'allToonsGoneBarrier'):
|
||||
self.ignoreBarrier(self.allToonsGoneBarrier)
|
||||
del self.allToonsGoneBarrier
|
||||
self.requestDelete()
|
||||
self.air.deallocateZone(self.zoneId)
|
||||
|
||||
def createEntityCreator(self):
|
||||
"""Create the object that will be used to create Entities.
|
||||
Inheritors, override if desired."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user