From 3c00fa597cd01b9c43d742c85f1d921aa688ebfa Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Wed, 10 Sep 2003 20:17:22 +0000 Subject: [PATCH] fixed delayed reparenting for multiple children --- direct/src/level/DistributedLevel.py | 37 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/direct/src/level/DistributedLevel.py b/direct/src/level/DistributedLevel.py index c4afe371c4..ff1cec3d59 100755 --- a/direct/src/level/DistributedLevel.py +++ b/direct/src/level/DistributedLevel.py @@ -28,7 +28,7 @@ class DistributedLevel(DistributedObject.DistributedObject, # this dict stores entity reparents if the parent hasn't been # created yet - self.pendingEntId2ParentId = {} + self.parent2ChildIds = {} # Most (if not all) of the timed entities of levels # run on looping intervals that are started once based on @@ -123,7 +123,7 @@ class DistributedLevel(DistributedObject.DistributedObject, self.localEntities[entId] = entity # there should not be any pending reparents left - assert len(self.pendingEntId2ParentId) == 0 + assert len(self.parent2ChildIds) == 0 def announceGenerate(self): self.notify.debug('announceGenerate') @@ -164,19 +164,30 @@ class DistributedLevel(DistributedObject.DistributedObject, self.notify.debug( 'entity %s requesting reparent to %s, not yet created' % (entity, parent)) + entId = entity.entId - self.pendingEntId2ParentId[entId] = parentId entity.reparentTo(hidden) - # do the reparent once the parent is initialized - def doReparent(entId=entId, parentId=parentId, self=self): - entity=self.getEntity(entId) - parent=self.getEntity(parentId) - self.notify.debug( - 'performing pending reparent of %s to %s' % - (entity, parent)) - entity.reparentTo(parent) - del self.pendingEntId2ParentId[entId] - self.accept(self.getEntityCreateEvent(parentId), doReparent) + + # if this parent doesn't already have another child pending, + # do some setup + if not self.parent2ChildIds.has_key(parentId): + self.parent2ChildIds[parentId] = [] + + # do the reparent once the parent is initialized + def doReparent(parentId=parentId, self=self): + assert self.parent2ChildIds.has_key(parentId) + parent=self.getEntity(parentId) + for entId in self.parent2ChildIds[parentId]: + entity=self.getEntity(entId) + self.notify.debug( + 'performing pending reparent of %s to %s' % + (entity, parent)) + entity.reparentTo(parent) + del self.parent2ChildIds[parentId] + + self.accept(self.getEntityCreateEvent(parentId), doReparent) + + self.parent2ChildIds[parentId].append(entId) def showZone(self, zoneNum): self.zoneNum2Node[zoneNum].show()