diff --git a/direct/src/actor/Actor.py b/direct/src/actor/Actor.py index 7a1f309845..f89a5830fa 100644 --- a/direct/src/actor/Actor.py +++ b/direct/src/actor/Actor.py @@ -2,7 +2,7 @@ from PandaObject import * -class Actor(PandaObject, ShowBase.NodePath): +class Actor(PandaObject, NodePath): """Actor class: Contains methods for creating, manipulating and playing animations on characters""" diff --git a/direct/src/distributed/ClientDistUpdate.py b/direct/src/distributed/ClientDistUpdate.py index 60c450c490..2422dec6a5 100644 --- a/direct/src/distributed/ClientDistUpdate.py +++ b/direct/src/distributed/ClientDistUpdate.py @@ -8,24 +8,27 @@ class ClientDistUpdate: def __init__(self, dcField): self.number = dcField.getNumber() self.name = dcField.getName() - self.types = self.deriveTypesFromParticle(dcField) + self.types = [] + self.divisors = [] + self.deriveTypesFromParticle(dcField) return None def deriveTypesFromParticle(self, dcField): - typeList=[] dcFieldAtomic = dcField.asAtomicField() dcFieldMolecular = dcField.asMolecularField() if dcFieldAtomic: for i in range(0, dcFieldAtomic.getNumElements()): - typeList.append(dcFieldAtomic.getElementType(i)) + self.types.append(dcFieldAtomic.getElementType(i)) + self.divisors.append(dcFieldAtomic.getElementDivisor(i)) elif dcFieldMolecular: for i in range(0, dcFieldMolecular.getNumAtomics()): componentField = dcFieldMolecular.getAtomic(i) for j in range(0, componentField.getNumElements()): - typeList.append(componentField.getElementType(j)) + self.types.append(componentField.getElementType(j)) + self.types.append(componentField.getElementDivisor(j)) else: ClientDistUpdate.notify.error("field is neither atom nor molecule") - return typeList + return None def updateField(self, cdc, do, di): # Look up the class diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index da5bc0b70c..e9dc9e3e6c 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -2,9 +2,12 @@ from PandaModules import * from TaskManagerGlobal import * +from MsgTypes import * import Task import DirectNotifyGlobal import ClientDistClass +# The repository must import all known types of Distributed Objects +import DistributedObject class ClientRepository: defaultServerPort = 5150 @@ -41,6 +44,7 @@ class ClientRepository: self.tcpConn = self.qcm.openTCPClientConnection( serverName, serverPort, 1000) self.qcr=QueuedConnectionReader(self.qcm, 0) + self.qcr.addConnection(self.tcpConn) self.cw=ConnectionWriter(self.qcm, 0) self.startReaderPollTask() @@ -57,6 +61,7 @@ class ClientRepository: def readerPollOnce(self): availGetVal = self.qcr.dataAvailable() if availGetVal: + print "Client: Incoming message!" datagram = NetDatagram() readRetVal = self.qcr.getData(datagram) if readRetVal: @@ -65,11 +70,13 @@ class ClientRepository: ClientRepository.notify.warning("getData returned false") return availGetVal - def handleDatagram(datagram): + def handleDatagram(self, datagram): di = DatagramIterator(datagram) - msgType = di.getArg(ST_uint16) + msgType = di.getArg(STUint16) - if msgType == ALL_OBJECT_GENERATE_WITH_REQUIRED: + 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) @@ -78,20 +85,24 @@ class ClientRepository: + str(msgType)) return None - def handleGenerateWithRequired(di): + 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): # Get the class Id - classId = di.getArg(ST_uint8); + classId = di.getArg(STUint8); # Get the DO Id - doId = di.getArg(ST_uint32) - # Get the echo context - echoContext = di.getArg(ST_uint32); + doId = di.getArg(STUint32) # Look up the cdc cdc = self.number2cdc[classId] # Create a new distributed object, and put it in the dictionary distObj = self.generateWithRequiredFields(cdc, doId, di) return None - def generateWithRequiredFields(cdc, doId, di): + def generateWithRequiredFields(self, cdc, doId, di): # Someday, this function will look in a cache of old distributed # objects to see if this object is in there, and pull it # out if necessary. For now, we'll just check to see if @@ -105,15 +116,15 @@ class ClientRepository: " was generated again") distObj = self.doId2do(doId) else: - distObj = \ - eval(cdc.name).generateWithRequiredFields(doId, di) + # Construct a new one + distObj = eval(cdc.name + "." + cdc.name)(doId, di) # Put the new do in both dictionaries self.doId2do[doId] = distObj self.doId2cdc[doId] = cdc return distObj - def handleUpdateField(di): + def handleUpdateField(self, di): # Get the DO Id doId = di.getArg(ST_uint32) # Find the DO diff --git a/direct/src/distributed/DistributedNode.py b/direct/src/distributed/DistributedNode.py index ec35e41c8a..e6ee483a9d 100644 --- a/direct/src/distributed/DistributedNode.py +++ b/direct/src/distributed/DistributedNode.py @@ -2,6 +2,6 @@ from DistributedObject import * -class DistributedNode(DistributedObject, ShowBase.NodePath): +class DistributedNode(DistributedObject, NodePath): """Distributed Node class:""" pass diff --git a/direct/src/distributed/DistributedObject.py b/direct/src/distributed/DistributedObject.py index 749577c563..1b1203c1da 100644 --- a/direct/src/distributed/DistributedObject.py +++ b/direct/src/distributed/DistributedObject.py @@ -4,4 +4,7 @@ from PandaObject import * class DistributedObject(PandaObject): """Distributed Object class:""" - pass + def __init__(self, doId, di): + self.doId=doId + self.zone=di.getUint32() + assert(di.getRemainingSize() == 0) diff --git a/direct/src/distributed/ServerRepository.py b/direct/src/distributed/ServerRepository.py index 532d770a04..26f155d743 100644 --- a/direct/src/distributed/ServerRepository.py +++ b/direct/src/distributed/ServerRepository.py @@ -2,6 +2,7 @@ from PandaModules import * from TaskManagerGlobal import * +from MsgTypes import * import Task import DirectNotifyGlobal @@ -74,11 +75,23 @@ class ServerRepository: print dgi.getUint16() newDatagram = Datagram() - datagram.addUint16(2) - datagram.addUint8(ord('s')) - self.cw.send(datagram, self.lastConnection) + newDatagram.addUint16(LOGIN_RESPONSE) + newDatagram.addUint8(ord('s')) + self.cw.send(newDatagram, self.lastConnection) return None + def sendAvatarGenerate(self): + datagram = Datagram() + # Message type is 1 + datagram.addUint16(ALL_OBJECT_GENERATE_WITH_REQUIRED) + # Avatar class type is 2 + datagram.addUint8(2) + # A sample id + datagram.addUint32(10) + # The only required field is the zone field + datagram.addUint32(999) + self.cw.send(datagram, self.lastConnection) + def startResetPollTask(self): return None diff --git a/direct/src/extensions/Datagram-extensions.py b/direct/src/extensions/Datagram-extensions.py index 8580162c24..76694f4376 100644 --- a/direct/src/extensions/Datagram-extensions.py +++ b/direct/src/extensions/Datagram-extensions.py @@ -1,23 +1,23 @@ - def putArg(self, arg, subatomicType): + def putArg(self, arg, subatomicType, divisor=1): # Import the type numbers from DCSubatomicType import * if subatomicType == STInt8: - self.addInt8(arg) + self.addInt8(int(arg*divisor)) elif subatomicType == STInt16: - self.addInt16(arg) + self.addInt16(int(arg*divisor)) elif subatomicType == STInt32: - self.addInt32(arg) + self.addInt32(int(arg*divisor)) elif subatomicType == STInt64: - self.addInt64(arg) + self.addInt64(int(arg*divisor)) elif subatomicType == STUint8: - self.addUint8(arg) + self.addUint8(int(arg*divisor)) elif subatomicType == STUint16: - self.addUint16(arg) + self.addUint16(int(arg*divisor)) elif subatomicType == STUint32: - self.addUint32(arg) + self.addUint32(int(arg*divisor)) elif subatomicType == STUint64: - self.addUint64(arg) + self.addUint64(int(arg*divisor)) elif subatomicType == STFloat64: self.addFloat64(arg) elif subatomicType == STString: diff --git a/direct/src/extensions/DatagramIterator-extensions.py b/direct/src/extensions/DatagramIterator-extensions.py index a91f63232e..ee839e7569 100644 --- a/direct/src/extensions/DatagramIterator-extensions.py +++ b/direct/src/extensions/DatagramIterator-extensions.py @@ -1,29 +1,58 @@ - def getArg(self, subatomicType): + def getArg(self, subatomicType, divisor=1): # Import the type numbers from DCSubatomicType import * - if subatomicType == STInt8: - retVal = self.getInt8() - elif subatomicType == STInt16: - retVal = self.getInt16() - elif subatomicType == STInt32: - retVal = self.getInt32() - elif subatomicType == STInt64: - retVal = self.getInt64() - elif subatomicType == STUint8: - retVal = self.getUint8() - elif subatomicType == STUint16: - retVal = self.getUint16() - elif subatomicType == STUint32: - retVal = self.getUint32() - elif subatomicType == STUint64: - retVal = self.getUint64() - elif subatomicType == STFloat64: - retVal = self.getFloat64() - elif subatomicType == STString: - retVal = self.getString() + if divisor == 1: + # No division necessary + if subatomicType == STInt8: + retVal = self.getInt8() + elif subatomicType == STInt16: + retVal = self.getInt16() + elif subatomicType == STInt32: + retVal = self.getInt32() + elif subatomicType == STInt64: + retVal = self.getInt64() + elif subatomicType == STUint8: + retVal = self.getUint8() + elif subatomicType == STUint16: + retVal = self.getUint16() + elif subatomicType == STUint32: + retVal = self.getUint32() + elif subatomicType == STUint64: + retVal = self.getUint64() + elif subatomicType == STFloat64: + retVal = self.getFloat64() + elif subatomicType == STString: + retVal = self.getString() + else: + raise Exception("Error: No such type as: " + str(subAtomicType)) else: - raise Exception("Error: No such type as: " + str(subAtomicType)) + # This needs to be divided + if subatomicType == STInt8: + retVal = (self.getInt8()/float(divisor)) + elif subatomicType == STInt16: + retVal = (self.getInt16()/float(divisor)) + elif subatomicType == STInt32: + retVal = (self.getInt32()/float(divisor)) + elif subatomicType == STInt64: + retVal = (self.getInt64()/float(divisor)) + elif subatomicType == STUint8: + retVal = (self.getUint8()/float(divisor)) + elif subatomicType == STUint16: + retVal = (self.getUint16()/float(divisor)) + elif subatomicType == STUint32: + retVal = (self.getUint32()/float(divisor)) + elif subatomicType == STUint64: + retVal = (self.getUint64()/float(divisor)) + elif subatomicType == STFloat64: + retVal = self.getFloat64() + elif subatomicType == STString: + retVal = self.getString() + else: + raise Exception("Error: No such type as: " + str(subAtomicType)) + + + return retVal diff --git a/direct/src/ffi/FFIOverload.py b/direct/src/ffi/FFIOverload.py index b040a27b6c..302088c0c4 100644 --- a/direct/src/ffi/FFIOverload.py +++ b/direct/src/ffi/FFIOverload.py @@ -34,10 +34,11 @@ def getTypeName(classTypeDesc, typeDesc): # Python types. This code sorts out the mapping if typeDesc.isAtomic(): - # Ints and bools are treated as ints. + # Ints, bools, and chars are treated as ints. # Enums are special and are not atomic, see below if ((typeDesc.atomicType == AT_int) or - (typeDesc.atomicType == AT_bool)): + (typeDesc.atomicType == AT_bool) or + (typeDesc.atomicType == AT_char)): return 'types.IntType' # Floats and doubles are both floats in Python @@ -45,9 +46,8 @@ def getTypeName(classTypeDesc, typeDesc): (typeDesc.atomicType == AT_double)): return 'types.FloatType' - # Strings and individual chars are treated as Python strings - elif ((typeDesc.atomicType == AT_char) or - (typeDesc.atomicType == AT_string)): + # Strings are treated as Python strings + elif ((typeDesc.atomicType == AT_string)): return 'types.StringType' elif (typeDesc.atomicType == AT_void): diff --git a/direct/src/showbase/OnscreenText.py b/direct/src/showbase/OnscreenText.py index 695095c55a..592447795e 100644 --- a/direct/src/showbase/OnscreenText.py +++ b/direct/src/showbase/OnscreenText.py @@ -4,7 +4,7 @@ from PandaObject import * -class OnscreenText(PandaObject, ShowBase.NodePath): +class OnscreenText(PandaObject, NodePath): Font = loader.loadModelOnce("fonts/ttf-comic").node() @@ -17,7 +17,7 @@ class OnscreenText(PandaObject, ShowBase.NodePath): NodePath.__init__(self) # make a text node - textNode = ShowBase.TextNode() + textNode = TextNode() textNode.setBillboard(0) textNode.setTextColor(0.0, 0.0, 0.0, 1.0) textNode.setCardColor(1.0, 1.0, 1.0, 1.0)