"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: except AttributeError:
return None 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): def getParentObj(self):
if self.parentId is None: if self.parentId is None:
return None return None

View File

@ -232,30 +232,6 @@ class DistributedObjectAI(DistributedObjectBase, EnforcesCalldowns):
except AttributeError: except AttributeError:
return None 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): def postGenerateMessage(self):
self.__generated = True self.__generated = True
messenger.send(self.uniqueName("generate"), [self]) messenger.send(self.uniqueName("generate"), [self])

View File

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

View File

@ -246,10 +246,20 @@ class DoCollectionManager:
def storeObjectLocation(self, object, parentId, zoneId): def storeObjectLocation(self, object, parentId, zoneId):
oldParentId = object.parentId oldParentId = object.parentId
oldZoneId = object.zoneId oldZoneId = object.zoneId
if (oldParentId != parentId) or (oldZoneId != zoneId): if (oldParentId != parentId):
# Remove old location # 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) 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 # object is already at that parent and zone
return return
@ -269,8 +279,7 @@ class DoCollectionManager:
object.parentId = parentId object.parentId = parentId
object.zoneId = zoneId object.zoneId = zoneId
if 1:
# Do we still need this
if oldParentId != parentId: if oldParentId != parentId:
# Give the parent a chance to run code when a new child # Give the parent a chance to run code when a new child
# sets location to it. For example, the parent may want to # sets location to it. For example, the parent may want to
@ -281,19 +290,19 @@ class DoCollectionManager:
elif parentId not in (0, self.getGameDoId()): elif parentId not in (0, self.getGameDoId()):
self.notify.warning('storeObjectLocation(%s): parent %s not present' % self.notify.warning('storeObjectLocation(%s): parent %s not present' %
(object.doId, parentId)) (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): def deleteObjectLocation(self, object, parentId, zoneId):
# Do not worry about null values # Do not worry about null values
if ((parentId is None) or (zoneId is None) or if ((parentId is None) or (zoneId is None) or
(parentId == zoneId == 0)): (parentId == zoneId == 0)):
return 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) self._doHierarchy.deleteObjectLocation(object, parentId, zoneId)
@ -339,6 +348,12 @@ class DoCollectionManager:
assert self.notify.debugStateCall(self) assert self.notify.debugStateCall(self)
#assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
#assert do.doId in self.doId2do #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) self.deleteObjectLocation(do, do.parentId, do.zoneId)
## location = do.getLocation() ## location = do.getLocation()
## if location is not None: ## if location is not None: