"handleChild(Arrive/Leave)() now only applies when a child is being placed under for the first time or actually leaving. added handleChild(Arrive/Leave)Zone() for the case where the child keeps the same parent, but changes zones"

This commit is contained in:
Josh Wilson 2007-08-14 07:34:42 +00:00
parent b1d7446c27
commit bc62667675
4 changed files with 66 additions and 82 deletions

View File

@ -451,30 +451,6 @@ class DistributedObject(DistributedObjectBase, EnforcesCalldowns):
except AttributeError:
return None
def handleChildArrive(self, childObj, zoneId):
self.notify.debugCall()
# A new child has just setLocation beneath us. Give us a
# chance to run code when a new child sets location to us. For
# example, we may want to scene graph reparent the child to
# some subnode we own.
## zone=self.children.setdefault(zoneId, {})
## zone[childObj.doId]=childObj
# Inheritors should override
pass
def handleChildLeave(self, childObj, zoneId):
self.notify.debugCall()
# A child is about to setLocation away from us. Give us a
# chance to run code just before a child sets location away from us.
## zone=self.children[zoneId]
## del zone[childObj.doId]
## if not len(zone):
## del self.children[zoneId]
# Inheritors should override
pass
def getParentObj(self):
if self.parentId is None:
return None

View File

@ -232,30 +232,6 @@ class DistributedObjectAI(DistributedObjectBase, EnforcesCalldowns):
except AttributeError:
return None
def handleChildArrive(self, childObj, zoneId):
self.notify.debugCall()
# A new child has just setLocation beneath us. Give us a
# chance to run code when a new child sets location to us. For
# example, we may want to scene graph reparent the child to
# some subnode we own.
## zone=self.children.setdefault(zoneId, {})
## zone[childObj.doId]=childObj
# Inheritors should override
pass
def handleChildLeave(self, childObj, zoneId):
self.notify.debugCall()
# A child is about to setLocation away from us. Give us a
# chance to run code just before a child sets location away from us.
## zone=self.children[zoneId]
## del zone[childObj.doId]
## if not len(zone):
## del self.children[zoneId]
# Inheritors should override
pass
def postGenerateMessage(self):
self.__generated = True
messenger.send(self.uniqueName("generate"), [self])

View File

@ -43,26 +43,43 @@ class DistributedObjectBase(DirectObject):
return None
def handleChildArrive(self, childObj, zoneId):
"""
A new child has just setLocation beneath us. Give us a
chance to run code when a new child sets location to us. For
example, we may want to scene graph reparent the child to
some subnode we own.
"""
assert self.notify.debugCall()
# A new child has just setLocation beneath us. Give us a
# chance to run code when a new child sets location to us. For
# example, we may want to scene graph reparent the child to
# some subnode we own.
## zone=self.children.setdefault(zoneId, {})
## zone[childObj.doId]=childObj
# Inheritors should override
pass
def handleChildArriveZone(self, childObj, zoneId):
"""
A child has just changed zones beneath us with setLocation.
Give us a chance to run code when an existing child sets
location to us. For example, we may want to scene graph
reparent the child to some subnode we own.
"""
assert self.notify.debugCall()
# Inheritors should override
pass
def handleChildLeave(self, childObj, zoneId):
"""
A child is about to setLocation away from us. Give us a
chance to run code just before a child sets location away from us.
"""
assert self.notify.debugCall()
# A child is about to setLocation away from us. Give us a
# chance to run code just before a child sets location away from us.
## zone=self.children[zoneId]
## del zone[childObj.doId]
## if not len(zone):
## del self.children[zoneId]
# Inheritors should override
pass
def handleChildLeaveZone(self, childObj, zoneId):
"""
A child is about to setLocation to another zone beneath us.
Give us a chance to run code just before a child sets
location to that zone.
"""
assert self.notify.debugCall()
# Inheritors should override
pass

View File

@ -246,10 +246,20 @@ class DoCollectionManager:
def storeObjectLocation(self, object, parentId, zoneId):
oldParentId = object.parentId
oldZoneId = object.zoneId
if (oldParentId != parentId) or (oldZoneId != zoneId):
# Remove old location
if (oldParentId != parentId):
# notify any existing parent that we're moving away
oldParentObj = self.doId2do.get(oldParentId)
if oldParentObj is not None:
oldParentObj.handleChildLeave(object, oldZoneId)
self.deleteObjectLocation(object, oldParentId, oldZoneId)
elif oldParentId == parentId and oldZoneId == zoneId:
elif (oldZoneId != zoneId):
# Remove old location
oldParentObj = self.doId2do.get(oldParentId)
if oldParentObj is not None:
oldParentObj.handleChildLeaveZone(object, oldZoneId)
self.deleteObjectLocation(object, oldParentId, oldZoneId)
else:
# object is already at that parent and zone
return
@ -269,31 +279,30 @@ class DoCollectionManager:
object.parentId = parentId
object.zoneId = zoneId
if 1:
# Do we still need this
if oldParentId != parentId:
# Give the parent a chance to run code when a new child
# sets location to it. For example, the parent may want to
# scene graph reparent the child to some subnode it owns.
parentObj = self.doId2do.get(parentId)
if parentObj is not None:
parentObj.handleChildArrive(object, zoneId)
elif parentId not in (0, self.getGameDoId()):
self.notify.warning('storeObjectLocation(%s): parent %s not present' %
(object.doId, parentId))
if oldParentId != parentId:
# Give the parent a chance to run code when a new child
# sets location to it. For example, the parent may want to
# scene graph reparent the child to some subnode it owns.
parentObj = self.doId2do.get(parentId)
if parentObj is not None:
parentObj.handleChildArrive(object, zoneId)
elif parentId not in (0, self.getGameDoId()):
self.notify.warning('storeObjectLocation(%s): parent %s not present' %
(object.doId, parentId))
elif oldZoneId != zoneId:
parentObj = self.doId2do.get(parentId)
if parentObj is not None:
parentObj.handleChildArriveZone(object, zoneId)
elif parentId not in (0, self.getGameDoId()):
self.notify.warning('storeObjectLocation(%s): parent %s not present' %
(object.doId, parentId))
def deleteObjectLocation(self, object, parentId, zoneId):
# Do not worry about null values
if ((parentId is None) or (zoneId is None) or
(parentId == zoneId == 0)):
return
if 1:
# Do we still need this
# notify any existing parent that we're moving away
oldParentObj = self.doId2do.get(parentId)
if oldParentObj is not None:
oldParentObj.handleChildLeave(object, zoneId)
self._doHierarchy.deleteObjectLocation(object, parentId, zoneId)
@ -339,6 +348,12 @@ class DoCollectionManager:
assert self.notify.debugStateCall(self)
#assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
#assert do.doId in self.doId2do
location = do.getLocation()
if location:
oldParentId, oldZoneId = location
oldParentObj = self.doId2do.get(oldParentId)
if oldParentObj:
oldParentObj.handleChildLeave(object, oldZoneId)
self.deleteObjectLocation(do, do.parentId, do.zoneId)
## location = do.getLocation()
## if location is not None: