mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -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.initVisibility()
|
||||||
self.placeLocalToon()
|
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):
|
def placeLocalToon(self):
|
||||||
# the entrancePoint entities register themselves with us
|
# the entrancePoint entities register themselves with us
|
||||||
if self.entranceId not in self.entranceId2entity:
|
if self.entranceId not in self.entranceId2entity:
|
||||||
@ -414,7 +421,7 @@ class DistributedLevel(DistributedObject.DistributedObject,
|
|||||||
|
|
||||||
if zoneNum != self.lastToonZone:
|
if zoneNum != self.lastToonZone:
|
||||||
self.lastToonZone = zoneNum
|
self.lastToonZone = zoneNum
|
||||||
print "made zone transition to %s" % zoneNum
|
print "toon is standing in zone %s" % zoneNum
|
||||||
messenger.send("factoryZoneChanged", [zoneNum])
|
messenger.send("factoryZoneChanged", [zoneNum])
|
||||||
self.smallTitleText.hide()
|
self.smallTitleText.hide()
|
||||||
self.spawnTitleText()
|
self.spawnTitleText()
|
||||||
|
@ -7,6 +7,7 @@ import Level
|
|||||||
import DirectNotifyGlobal
|
import DirectNotifyGlobal
|
||||||
import EntityCreatorAI
|
import EntityCreatorAI
|
||||||
import WeightedChoice
|
import WeightedChoice
|
||||||
|
from PythonUtil import Functor
|
||||||
|
|
||||||
class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
||||||
Level.Level):
|
Level.Level):
|
||||||
@ -25,6 +26,8 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
|||||||
assert None not in avIds
|
assert None not in avIds
|
||||||
self.avIdList = avIds
|
self.avIdList = avIds
|
||||||
self.numPlayers = len(self.avIdList)
|
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))
|
self.notify.debug("expecting avatars: %s" % str(self.avIdList))
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
@ -57,6 +60,7 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
|||||||
if __debug__:
|
if __debug__:
|
||||||
self.removeAutosaveTask()
|
self.removeAutosaveTask()
|
||||||
self.destroyLevel()
|
self.destroyLevel()
|
||||||
|
self.ignoreAll()
|
||||||
DistributedObjectAI.DistributedObjectAI.delete(self)
|
DistributedObjectAI.DistributedObjectAI.delete(self)
|
||||||
|
|
||||||
def initializeLevel(self, levelSpec):
|
def initializeLevel(self, levelSpec):
|
||||||
@ -78,6 +82,34 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
|||||||
# listen for requests to save the spec
|
# listen for requests to save the spec
|
||||||
self.accept(self.editMgrEntity.getSpecSaveEvent(), self.saveSpec)
|
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):
|
def createEntityCreator(self):
|
||||||
"""Create the object that will be used to create Entities.
|
"""Create the object that will be used to create Entities.
|
||||||
Inheritors, override if desired."""
|
Inheritors, override if desired."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user