move interest code to DoInterestManager

This commit is contained in:
Dave Schuyler 2005-01-28 02:55:41 +00:00
parent bfbfcc0f74
commit d50d46a46e
4 changed files with 135 additions and 129 deletions

View File

@ -15,13 +15,13 @@ from PyDatagram import PyDatagram
from PyDatagramIterator import PyDatagramIterator from PyDatagramIterator import PyDatagramIterator
class ClientRepository(ConnectionRepository.ConnectionRepository): class ClientRepository(ConnectionRepository.ConnectionRepository):
"""
""" This maintains a client-side connection with a Panda server. This maintains a client-side connection with a Panda server.
It currently supports several different versions of the server: It currently supports several different versions of the server:
within the VR Studio, we are currently in transition from the within the VR Studio, we are currently in transition from the
Toontown server to the OTP server; people outside the VR studio Toontown server to the OTP server; people outside the VR studio
will use the Panda LAN server provided by CMU.""" will use the Panda LAN server provided by CMU.
"""
notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository") notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository")
def __init__(self): def __init__(self):
@ -64,11 +64,11 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
self.heartbeatStarted = 0 self.heartbeatStarted = 0
self.lastHeartbeat = 0 self.lastHeartbeat = 0
if wantOtpServer: #%# if wantOtpServer:
# Top level Interest Manager #%# # Top level Interest Manager
self._interestIdAssign = 1 #%# self._interestIdAssign = 1
self._interestIdScops = 100; #%# 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
# datagrams from the CMU Panda LAN server. You can # datagrams from the CMU Panda LAN server. You can
@ -577,7 +577,6 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
self.DOIDbase = di.getUint32() self.DOIDbase = di.getUint32()
self.DOIDlast = self.DOIDbase + di.getUint32() self.DOIDlast = self.DOIDbase + di.getUint32()
self.DOIDnext = self.DOIDbase self.DOIDnext = self.DOIDbase
return None
def handleRequestGenerates(self, di): def handleRequestGenerates(self, di):
# When new clients join the zone of an object, they need to hear # When new clients join the zone of an object, they need to hear
@ -816,7 +815,8 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
self.handleUnexpectedMsgType(msgType, di) self.handleUnexpectedMsgType(msgType, di)
if wantOtpServer: #%#:
if 0 and wantOtpServer:
# interest managment # interest managment
def addInterest(self, parentId, zoneIdList, description, event=None): def addInterest(self, parentId, zoneIdList, description, event=None):
""" """

View File

@ -1,14 +1,14 @@
from pandac.PandaModules import * from pandac.PandaModules import *
from direct.task import Task from direct.task import Task
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.showbase import DirectObject from direct.distributed.DoInterestManager import DoInterestManager
from PyDatagram import PyDatagram from PyDatagram import PyDatagram
from PyDatagramIterator import PyDatagramIterator from PyDatagramIterator import PyDatagramIterator
import types import types
import imp import imp
class ConnectionRepository(DirectObject.DirectObject, CConnectionRepository): class ConnectionRepository(DoInterestManager, CConnectionRepository):
""" """
This is a base class for things that know how to establish a This is a base class for things that know how to establish a
connection (and exchange datagrams) with a gameserver. This connection (and exchange datagrams) with a gameserver. This
@ -18,7 +18,8 @@ class ConnectionRepository(DirectObject.DirectObject, CConnectionRepository):
taskPriority = -30 taskPriority = -30
def __init__(self, config): def __init__(self, config):
DirectObject.DirectObject.__init__(self) assert self.notify.debugCall()
DoInterestManager.__init__(self)
CConnectionRepository.__init__(self) CConnectionRepository.__init__(self)
self.setPythonRepository(self) self.setPythonRepository(self)

View File

@ -330,8 +330,8 @@ class DistributedObject(PandaObject):
self.__barrierContext = None self.__barrierContext = None
if wantOtpServer: if wantOtpServer:
def addInterest(self, zoneId, note=""): def addInterest(self, zoneId, note="", event=None):
self.cr.addInterest(self.getDoId(), zoneId, note) self.cr.addInterest(self.getDoId(), zoneId, note, event)
def setLocation(self, parentId, zoneId): def setLocation(self, parentId, zoneId):
# The store must run first so we know the old location # The store must run first so we know the old location

View File

