diff --git a/direct/src/distributed/ClientDistClass.py b/direct/src/distributed/ClientDistClass.py index e216f17b09..aa447c93b4 100644 --- a/direct/src/distributed/ClientDistClass.py +++ b/direct/src/distributed/ClientDistClass.py @@ -14,6 +14,9 @@ class ClientDistClass: self.number2CDU = self.createNumber2CDUDict(self.allCDU) self.name2CDU = self.createName2CDUDict(self.allCDU) self.allRequiredCDU = self.listRequiredCDU(self.allCDU) + # Import the class, and store the constructor + exec("import " + self.name) + self.constructor = eval(self.name + "." + self.name) return None def parseFields(self, dcClass): @@ -25,7 +28,7 @@ class ClientDistClass: def createAllCDU(self, allFields): allCDU = [] for i in allFields: - allCDU.append(ClientDistUpdate.ClientDistUpdate(i)) + allCDU.append(ClientDistUpdate.ClientDistUpdate(self, i)) return allCDU def createNumber2CDUDict(self, allCDU): diff --git a/direct/src/distributed/ClientDistUpdate.py b/direct/src/distributed/ClientDistUpdate.py index b42492dfde..1a7d0be0eb 100644 --- a/direct/src/distributed/ClientDistUpdate.py +++ b/direct/src/distributed/ClientDistUpdate.py @@ -1,21 +1,28 @@ """ClientDistUpdate module: contains the ClientDistUpdate class""" import DirectNotifyGlobal -import Avatar -import DistributedToon import Datagram from MsgTypes import * class ClientDistUpdate: notify = DirectNotifyGlobal.directNotify.newCategory("ClientDistUpdate") - def __init__(self, dcField): + def __init__(self, cdc, dcField): + self.cdc = cdc self.field = dcField self.number = dcField.getNumber() self.name = dcField.getName() self.types = [] self.divisors = [] - self.deriveTypesFromParticle(dcField) + self.deriveTypesFromParticle(dcField) + # Figure out our function pointer + exec("import " + cdc.name) + try: + self.func = eval(cdc.name + "." + cdc.name + "." + self.name) + except: + ClientDistUpdate.notify.warning(cdc.name + "." + self.name + + " does not exist") + self.func = None return None def deriveTypesFromParticle(self, dcField): @@ -37,7 +44,7 @@ class ClientDistUpdate: def updateField(self, cdc, do, di): - func = eval(cdc.name + "." + cdc.name + "." + self.name) + #func = eval(cdc.name + "." + cdc.name + "." + self.name) #print("Calling: " + cdc.name + "." + cdc.name + "." + self.name + # " for do " + str(do.getDoId())) @@ -45,7 +52,7 @@ class ClientDistUpdate: args = self.extractArgs(di) # Apply the function to the object with the arguments - apply(func, [do] + args) + apply(self.func, [do] + args) return None diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index b1a737474f..51ace5396f 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -8,16 +8,16 @@ import Task import DirectNotifyGlobal import ClientDistClass import CRCache +import Datagram # The repository must import all known types of Distributed Objects -import DistributedObject -import DistributedToon +#import DistributedObject +#import DistributedToon import DirectObject class ClientRepository(DirectObject.DirectObject): notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository") - def __init__(self, dcFileName, AIClientFlag=0): - self.AIClientFlag=AIClientFlag + def __init__(self, dcFileName): self.number2cdc={} self.name2cdc={} self.doId2do={} @@ -94,11 +94,8 @@ class ClientRepository(DirectObject.DirectObject): # Look up the cdc cdc = self.number2cdc[classId] # Create a new distributed object, and put it in the dictionary - distObj = self.generateWithRequiredFields(cdc, - eval(cdc.name + \ - "." + \ - cdc.name), - doId, di) + distObj = self.generateWithRequiredFields(cdc, doId, di) + # Call "generate" for the dist obj distObj.generate() return None @@ -110,15 +107,12 @@ class ClientRepository(DirectObject.DirectObject): # Look up the cdc cdc = self.number2cdc[classId] # Create a new distributed object, and put it in the dictionary - distObj = self.generateWithRequiredOtherFields(cdc, - eval(cdc.name + \ - "." + \ - cdc.name), - doId, di) + distObj = self.generateWithRequiredOtherFields(cdc, doId, di) + # Call "generate" for the distObj distObj.generate() return None - def generateWithRequiredFields(self, cdc, constructor, doId, di): + def generateWithRequiredFields(self, cdc, doId, di): # Is it in our dictionary? if self.doId2do.has_key(doId): # If so, just update it. @@ -139,7 +133,7 @@ class ClientRepository(DirectObject.DirectObject): # If it is not in the dictionary or the cache, then... else: # Construct a new one - distObj = constructor(self) + distObj = cdc.constructor(self) # Assign it an Id distObj.doId = doId # Update the required fields @@ -150,7 +144,7 @@ class ClientRepository(DirectObject.DirectObject): return distObj - def generateWithRequiredOtherFields(self, cdc, constructor, doId, di): + def generateWithRequiredOtherFields(self, cdc, doId, di): # Is it in our dictionary? if self.doId2do.has_key(doId): # If so, just update it. @@ -171,7 +165,7 @@ class ClientRepository(DirectObject.DirectObject): # If it is not in the dictionary or the cache, then... else: # Construct a new one - distObj = constructor(self) + distObj = cdc.constructor(self) # Assign it an Id distObj.doId = doId # Update the required fields @@ -242,6 +236,36 @@ class ClientRepository(DirectObject.DirectObject): cdc = self.doId2cdc[doId] # Let the cdc finish the job cdc.updateField(do, di) + return None + + def handleUnexpectedMsgType(self, msgType, di): + ClientRepository.notify.warning( + "Ignoring unexpected message type: " + + str(msgType) + + " in state: " + + self.fsm.getCurrentState().getName()) + return None + + def sendSetShardMsg(self, shardId): + datagram = Datagram.Datagram() + # Add message type + datagram.addUint16(CLIENT_SET_SHARD) + # Add shard id + datagram.addUint32(shardId) + # send the message + self.send(datagram) + return None + + def sendSetZoneMsg(self, zoneId): + datagram = Datagram.Datagram() + # Add message type + datagram.addUint16(CLIENT_SET_ZONE) + # Add zone id + datagram.addUint16(zoneId) + + # send the message + self.send(datagram) + return None def sendUpdate(self, do, fieldName, args): # Get the DO id diff --git a/direct/src/distributed/MsgTypes.py b/direct/src/distributed/MsgTypes.py index 5f562064bb..d274011083 100644 --- a/direct/src/distributed/MsgTypes.py +++ b/direct/src/distributed/MsgTypes.py @@ -4,5 +4,7 @@ CLIENT_OBJECT_UPDATE_FIELD = 24 CLIENT_OBJECT_UPDATE_FIELD_RESP = 24 CLIENT_OBJECT_DISABLE_RESP = 25 CLIENT_OBJECT_DELETE_RESP = 27 +CLIENT_SET_ZONE = 29 +CLIENT_SET_SHARD = 31 CLIENT_CREATE_OBJECT_REQUIRED = 34 CLIENT_CREATE_OBJECT_REQUIRED_OTHER = 35 diff --git a/direct/src/fsm/FSM.py b/direct/src/fsm/FSM.py index fa79189b3e..e4c92f2fbe 100644 --- a/direct/src/fsm/FSM.py +++ b/direct/src/fsm/FSM.py @@ -112,9 +112,9 @@ class FSM(DirectObject): if (aState in self.__states): FSM.notify.debug("entering %s" % aState.getName()) self.__currentState = aState - aState.enter(argList) messenger.send(self.getName() + '_' + aState.getName() + '_entered') + aState.enter(argList) else: FSM.notify.error("enter: no such state")