mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Changed out Zone Managment
This commit is contained in:
parent
f939c61b1a
commit
d1e875e3df
@ -29,6 +29,10 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
self.setClientDatagram(1)
|
self.setClientDatagram(1)
|
||||||
|
|
||||||
self.recorder = base.recorder
|
self.recorder = base.recorder
|
||||||
|
if wantOtpServer:
|
||||||
|
# this is used to imulate the old setzone behavior
|
||||||
|
# with set locationa and set interest
|
||||||
|
self.old_setzone_interest_handle = None
|
||||||
|
|
||||||
# Dict of {DistributedObject ids : DistributedObjects}
|
# Dict of {DistributedObject ids : DistributedObjects}
|
||||||
self.doId2do = {}
|
self.doId2do = {}
|
||||||
@ -63,6 +67,7 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
if wantOtpServer:
|
if wantOtpServer:
|
||||||
# Top level Interest Manager
|
# Top level Interest Manager
|
||||||
self._interestIdAssign = 1
|
self._interestIdAssign = 1
|
||||||
|
self._interestIdScops = 100;
|
||||||
self._interests = {}
|
self._interests = {}
|
||||||
|
|
||||||
# By default, the ClientRepository is set up to respond to
|
# By default, the ClientRepository is set up to respond to
|
||||||
@ -612,8 +617,8 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
self.handleGenerateWithRequired(di)
|
self.handleGenerateWithRequired(di)
|
||||||
elif msgType == CLIENT_CREATE_OBJECT_REQUIRED_OTHER:
|
elif msgType == CLIENT_CREATE_OBJECT_REQUIRED_OTHER:
|
||||||
self.handleGenerateWithRequiredOther(di)
|
self.handleGenerateWithRequiredOther(di)
|
||||||
elif msgType == CLIENT_DONE_SET_ZONE_RESP:
|
elif msgType == CLIENT_DONE_INTEREST_RESP:
|
||||||
self.handleSetZoneDone()
|
self.handleInterestDoneMessage(di)
|
||||||
elif msgType == CLIENT_OBJECT_LOCATION:
|
elif msgType == CLIENT_OBJECT_LOCATION:
|
||||||
self.handleObjectLocation(di)
|
self.handleObjectLocation(di)
|
||||||
else:
|
else:
|
||||||
@ -708,26 +713,46 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
self.send(datagram)
|
self.send(datagram)
|
||||||
|
|
||||||
if wantOtpServer:
|
if wantOtpServer:
|
||||||
def sendSetZoneMsg(self, zoneId, visibleZoneList=None, parent=None):
|
def sendImulateSetZone(self, zoneId, visibleZoneList=None, parentIdin=None, event=None):
|
||||||
datagram = PyDatagram()
|
"""
|
||||||
# Add message type
|
This Will Move The avatar and set an interest to that location ..
|
||||||
datagram.addUint16(CLIENT_SET_ZONE)
|
"""
|
||||||
# Add Parent
|
parentId = parentIdin;
|
||||||
if parent is not None:
|
if parentId is None:
|
||||||
datagram.addUint32(parent)
|
parentId = base.localAvatar.defaultShard;
|
||||||
else:
|
|
||||||
datagram.addUint32(base.localAvatar.defaultShard)
|
MyAvID = base.localAvatar.doId;
|
||||||
# Add zone id
|
# move thwe avatar..
|
||||||
datagram.addUint32(zoneId)
|
self.sendSetLocation(MyAvID,parentId,zoneId);
|
||||||
# if we have an explicit list of visible zones, add them
|
# move the interest..
|
||||||
|
|
||||||
|
InterestZones = zoneId;
|
||||||
if visibleZoneList is not None:
|
if visibleZoneList is not None:
|
||||||
vzl = list(visibleZoneList)
|
InterestZones = visibleZoneList
|
||||||
vzl.sort()
|
|
||||||
assert PythonUtil.uniqueElements(vzl)
|
if(self.old_setzone_interest_handle == None):
|
||||||
for zone in vzl:
|
self.old_setzone_interest_handle = self.addInterest(parentId, InterestZones, "OldSetZone Imulator", event)
|
||||||
datagram.addUint32(zone)
|
else:
|
||||||
# send the message
|
self.alterInterest(self.old_setzone_interest_handle,parentId, InterestZones, "OldSetZone Imulator", event)
|
||||||
|
|
||||||
|
def sendImulateSetZoneOff(self):
|
||||||
|
MyAvID = base.localAvatar.doId;
|
||||||
|
self.sendSetLocation(MyAvID,0,0);
|
||||||
|
if self.old_setzone_interest_handle is not None:
|
||||||
|
self.removeInterest(self.old_setzone_interest_handle)
|
||||||
|
self.old_setzone_interest_handle = None
|
||||||
|
|
||||||
|
|
||||||
|
def sendSetLocation(self,doId,parentId,zoneId):
|
||||||
|
datagram = PyDatagram()
|
||||||
|
datagram.addUint16(CLIENT_OBJECT_LOCATION)
|
||||||
|
datagram.addUint32(doId)
|
||||||
|
datagram.addUint32(parentId)
|
||||||
|
datagram.addUint32(zoneId)
|
||||||
self.send(datagram)
|
self.send(datagram)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
def sendSetZoneMsg(self, zoneId, visibleZoneList=None):
|
def sendSetZoneMsg(self, zoneId, visibleZoneList=None):
|
||||||
datagram = PyDatagram()
|
datagram = PyDatagram()
|
||||||
@ -754,7 +779,8 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
|
|
||||||
msgType = self.getMsgType()
|
msgType = self.getMsgType()
|
||||||
|
|
||||||
# watch for setZoneDones
|
|
||||||
|
if not wantOtpServer:
|
||||||
if msgType == CLIENT_DONE_SET_ZONE_RESP:
|
if msgType == CLIENT_DONE_SET_ZONE_RESP:
|
||||||
self.handleSetZoneDone()
|
self.handleSetZoneDone()
|
||||||
|
|
||||||
@ -792,46 +818,98 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
|
|
||||||
if wantOtpServer:
|
if wantOtpServer:
|
||||||
# interest managment
|
# interest managment
|
||||||
def addInterest(self, parentId, zoneId, description):
|
def addInterest(self, parentId, zoneIdList, description, event=None):
|
||||||
"""
|
"""
|
||||||
Part of the new otp-server code.
|
Part of the new otp-server code.
|
||||||
"""
|
"""
|
||||||
self._interestIdAssign += 1
|
self._interestIdAssign += 1
|
||||||
self._interests[self._interestIdAssign] = description
|
self._interestIdScops += 1
|
||||||
|
self._interests[self._interestIdAssign] = [ description ,self._interestIdScops, event , "Active" ]
|
||||||
contextId = self._interestIdAssign
|
contextId = self._interestIdAssign
|
||||||
self._sendAddInterest(contextId, parentId, zoneId)
|
scopeId = self._interestIdScops
|
||||||
|
self._sendAddInterest(contextId, scopeId, parentId, zoneIdList)
|
||||||
assert self.printInterests()
|
assert self.printInterests()
|
||||||
return contextId
|
return contextId
|
||||||
|
|
||||||
def removeInterest(self, contextId):
|
def removeInterest(self, contextId, event=None):
|
||||||
"""
|
"""
|
||||||
Part of the new otp-server code.
|
Part of the new otp-server code.
|
||||||
"""
|
"""
|
||||||
answer = 0
|
answer = 0
|
||||||
if self._interests.has_key(contextId):
|
if self._interests.has_key(contextId):
|
||||||
|
if event is not None:
|
||||||
|
self._interestIdScops += 1
|
||||||
|
self._interests[contextId][2] = event
|
||||||
|
self._interests[contextId][1] = self._interestIdScops
|
||||||
self._sendRemoveInterest(contextId)
|
self._sendRemoveInterest(contextId)
|
||||||
del self._interests[contextId]
|
del self._interests[contextId]
|
||||||
|
else:
|
||||||
|
self._interests[contextId][3] = "PendingDel"
|
||||||
|
self._interests[contextId][2] = None
|
||||||
|
self._interests[contextId][1] = 0
|
||||||
|
self._sendRemoveInterest(contextId)
|
||||||
|
|
||||||
answer = 1
|
answer = 1
|
||||||
assert self.printInterests()
|
assert self.printInterests()
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
def alterInterest(self, contextId, parentId, zoneId, description = None):
|
def alterInterest(self, contextId, parentId, zoneIdList, description = None, event=None):
|
||||||
"""
|
"""
|
||||||
Part of the new otp-server code.
|
Part of the new otp-server code.
|
||||||
Removes old and adds new..
|
Removes old and adds new..
|
||||||
"""
|
"""
|
||||||
print 'new'
|
|
||||||
answer = 0
|
answer = 0
|
||||||
if self._interests.has_key(contextId):
|
if self._interests.has_key(contextId):
|
||||||
|
self._interestIdScops += 1
|
||||||
if description is not None:
|
if description is not None:
|
||||||
self._interests[contextId] = description
|
self._interests[contextId][0] = description
|
||||||
self._sendAddInterest(contextId, parentId, zoneId)
|
|
||||||
|
self._interests[contextId][1] = self._interestIdScops;
|
||||||
|
self._interests[contextId][2] = event;
|
||||||
|
self._sendAddInterest(contextId,self._interestIdScops, parentId, zoneIdList)
|
||||||
answer = 1
|
answer = 1
|
||||||
assert self.printInterests()
|
assert self.printInterests()
|
||||||
else:
|
else:
|
||||||
self.notify.warning("alterInterest: contextId not found: %s" % (contextId))
|
self.notify.warning("alterInterest: contextId not found: %s" % (contextId))
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
|
||||||
|
def GetInterestScopeID(self, contextId):
|
||||||
|
"""
|
||||||
|
Part of the new otp-server code.
|
||||||
|
Return a ScopeId Id for an Interest
|
||||||
|
"""
|
||||||
|
answer = 0
|
||||||
|
if self._interests.has_key(contextId):
|
||||||
|
answer = self._interests[contextId][1];
|
||||||
|
else:
|
||||||
|
self.notify.warning("GetInterestScopeID: contextId not found: %s" % (contextId))
|
||||||
|
return answer
|
||||||
|
|
||||||
|
|
||||||
|
def GetInterestScopeEvent(self, contextId):
|
||||||
|
"""
|
||||||
|
Part of the new otp-server code.
|
||||||
|
Return a ScopeId Id for an Interest
|
||||||
|
"""
|
||||||
|
answer = None
|
||||||
|
if self._interests.has_key(contextId):
|
||||||
|
answer = self._interests[contextId][2];
|
||||||
|
else:
|
||||||
|
self.notify.warning("GetInterestScopeEvent: contextId not found: %s" % (contextId))
|
||||||
|
return answer
|
||||||
|
|
||||||
|
|
||||||
|
def _PonderRemoveFlaggedInterest(self, handle):
|
||||||
|
"""
|
||||||
|
Part of the new otp-server code.
|
||||||
|
Return a ScopeId Id for an Interest
|
||||||
|
"""
|
||||||
|
answer = None
|
||||||
|
if self._interests.has_key(handle):
|
||||||
|
if self._interests[handle][3] == "PendingDel":
|
||||||
|
del self._interests[handle]
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
def printInterests(self):
|
def printInterests(self):
|
||||||
"""
|
"""
|
||||||
@ -839,11 +917,11 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
"""
|
"""
|
||||||
print "*********************** Interest Sets **************"
|
print "*********************** Interest Sets **************"
|
||||||
for i in self._interests.keys():
|
for i in self._interests.keys():
|
||||||
print "Interest ID:%s, Description=%s"%(i, self._interests[i])
|
print "Interest ID:%s, Description=%s Scope=%s Event=%s Mode=%s"%(i, self._interests[i][0],self._interests[i][1],self._interests[i][2],self._interests[i][3])
|
||||||
print "****************************************************"
|
print "****************************************************"
|
||||||
return 1 # for assert()
|
return 1 # for assert()
|
||||||
|
|
||||||
def _sendAddInterest(self, contextId, parentId, zoneId):
|
def _sendAddInterest(self, contextId, scopeId, parentId, zoneIdList):
|
||||||
"""
|
"""
|
||||||
Part of the new otp-server code.
|
Part of the new otp-server code.
|
||||||
|
|
||||||
@ -856,8 +934,20 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
# Add message type
|
# Add message type
|
||||||
datagram.addUint16(CLIENT_ADD_INTEREST)
|
datagram.addUint16(CLIENT_ADD_INTEREST)
|
||||||
datagram.addUint16(contextId)
|
datagram.addUint16(contextId)
|
||||||
|
datagram.addUint32(scopeId)
|
||||||
datagram.addUint32(parentId)
|
datagram.addUint32(parentId)
|
||||||
datagram.addUint32(zoneId)
|
|
||||||
|
print zoneIdList
|
||||||
|
|
||||||
|
if isinstance(zoneIdList,types.ListType):
|
||||||
|
vzl = list(zoneIdList)
|
||||||
|
vzl.sort()
|
||||||
|
PythonUtil.uniqueElements(vzl)
|
||||||
|
for zone in vzl:
|
||||||
|
datagram.addUint32(zone)
|
||||||
|
else:
|
||||||
|
datagram.addUint32(zoneIdList)
|
||||||
|
|
||||||
self.send(datagram)
|
self.send(datagram)
|
||||||
|
|
||||||
def _sendRemoveInterest(self, contextId):
|
def _sendRemoveInterest(self, contextId):
|
||||||
@ -875,6 +965,28 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
datagram.addUint16(contextId)
|
datagram.addUint16(contextId)
|
||||||
self.send(datagram)
|
self.send(datagram)
|
||||||
|
|
||||||
|
def handleInterestDoneMessage(self, di):
|
||||||
|
"""
|
||||||
|
This handles the interest done messages and may dispatch a
|
||||||
|
action based on the ID , Context
|
||||||
|
"""
|
||||||
|
id = di.getUint16()
|
||||||
|
scope = di.getUint32()
|
||||||
|
expect_scope = self.GetInterestScopeID(id)
|
||||||
|
print "handleInterestDoneMessage--> Received ID:%s Scope:%s"%(id,scope);
|
||||||
|
if expect_scope == scope:
|
||||||
|
print "handleInterestDoneMessage--> Scope Match:%s Scope:%s"%(id,scope);
|
||||||
|
event = self.GetInterestScopeEvent(id)
|
||||||
|
if event is not None:
|
||||||
|
print "handleInterestDoneMessage--> Send Event : %s"%(event);
|
||||||
|
messenger.send(event)
|
||||||
|
else:
|
||||||
|
print "handleInterestDoneMessage--> No Event ";
|
||||||
|
self._PonderRemoveFlaggedInterest(id)
|
||||||
|
else:
|
||||||
|
print "handleInterestDoneMessage--> Scope MisMatch :%s :%s"%(expect_scope,scope);
|
||||||
|
|
||||||
|
assert self.printInterests()
|
||||||
|
|
||||||
def sendHeartbeat(self):
|
def sendHeartbeat(self):
|
||||||
datagram = PyDatagram()
|
datagram = PyDatagram()
|
||||||
|
@ -27,6 +27,7 @@ CLIENT_OBJECT_DISABLE = 25
|
|||||||
CLIENT_OBJECT_DISABLE_RESP = 25
|
CLIENT_OBJECT_DISABLE_RESP = 25
|
||||||
CLIENT_OBJECT_DELETE = 27
|
CLIENT_OBJECT_DELETE = 27
|
||||||
CLIENT_OBJECT_DELETE_RESP = 27
|
CLIENT_OBJECT_DELETE_RESP = 27
|
||||||
|
if not wantOtpServer:
|
||||||
CLIENT_SET_ZONE = 29
|
CLIENT_SET_ZONE = 29
|
||||||
CLIENT_REMOVE_ZONE = 30
|
CLIENT_REMOVE_ZONE = 30
|
||||||
CLIENT_SET_SHARD = 31
|
CLIENT_SET_SHARD = 31
|
||||||
@ -43,7 +44,11 @@ CLIENT_DISCONNECT = 37
|
|||||||
CLIENT_CHANGE_IP_ADDRESS_RESP = 45
|
CLIENT_CHANGE_IP_ADDRESS_RESP = 45
|
||||||
CLIENT_GET_STATE = 46
|
CLIENT_GET_STATE = 46
|
||||||
CLIENT_GET_STATE_RESP = 47
|
CLIENT_GET_STATE_RESP = 47
|
||||||
|
if wantOtpServer:
|
||||||
|
CLIENT_DONE_INTEREST_RESP = 48
|
||||||
|
else:
|
||||||
CLIENT_DONE_SET_ZONE_RESP = 48
|
CLIENT_DONE_SET_ZONE_RESP = 48
|
||||||
|
|
||||||
CLIENT_DELETE_AVATAR = 49
|
CLIENT_DELETE_AVATAR = 49
|
||||||
|
|
||||||
# I think this is 5 to look like a CLIENT_GET_AVATARS_RESP
|
# I think this is 5 to look like a CLIENT_GET_AVATARS_RESP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user