*** empty log message ***

This commit is contained in:
Jesse Schell 2000-10-31 16:05:42 +00:00
parent 40ae72cd2e
commit c534bcaa87
10 changed files with 135 additions and 78 deletions

View File

@ -13,6 +13,7 @@ class ClientDistClass:
self.allCDU = self.createAllCDU(self.allFields) self.allCDU = self.createAllCDU(self.allFields)
self.number2CDU = self.createNumber2CDUDict(self.allCDU) self.number2CDU = self.createNumber2CDUDict(self.allCDU)
self.name2CDU = self.createName2CDUDict(self.allCDU) self.name2CDU = self.createName2CDUDict(self.allCDU)
self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
return None return None
def parseFields(self, dcClass): def parseFields(self, dcClass):
@ -39,6 +40,15 @@ class ClientDistClass:
dict[i.name] = i dict[i.name] = i
return dict return dict
def listRequiredCDU(self, allCDU):
requiredCDU = []
for i in allCDU:
atom = i.field.asAtomicField()
if atom:
if atom.isRequired():
requiredCDU.append(i)
return requiredCDU
def updateField(self, do, di): def updateField(self, do, di):
# Get the update field id # Get the update field id
fieldId = di.getArg(ST_uint8) fieldId = di.getArg(ST_uint8)

View File

@ -1,11 +1,14 @@
"""ClientDistUpdate module: contains the ClientDistUpdate class""" """ClientDistUpdate module: contains the ClientDistUpdate class"""
import DirectNotifyGlobal import DirectNotifyGlobal
import Avatar
import DistributedToon
class ClientDistUpdate: class ClientDistUpdate:
notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate") notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate")
def __init__(self, dcField): def __init__(self, dcField):
self.field = dcField
self.number = dcField.getNumber() self.number = dcField.getNumber()
self.name = dcField.getName() self.name = dcField.getName()
self.types = [] self.types = []
@ -32,10 +35,11 @@ class ClientDistUpdate:
def updateField(self, cdc, do, di): def updateField(self, cdc, do, di):
# Look up the class # Look up the class
aClass = eval(cdc.name) #aClass = eval(cdc.name + "." + cdc.name)
# Look up the function # Look up the function
assert(aClass.__dict__.has_key(self.name)) #assert(aClass.__dict__.has_key(self.name))
func = aClass.__dict__[self.name] #func = aClass.__dict__[self.name]
func = eval(cdc.name + "." + cdc.name + "." + self.name)
# Get the arguments into a list # Get the arguments into a list
args = self.extractArgs(di) args = self.extractArgs(di)
# Apply the function to the object with the arguments # Apply the function to the object with the arguments
@ -45,7 +49,7 @@ class ClientDistUpdate:
def extractArgs(self, di): def extractArgs(self, di):
args = [] args = []
for i in self.types: for i in self.types:
args.append(di.getArgs(i)) args.append(di.getArg(i))
return args return args
def addArgs(self, datagram, args): def addArgs(self, datagram, args):

View File