@ -9,25 +9,21 @@ p.s. A great deal of this code is just code moved from ClientRepository.py.
from pandac.PandaModules import * from pandac.PandaModules import *
from MsgTypes import * from MsgTypes import *
from direct.task import Task
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
import CRCache from direct.showbase.PythonUtil import *
import ConnectionRepository from direct.showbase import DirectObject
from direct.showbase import PythonUtil
import ParentMgr
import RelatedObjectMgr
import time
from ClockDelta import *
from PyDatagram import PyDatagram from PyDatagram import PyDatagram
from PyDatagramIterator import PyDatagramIterator #from PyDatagramIterator import PyDatagramIterator
class DoInterestManager(DirectObject.DirectObject): class DoInterestManager(DirectObject.DirectObject):
""" """
Top level Interest Manager Top level Interest Manager
""" """
if __debug__:
notify = DirectNotifyGlobal.directNotify.newCategory("DoInterestManager") notify = DirectNotifyGlobal.directNotify.newCategory("DoInterestManager")
def __init__(self): def __init__(self):
assert self.notify.debugCall()
DirectObject.DirectObject.__init__(self) DirectObject.DirectObject.__init__(self)
self._interestIdAssign = 1 self._interestIdAssign = 1
self._interestIdScopes = 100; self._interestIdScopes = 100;
@ -37,6 +33,7 @@ class DoInterestManager(DirectObject.DirectObject):
""" """
Look into a zone. Look into a zone.
""" """
assert self.notify.debugCall()
self._interestIdAssign += 1 self._interestIdAssign += 1
self._interestIdScopes += 1 self._interestIdScopes += 1
contextId = self._interestIdAssign contextId = self._interestIdAssign
@ -50,6 +47,7 @@ class DoInterestManager(DirectObject.DirectObject):
""" """
Stop looking in a zone Stop looking in a zone
""" """
assert self.notify.debugCall()
answer = 0 answer = 0
if self._interests.has_key(contextId): if self._interests.has_key(contextId):
if event is not None: if event is not None:
@ -73,6 +71,7 @@ class DoInterestManager(DirectObject.DirectObject):
""" """
Removes old interests and adds new interests. Removes old interests and adds new interests.
""" """
assert self.notify.debugCall()
answer = 0 answer = 0
if self._interests.has_key(contextId): if self._interests.has_key(contextId):
self._interestIdScopes += 1 self._interestIdScopes += 1
@ -94,6 +93,7 @@ class DoInterestManager(DirectObject.DirectObject):
Part of the new otp-server code. Part of the new otp-server code.
Return a ScopeId Id for an Interest Return a ScopeId Id for an Interest
""" """
assert self.notify.debugCall()
answer = 0 answer = 0
if self._interests.has_key(contextId): if self._interests.has_key(contextId):
answer = self._interests[contextId][1]; answer = self._interests[contextId][1];
@ -106,6 +106,7 @@ class DoInterestManager(DirectObject.DirectObject):
""" """
returns an event for an interest. returns an event for an interest.
""" """
assert self.notify.debugCall()
answer = None answer = None
if self._interests.has_key(contextId): if self._interests.has_key(contextId):
answer = self._interests[contextId][2]; answer = self._interests[contextId][2];
@ -117,6 +118,7 @@ class DoInterestManager(DirectObject.DirectObject):
""" """
Consider whether we should cull the interest set. Consider whether we should cull the interest set.
""" """
assert self.notify.debugCall()
if self._interests.has_key(handle): if self._interests.has_key(handle):
if self._interests[handle][3] == "PendingDel": if self._interests[handle][3] == "PendingDel":
del self._interests[handle] del self._interests[handle]
@ -146,6 +148,7 @@ class DoInterestManager(DirectObject.DirectObject):
necessarily have any relationship to the same contextId necessarily have any relationship to the same contextId
on another client. on another client.
""" """
assert self.notify.debugCall()
datagram = PyDatagram() datagram = PyDatagram()
# Add message type # Add message type
datagram.addUint16(CLIENT_ADD_INTEREST) datagram.addUint16(CLIENT_ADD_INTEREST)
@ -169,6 +172,7 @@ class DoInterestManager(DirectObject.DirectObject):
necessarily have any relationship to the same contextId necessarily have any relationship to the same contextId
on another client. on another client.
""" """
assert self.notify.debugCall()
datagram = PyDatagram() datagram = PyDatagram()
# Add message type # Add message type
datagram.addUint16(CLIENT_REMOVE_INTEREST) datagram.addUint16(CLIENT_REMOVE_INTEREST)
@ -180,19 +184,20 @@ class DoInterestManager(DirectObject.DirectObject):
This handles the interest done messages and may dispatch a This handles the interest done messages and may dispatch a
action based on the ID, Context action based on the ID, Context
""" """
assert self.notify.debugCall()
id = di.getUint16() id = di.getUint16()
scope = di.getUint32() scope = di.getUint32()
expect_scope = self.GetInterestScopeID(id) expect_scope = self.getInterestScopeId(id)
print "handleInterestDoneMessage--> Received ID:%s Scope:%s"%(id,scope); print "handleInterestDoneMessage--> Received ID:%s Scope:%s"%(id,scope);
if expect_scope == scope: if expect_scope == scope:
print "handleInterestDoneMessage--> Scope Match:%s Scope:%s"%(id,scope); print "handleInterestDoneMessage--> Scope Match:%s Scope:%s"%(id,scope);
event = self.GetInterestScopeEvent(id) event = self.getInterestScopeEvent(id)
if event is not None: if event is not None:
print "handleInterestDoneMessage--> Send Event : %s"%(event); print "handleInterestDoneMessage--> Send Event : %s"%(event);
messenger.send(event) messenger.send(event)
else: else:
print "handleInterestDoneMessage--> No Event "; print "handleInterestDoneMessage--> No Event ";
self._PonderRemoveFlaggedInterest(id) self._ponderRemoveFlaggedInterest(id)
else: else:
print "handleInterestDoneMessage--> Scope MisMatch :%s :%s"%(expect_scope,scope); print "handleInterestDoneMessage--> Scope MisMatch :%s :%s"%(expect_scope,scope);