mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
moving parent zone stuff to collection manager
This commit is contained in:
parent
2b860ac591
commit
c28e3a500b
@ -381,35 +381,8 @@ class DistributedObject(PandaObject):
|
|||||||
self.cr.sendSetLocation(self.doId, parentId, zoneId)
|
self.cr.sendSetLocation(self.doId, parentId, zoneId)
|
||||||
|
|
||||||
def setLocation(self, parentId, zoneId):
|
def setLocation(self, parentId, zoneId):
|
||||||
# Prevent Duplicate SetLocations for being Called
|
|
||||||
if (self.parentId == parentId) and (self.zoneId == zoneId):
|
|
||||||
return
|
|
||||||
|
|
||||||
#self.notify.info("setLocation: %s parentId: %s zoneId: %s" % (self.doId, parentId, zoneId))
|
|
||||||
# parentId can be 'None', e.g. when an object is being disabled
|
|
||||||
oldParentId = self.parentId
|
|
||||||
oldZoneId = self.zoneId
|
|
||||||
parentIsNew = (oldParentId != parentId)
|
|
||||||
|
|
||||||
# notify any existing parent that we're moving away
|
|
||||||
if (oldParentId is not None) and parentIsNew:
|
|
||||||
oldParentObj = self.cr.doId2do.get(oldParentId)
|
|
||||||
if oldParentObj:
|
|
||||||
oldParentObj.handleChildLeave(self, oldZoneId)
|
|
||||||
|
|
||||||
# The store must run first so we know the old location
|
|
||||||
self.parentId = parentId
|
|
||||||
self.zoneId = zoneId
|
|
||||||
self.cr.storeObjectLocation(self.doId, parentId, zoneId)
|
self.cr.storeObjectLocation(self.doId, parentId, zoneId)
|
||||||
|
|
||||||
# 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.
|
|
||||||
if (self.parentId is not None) and parentIsNew:
|
|
||||||
parentObj = self.cr.doId2do.get(parentId)
|
|
||||||
if parentObj:
|
|
||||||
parentObj.handleChildArrive(self, zoneId)
|
|
||||||
|
|
||||||
def getLocation(self):
|
def getLocation(self):
|
||||||
try:
|
try:
|
||||||
if self.parentId == 0 and self.zoneId == 0:
|
if self.parentId == 0 and self.zoneId == 0:
|
||||||
|
@ -192,12 +192,9 @@ class DistributedObjectAI(DirectObject):
|
|||||||
|
|
||||||
oldParentId = self.parentId
|
oldParentId = self.parentId
|
||||||
oldZoneId = self.zoneId
|
oldZoneId = self.zoneId
|
||||||
|
self.air.storeObjectLocation(self.doId, parentId, zoneId)
|
||||||
if ((oldParentId != parentId) or
|
if ((oldParentId != parentId) or
|
||||||
(oldZoneId != zoneId)):
|
(oldZoneId != zoneId)):
|
||||||
#print "%s location is now %s, %s (%s)"%(self.doId, parentId, zoneId, self)
|
|
||||||
self.zoneId = zoneId
|
|
||||||
self.parentId = parentId
|
|
||||||
self.air.changeDOZoneInTables(self, parentId, zoneId, oldParentId, oldZoneId)
|
|
||||||
messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId])
|
messenger.send(self.getZoneChangeEvent(), [zoneId, oldZoneId])
|
||||||
# if we are not going into the quiet zone, send a 'logical' zone
|
# if we are not going into the quiet zone, send a 'logical' zone
|
||||||
# change message
|
# change message
|
||||||
@ -207,7 +204,6 @@ class DistributedObjectAI(DirectObject):
|
|||||||
lastLogicalZone = self.lastNonQuietZone
|
lastLogicalZone = self.lastNonQuietZone
|
||||||
self.handleLogicalZoneChange(zoneId, lastLogicalZone)
|
self.handleLogicalZoneChange(zoneId, lastLogicalZone)
|
||||||
self.lastNonQuietZone = zoneId
|
self.lastNonQuietZone = zoneId
|
||||||
self.air.storeObjectLocation(self.doId, parentId, zoneId)
|
|
||||||
|
|
||||||
def getLocation(self):
|
def getLocation(self):
|
||||||
try:
|
try:
|
||||||
@ -220,6 +216,30 @@ class DistributedObjectAI(DirectObject):
|
|||||||
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 updateRequiredFields(self, dclass, di):
|
def updateRequiredFields(self, dclass, di):
|
||||||
dclass.receiveUpdateBroadcastRequired(self, di)
|
dclass.receiveUpdateBroadcastRequired(self, di)
|
||||||
self.announceGenerate()
|
self.announceGenerate()
|
||||||
@ -355,9 +375,9 @@ class DistributedObjectAI(DirectObject):
|
|||||||
# Send a generate message
|
# Send a generate message
|
||||||
self.sendGenerateWithRequired(self.air, parentId, zoneId, optionalFields)
|
self.sendGenerateWithRequired(self.air, parentId, zoneId, optionalFields)
|
||||||
|
|
||||||
assert not hasattr(self, 'parentId') or self.parentId is None
|
## assert not hasattr(self, 'parentId') or self.parentId is None
|
||||||
self.parentId = parentId
|
## self.parentId = parentId
|
||||||
self.zoneId = zoneId
|
## self.zoneId = zoneId
|
||||||
self.generate()
|
self.generate()
|
||||||
self.announceGenerate()
|
self.announceGenerate()
|
||||||
|
|
||||||
|
@ -202,11 +202,34 @@ class DoCollectionManager:
|
|||||||
parentZoneDict = self.__doHierarchy.setdefault(parentId, {})
|
parentZoneDict = self.__doHierarchy.setdefault(parentId, {})
|
||||||
zoneDoSet = parentZoneDict.setdefault(zoneId, set())
|
zoneDoSet = parentZoneDict.setdefault(zoneId, set())
|
||||||
zoneDoSet.add(doId)
|
zoneDoSet.add(doId)
|
||||||
|
|
||||||
|
# Set the new parent and zone on the object
|
||||||
|
obj.parentId = parentId
|
||||||
|
obj.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(obj, zoneId)
|
||||||
|
|
||||||
def deleteObjectLocation(self, doId, parentId, zoneId):
|
def deleteObjectLocation(self, doId, parentId, zoneId):
|
||||||
# Do not worry about null values
|
# Do not worry about null values
|
||||||
if (parentId is None) or (zoneId is None):
|
if (parentId is None) or (zoneId is None):
|
||||||
return
|
return
|
||||||
|
if 1:
|
||||||
|
# Do we still need this
|
||||||
|
|
||||||
|
# notify any existing parent that we're moving away
|
||||||
|
oldParentObj = self.doId2do.get(parentId)
|
||||||
|
obj = self.doId2do.get(doId)
|
||||||
|
if oldParentObj is not None and obj is not None:
|
||||||
|
oldParentObj.handleChildLeave(obj, zoneId)
|
||||||
|
|
||||||
parentZoneDict = self.__doHierarchy.get(parentId)
|
parentZoneDict = self.__doHierarchy.get(parentId)
|
||||||
if parentZoneDict is not None:
|
if parentZoneDict is not None:
|
||||||
zoneDoSet = parentZoneDict.get(zoneId)
|
zoneDoSet = parentZoneDict.get(zoneId)
|
||||||
@ -277,28 +300,28 @@ class DoCollectionManager:
|
|||||||
if do.doId in self.doId2do:
|
if do.doId in self.doId2do:
|
||||||
del self.doId2do[do.doId]
|
del self.doId2do[do.doId]
|
||||||
|
|
||||||
def changeDOZoneInTables(self, do, newParentId, newZoneId, oldParentId, oldZoneId):
|
## def changeDOZoneInTables(self, do, newParentId, newZoneId, oldParentId, oldZoneId):
|
||||||
if 1:
|
## if 1:
|
||||||
self.storeObjectLocation(do.doId, newParentId, newZoneId)
|
## self.storeObjectLocation(do.doId, newParentId, newZoneId)
|
||||||
else:
|
## else:
|
||||||
#assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
|
## #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
|
||||||
oldLocation = (oldParentId, oldZoneId)
|
## oldLocation = (oldParentId, oldZoneId)
|
||||||
newLocation = (newParentId, newZoneId)
|
## newLocation = (newParentId, newZoneId)
|
||||||
# HACK: DistributedGuildMemberUD starts in -1,-1, which isnt ever put in the
|
## # HACK: DistributedGuildMemberUD starts in -1,-1, which isnt ever put in the
|
||||||
# zoneId2doIds table
|
## # zoneId2doIds table
|
||||||
if self.isValidLocationTuple(oldLocation):
|
## if self.isValidLocationTuple(oldLocation):
|
||||||
assert self.notify.debugStateCall(self)
|
## assert self.notify.debugStateCall(self)
|
||||||
assert oldLocation in self.zoneId2doIds
|
## assert oldLocation in self.zoneId2doIds
|
||||||
assert do.doId in self.zoneId2doIds[oldLocation]
|
## assert do.doId in self.zoneId2doIds[oldLocation]
|
||||||
assert do.doId not in self.zoneId2doIds.get(newLocation,{})
|
## assert do.doId not in self.zoneId2doIds.get(newLocation,{})
|
||||||
# remove from old zone
|
## # remove from old zone
|
||||||
del(self.zoneId2doIds[oldLocation][do.doId])
|
## del(self.zoneId2doIds[oldLocation][do.doId])
|
||||||
if len(self.zoneId2doIds[oldLocation]) == 0:
|
## if len(self.zoneId2doIds[oldLocation]) == 0:
|
||||||
del self.zoneId2doIds[oldLocation]
|
## del self.zoneId2doIds[oldLocation]
|
||||||
if self.isValidLocationTuple(newLocation):
|
## if self.isValidLocationTuple(newLocation):
|
||||||
# add to new zone
|
## # add to new zone
|
||||||
self.zoneId2doIds.setdefault(newLocation, {})
|
## self.zoneId2doIds.setdefault(newLocation, {})
|
||||||
self.zoneId2doIds[newLocation][do.doId]=do
|
## self.zoneId2doIds[newLocation][do.doId]=do
|
||||||
|
|
||||||
## def getObjectsInZone(self, parentId, zoneId):
|
## def getObjectsInZone(self, parentId, zoneId):
|
||||||
## """ call this to get a dict of doId:distObj for a zone.
|
## """ call this to get a dict of doId:distObj for a zone.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user