@ -8,9 +8,10 @@ import DirectNotifyGlobal
import ClientDistClass import ClientDistClass
# The repository must import all known types of Distributed Objects # The repository must import all known types of Distributed Objects
import DistributedObject import DistributedObject
import DistributedToon
import DirectObject
class ClientRepository: class ClientRepository(DirectObject.DirectObject):
defaultServerPort = 5150
notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository") notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository")
def __init__(self, dcFileName, AIClientFlag=0): def __init__(self, dcFileName, AIClientFlag=0):
@ -38,8 +39,7 @@ class ClientRepository:
self.name2cdc[dcClass.getName()]=clientDistClass self.name2cdc[dcClass.getName()]=clientDistClass
return None return None
def connect(self, serverName="localhost", def connect(self, serverName, serverPort):
serverPort=defaultServerPort):
self.qcm=QueuedConnectionManager() self.qcm=QueuedConnectionManager()
self.tcpConn = self.qcm.openTCPClientConnection( self.tcpConn = self.qcm.openTCPClientConnection(
serverName, serverPort, 1000) serverName, serverPort, 1000)
@ -71,38 +71,26 @@ class ClientRepository:
return availGetVal return availGetVal
def handleDatagram(self, datagram): def handleDatagram(self, datagram):
di = DatagramIterator(datagram) # This class is meant to be pure virtual, and any classes that
msgType = di.getArg(STUint16) # inherit from it need to make their own handleDatagram method
pass
if msgType == LOGIN_RESPONSE:
self.handleLoginResponse(di)
elif msgType == ALL_OBJECT_GENERATE_WITH_REQUIRED:
self.handleGenerateWithRequired(di)
elif msgType == ALL_OBJECT_UPDATE_FIELD:
self.handleUpdateField(di)
else:
ClientRepository.notify.warning("We don't handle type: "
+ str(msgType))
return None
def handleLoginResponse(self, di):
# Pull the security byte
secByte = di.getUint8()
# Print the byte
print ("Got login with security: " + chr(secByte))
def handleGenerateWithRequired(self, di): def handleGenerateWithRequired(self, di):
# Get the class Id # Get the class Id
classId = di.getArg(STUint8); classId = di.getArg(STUint16);
# Get the DO Id # Get the DO Id
doId = di.getArg(STUint32) doId = di.getArg(STUint32)
# Look up the cdc # Look up the cdc
cdc = self.number2cdc[classId] cdc = self.number2cdc[classId]
# Create a new distributed object, and put it in the dictionary # Create a new distributed object, and put it in the dictionary
distObj = self.generateWithRequiredFields(cdc, doId, di) distObj = self.generateWithRequiredFields(cdc,
eval(cdc.name + \
"." + \
cdc.name),
doId, di)
return None return None
def generateWithRequiredFields(self, cdc, doId, di): def generateWithRequiredFields(self, cdc, constructor, doId, di):
# Someday, this function will look in a cache of old distributed # Someday, this function will look in a cache of old distributed
# objects to see if this object is in there, and pull it # objects to see if this object is in there, and pull it
# out if necessary. For now, we'll just check to see if # out if necessary. For now, we'll just check to see if
@ -114,10 +102,15 @@ class ClientRepository:
ClientRepository.notify.warning("doId: " + ClientRepository.notify.warning("doId: " +
str(doId) + str(doId) +
" was generated again") " was generated again")
distObj = self.doId2do(doId) distObj = self.doId2do[doId]
distObj.updateRequiredFields(cdc, di)
else: else:
# Construct a new one # Construct a new one
distObj = eval(cdc.name + "." + cdc.name)(doId, di) distObj = constructor()
# Assign it an Id
distObj.doId = doId
# Update the required fields
distObj.updateRequiredFields(cdc, di)
# Put the new do in both dictionaries # Put the new do in both dictionaries
self.doId2do[doId] = distObj self.doId2do[doId] = distObj
self.doId2cdc[doId] = cdc self.doId2cdc[doId] = cdc
@ -136,19 +129,6 @@ class ClientRepository:
# Let the cdc finish the job # Let the cdc finish the job
cdc.updateField(do, di) cdc.updateField(do, di)
def sendLoginMsg(self):
datagram = Datagram()
# Add message type
datagram.addUint16(1)
# Add swid
datagram.addString("1234567890123456789012345678901234")
# Add IP Address
datagram.addUint32(0)
# Add UDP port
datagram.addUint16(5150)
# Send the message
self.cw.send(datagram, self.tcpConn)
def sendUpdate(self, do, fieldName, args): def sendUpdate(self, do, fieldName, args):
# Get the DO id # Get the DO id
doId = do.doId doId = do.doId

View File

@ -1,8 +1,14 @@
"""DistributedActor module: contains the DistributedActor class""" """DistributedActor module: contains the DistributedActor class"""
from DistributedNode import * import DistributedNode
import Actor import Actor
class DistributedActor(DistributedNode, Actor.Actor): class DistributedActor(DistributedNode.DistributedNode, Actor.Actor):
"""Distributed Actor class:""" """Distributed Actor class:"""
def __init__(self):
pass pass
def generateInit(self, di):
DistributedNode.DistributedNode.generateInit(self, di)

View File

@ -1,7 +1,27 @@
"""DistributedNode module: contains the DistributedNode class""" """DistributedNode module: contains the DistributedNode class"""
from DistributedObject import * import NodePath
import DistributedObject
class DistributedNode(DistributedObject, NodePath): class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
"""Distributed Node class:""" """Distributed Node class:"""
def __init__(self):
pass pass
def generateInit(self, di):
DistributedObject.DistributedObject.generateInit(self, di)
def d_setPos(self, x, y, z):
self.sendUpdate("setPos", [x, y, z])
def d_setHpr(self, h, p, r):
self.sendUpdate("setHpr", [h, p, r])
def d_setPosHpr(self):
self.d_setPos_Hpr(self.getX(), self.getY(), self.getZ(),
self.getH(), self.getP(), self.getR())
def d_setPosHpr(self, x, y, z, h, p, r):
self.sendUpdate("setPosHpr", [x, y, z, h, p, r])

View File

@ -4,10 +4,24 @@ from PandaObject import *
class DistributedObject(PandaObject): class DistributedObject(PandaObject):
"""Distributed Object class:""" """Distributed Object class:"""
def __init__(self, doId, di): def __init__(self):
self.doId=doId pass
self.zone=di.getUint32()
assert(di.getRemainingSize() == 0) def getDoId(self):
"""getDoId(self)
Return the distributed object id
"""
return self.__doId
def updateRequiredFields(self, cdc, di):
for i in cdc.allRequiredCDU:
i.updateField(cdc, self, di)
def sendUpdate(self, fieldName, args): def sendUpdate(self, fieldName, args):
cr.sendupdate(self, fieldName, args) cr.sendupdate(self, fieldName, args)
def taskName(self, taskString):
return (taskString + "-" + str(self.getDoId))

View File

@ -0,0 +1,8 @@
"""MsgTypes module: contains distributed object message types"""
CLIENT_OBJECT_UPDATE_FIELD = 24
CLIENT_OBJECT_UPDATE_FIELD_RESP = 24
CLIENT_OBJECT_DISABLE_RESP = 25
CLIENT_OBJECT_DELETE_RESP = 27
CLIENT_CREATE_OBJECT_REQUIRED = 34
CLIENT_CREATE_OBJECT_REQUIRED_OTHER = 35

View File

@ -32,7 +32,8 @@ class FSM(DirectObject):
self.setFinalState(finalStateName) self.setFinalState(finalStateName)
#enter the initial state # Enter the initial state.
# It is assumed that the initial state takes no arguments.
self.__currentState = self.__initialState self.__currentState = self.__initialState
self.__enter(self.__initialState) self.__enter(self.__initialState)
@ -88,45 +89,47 @@ class FSM(DirectObject):
for state in self.__states: for state in self.__states:
if (state.getName() == stateName): if (state.getName() == stateName):
return state return state
FSM.notify.warning("getStateNamed: no such state") FSM.notify.warning("getStateNamed: " + str(stateName) + " no such state")
# basic FSM functionality # basic FSM functionality
def __exitCurrent(self): def __exitCurrent(self, argList):
"""__exitCurrent(self) """__exitCurrent(self)
Exit the current state""" Exit the current state"""
FSM.notify.info("exiting %s" % self.__currentState.getName()) FSM.notify.info("exiting %s" % self.__currentState.getName())
self.__currentState.exit(argList)
messenger.send(self.getName() + '_' + messenger.send(self.getName() + '_' +
self.__currentState.getName() + '_exited') self.__currentState.getName() + '_exited')
self.__currentState.exit()
self.__currentState = None self.__currentState = None
def __enter(self, aState): def __enter(self, aState, argList=[]):
"""__enter(self, State) """__enter(self, State)
Enter a given state, if it exists""" Enter a given state, if it exists"""
if (aState in self.__states): if (aState in self.__states):
self.__currentState = aState self.__currentState = aState
aState.enter() aState.enter(argList)
messenger.send(self.getName() + '_' + messenger.send(self.getName() + '_' +
aState.getName() + '_entered') aState.getName() + '_entered')
FSM.notify.info("entering %s" % aState.getName()) FSM.notify.info("entering %s" % aState.getName())
else: else:
FSM.notify.error("enter: no such state") FSM.notify.error("enter: no such state")
def __transition(self, aState): def __transition(self, aState, enterArgList=[], exitArgList=[]):
"""__transition(self, State) """__transition(self, State, enterArgList, exitArgList)
Exit currentState and enter given one""" Exit currentState and enter given one"""
self.__exitCurrent() self.__exitCurrent(exitArgList)
self.__enter(aState) self.__enter(aState, enterArgList)
def request(self, aStateName): def request(self, aStateName, enterArgList=[], exitArgList=[]):
"""request(self, string) """request(self, string)
Attempt transition from currentState to given one. Attempt transition from currentState to given one.
Return true is transition exists to given state, Return true is transition exists to given state,
false otherwise""" false otherwise"""
if (aStateName in self.__currentState.getTransitions()): if (aStateName in self.__currentState.getTransitions()):
self.__transition(self.getStateNamed(aStateName)) self.__transition(self.getStateNamed(aStateName),
enterArgList,
exitArgList)
return 1 return 1
else: else:
FSM.notify.info("no transition exists to %s" % aStateName) FSM.notify.info("no transition exists to %s" % aStateName)

View File

@ -89,15 +89,15 @@ class State(DirectObject):
Return true if state has child FSMs""" Return true if state has child FSMs"""
return(self.__FSMList != None) return(self.__FSMList != None)
def __enterChildren(self): def __enterChildren(self, argList):
"""__enterChildren(self) """__enterChildren(self, argList)
Enter all child FSMs""" Enter all child FSMs"""
if self.hasChildren(): if self.hasChildren():
for fsm in self.__FSMList: for fsm in self.__FSMList:
fsm.request((fsm.getInitialState()).getName()) fsm.request((fsm.getInitialState()).getName())
def __exitChildren(self): def __exitChildren(self, argList):
"""__exitChildren(self) """__exitChildren(self, argList)
Exit all child FSMs""" Exit all child FSMs"""
if self.hasChildren(): if self.hasChildren():
for fsm in self.__FSMList: for fsm in self.__FSMList:
@ -106,24 +106,24 @@ class State(DirectObject):
# basic State functionality # basic State functionality
def enter(self): def enter(self, argList=[]):
"""enter(self) """enter(self)
Call the enter function for this state""" Call the enter function for this state"""
if (self.__enterFunc != None): if (self.__enterFunc != None):
apply(self.__enterFunc) apply(self.__enterFunc, argList)
#enter child FSMs #enter child FSMs
self.__enterChildren() self.__enterChildren(argList)
def exit(self): def exit(self, argList=[]):
"""exit(self) """exit(self)
Call the exit function for this state""" Call the exit function for this state"""
#first exit child FSMs #first exit child FSMs
self.__exitChildren() self.__exitChildren(argList)
#call exit function if it exists #call exit function if it exists
if (self.__exitFunc != None): if (self.__exitFunc != None):
apply(self.__exitFunc) apply(self.__exitFunc, argList)
def __str__(self): def __str__(self):
"""__str__(self)""" """__str__(self)"""

View File

@ -459,6 +459,17 @@ def enterState():
def exitState(): def exitState():
print 'exitState' print 'exitState'
<<<<<<< FSMInspector.py
fsm = FSM.FSM('stopLight',
[ State.State('red', enterState, exitState, ['green']),
State.State('yellow', enterState, exitState, ['red']),
State.State('green', enterState, exitState, ['yellow']) ],
'red',
'red')
import FSMInspector
inspector = FSMInspector.FSMInspector(FSM = fsm, title = fsm.getName())
=======
# Note, the inspectorPos argument is optional, the inspector will # Note, the inspectorPos argument is optional, the inspector will
# automagically position states on startup # automagically position states on startup
@ -526,5 +537,6 @@ from ShowBaseGlobal import *
import FSMInspector import FSMInspector
inspector = FSMInspector.FSMInspector(fsm, title = fsm.getName()) inspector = FSMInspector.FSMInspector(fsm, title = fsm.getName())
>>>>>>> 1.7
""" """