Browse Source

*** empty log message ***

Jesse Schell 25 years ago
parent
commit
dd0210b095

+ 1 - 1
direct/src/actor/Actor.py

@@ -2,7 +2,7 @@
 
 
 from PandaObject import *
 from PandaObject import *
 
 
-class Actor(PandaObject, ShowBase.NodePath):
+class Actor(PandaObject, NodePath):
     """Actor class: Contains methods for creating, manipulating
     """Actor class: Contains methods for creating, manipulating
     and playing animations on characters"""
     and playing animations on characters"""
 
 

+ 8 - 5
direct/src/distributed/ClientDistUpdate.py

@@ -8,24 +8,27 @@ class ClientDistUpdate:
     def __init__(self, dcField):
     def __init__(self, dcField):
         self.number = dcField.getNumber()
         self.number = dcField.getNumber()
         self.name = dcField.getName()
         self.name = dcField.getName()
-        self.types = self.deriveTypesFromParticle(dcField)
+        self.types = []
+        self.divisors = []
+        self.deriveTypesFromParticle(dcField)        
         return None
         return None
 
 
     def deriveTypesFromParticle(self, dcField):
     def deriveTypesFromParticle(self, dcField):
-        typeList=[]
         dcFieldAtomic = dcField.asAtomicField()
         dcFieldAtomic = dcField.asAtomicField()
         dcFieldMolecular = dcField.asMolecularField()
         dcFieldMolecular = dcField.asMolecularField()
         if dcFieldAtomic:
         if dcFieldAtomic:
             for i in range(0, dcFieldAtomic.getNumElements()):
             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:
         elif dcFieldMolecular:
             for i in range(0, dcFieldMolecular.getNumAtomics()):
             for i in range(0, dcFieldMolecular.getNumAtomics()):
                 componentField = dcFieldMolecular.getAtomic(i)
                 componentField = dcFieldMolecular.getAtomic(i)
                 for j in range(0, componentField.getNumElements()):
                 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:
         else:
             ClientDistUpdate.notify.error("field is neither atom nor molecule")
             ClientDistUpdate.notify.error("field is neither atom nor molecule")
-        return typeList
+        return None
 
 
     def updateField(self, cdc, do, di):
     def updateField(self, cdc, do, di):
         # Look up the class
         # Look up the class

+ 23 - 12
direct/src/distributed/ClientRepository.py

@@ -2,9 +2,12 @@
 
 
 from PandaModules import *
 from PandaModules import *
 from TaskManagerGlobal import *
 from TaskManagerGlobal import *
+from MsgTypes import *
 import Task
 import Task
 import DirectNotifyGlobal
 import DirectNotifyGlobal
 import ClientDistClass
 import ClientDistClass
+# The repository must import all known types of Distributed Objects
+import DistributedObject
 
 
 class ClientRepository:
 class ClientRepository:
     defaultServerPort = 5150
     defaultServerPort = 5150
@@ -41,6 +44,7 @@ class ClientRepository:
         self.tcpConn = self.qcm.openTCPClientConnection(
         self.tcpConn = self.qcm.openTCPClientConnection(
             serverName, serverPort, 1000)
             serverName, serverPort, 1000)
         self.qcr=QueuedConnectionReader(self.qcm, 0)
         self.qcr=QueuedConnectionReader(self.qcm, 0)
+        self.qcr.addConnection(self.tcpConn)
         self.cw=ConnectionWriter(self.qcm, 0)
         self.cw=ConnectionWriter(self.qcm, 0)
         self.startReaderPollTask()
         self.startReaderPollTask()
 
 
@@ -57,6 +61,7 @@ class ClientRepository:
     def readerPollOnce(self):
     def readerPollOnce(self):
         availGetVal = self.qcr.dataAvailable()
         availGetVal = self.qcr.dataAvailable()
         if availGetVal:
         if availGetVal:
+            print "Client: Incoming message!"
             datagram = NetDatagram()
             datagram = NetDatagram()
             readRetVal = self.qcr.getData(datagram)
             readRetVal = self.qcr.getData(datagram)
             if readRetVal:
             if readRetVal:
@@ -65,11 +70,13 @@ class ClientRepository:
                 ClientRepository.notify.warning("getData returned false")
                 ClientRepository.notify.warning("getData returned false")
         return availGetVal
         return availGetVal
 
 
-    def handleDatagram(datagram):
+    def handleDatagram(self, datagram):
         di = DatagramIterator(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)
             self.handleGenerateWithRequired(di)
         elif msgType == ALL_OBJECT_UPDATE_FIELD:
         elif msgType == ALL_OBJECT_UPDATE_FIELD:
             self.handleUpdateField(di)
             self.handleUpdateField(di)
@@ -78,20 +85,24 @@ class ClientRepository:
                                             + str(msgType))
                                             + str(msgType))
         return None
         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
         # Get the class Id
-        classId = di.getArg(ST_uint8);
+        classId = di.getArg(STUint8);
         # Get the DO Id
         # 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
         # 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, doId, di)
         return None
         return None
 
 
-    def generateWithRequiredFields(cdc, doId, di):
+    def generateWithRequiredFields(self, cdc, 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
@@ -105,15 +116,15 @@ class ClientRepository:
                                             " was generated again")
                                             " was generated again")
             distObj = self.doId2do(doId)
             distObj = self.doId2do(doId)
         else:
         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
             # Put the new do in both dictionaries
             self.doId2do[doId] = distObj
             self.doId2do[doId] = distObj
             self.doId2cdc[doId] = cdc
             self.doId2cdc[doId] = cdc
             
             
         return distObj
         return distObj
 
 
-    def handleUpdateField(di):
+    def handleUpdateField(self, di):
         # Get the DO Id
         # Get the DO Id
         doId = di.getArg(ST_uint32)
         doId = di.getArg(ST_uint32)
         # Find the DO
         # Find the DO

+ 1 - 1
direct/src/distributed/DistributedNode.py

@@ -2,6 +2,6 @@
 
 
 from DistributedObject import *
 from DistributedObject import *
 
 
-class DistributedNode(DistributedObject, ShowBase.NodePath):
+class DistributedNode(DistributedObject, NodePath):
     """Distributed Node class:"""
     """Distributed Node class:"""
     pass
     pass

+ 4 - 1
direct/src/distributed/DistributedObject.py

@@ -4,4 +4,7 @@ from PandaObject import *
 
 
 class DistributedObject(PandaObject):
 class DistributedObject(PandaObject):
     """Distributed Object class:"""
     """Distributed Object class:"""
-    pass
+    def __init__(self, doId, di):
+        self.doId=doId
+        self.zone=di.getUint32()
+        assert(di.getRemainingSize() == 0)

+ 16 - 3
direct/src/distributed/ServerRepository.py

@@ -2,6 +2,7 @@
 
 
 from PandaModules import *
 from PandaModules import *
 from TaskManagerGlobal import *
 from TaskManagerGlobal import *
+from MsgTypes import *
 import Task
 import Task
 import DirectNotifyGlobal
 import DirectNotifyGlobal
 
 
@@ -74,11 +75,23 @@ class ServerRepository:
         print dgi.getUint16()
         print dgi.getUint16()
 
 
         newDatagram = Datagram()
         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
         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):
     def startResetPollTask(self):
         return None
         return None
     
     

+ 9 - 9
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
         # Import the type numbers
         from DCSubatomicType import *
         from DCSubatomicType import *
         if subatomicType == STInt8:
         if subatomicType == STInt8:
-            self.addInt8(arg)
+            self.addInt8(int(arg*divisor))
         elif subatomicType == STInt16:
         elif subatomicType == STInt16:
-            self.addInt16(arg)
+            self.addInt16(int(arg*divisor))
         elif subatomicType == STInt32:
         elif subatomicType == STInt32:
-            self.addInt32(arg)
+            self.addInt32(int(arg*divisor))
         elif subatomicType == STInt64:
         elif subatomicType == STInt64:
-            self.addInt64(arg)
+            self.addInt64(int(arg*divisor))
         elif subatomicType == STUint8:
         elif subatomicType == STUint8:
-            self.addUint8(arg)
+            self.addUint8(int(arg*divisor))
         elif subatomicType == STUint16:
         elif subatomicType == STUint16:
-            self.addUint16(arg)
+            self.addUint16(int(arg*divisor))
         elif subatomicType == STUint32:
         elif subatomicType == STUint32:
-            self.addUint32(arg)
+            self.addUint32(int(arg*divisor))
         elif subatomicType == STUint64:
         elif subatomicType == STUint64:
-            self.addUint64(arg)
+            self.addUint64(int(arg*divisor))
         elif subatomicType == STFloat64:
         elif subatomicType == STFloat64:
             self.addFloat64(arg)
             self.addFloat64(arg)
         elif subatomicType == STString:
         elif subatomicType == STString:

+ 51 - 22
direct/src/extensions/DatagramIterator-extensions.py

@@ -1,29 +1,58 @@
 
 
-    def getArg(self, subatomicType):
+    def getArg(self, subatomicType, divisor=1):
         # Import the type numbers
         # Import the type numbers
         from DCSubatomicType import *
         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:
         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
         return retVal
 
 
                 
                 

+ 5 - 5
direct/src/ffi/FFIOverload.py

@@ -34,10 +34,11 @@ def getTypeName(classTypeDesc, typeDesc):
     # Python types. This code sorts out the mapping
     # Python types. This code sorts out the mapping
     if typeDesc.isAtomic():
     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
         # Enums are special and are not atomic, see below
         if ((typeDesc.atomicType == AT_int) or
         if ((typeDesc.atomicType == AT_int) or
-            (typeDesc.atomicType == AT_bool)):
+            (typeDesc.atomicType == AT_bool) or
+            (typeDesc.atomicType == AT_char)):
             return 'types.IntType'
             return 'types.IntType'
         
         
         # Floats and doubles are both floats in Python
         # Floats and doubles are both floats in Python
@@ -45,9 +46,8 @@ def getTypeName(classTypeDesc, typeDesc):
             (typeDesc.atomicType == AT_double)):
             (typeDesc.atomicType == AT_double)):
             return 'types.FloatType'
             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'
             return 'types.StringType'
         
         
         elif (typeDesc.atomicType == AT_void):
         elif (typeDesc.atomicType == AT_void):

+ 2 - 2
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()
     Font = loader.loadModelOnce("fonts/ttf-comic").node()
 
 
@@ -17,7 +17,7 @@ class OnscreenText(PandaObject, ShowBase.NodePath):
         NodePath.__init__(self)
         NodePath.__init__(self)
 
 
         # make a text node
         # make a text node
-        textNode = ShowBase.TextNode()
+        textNode = TextNode()
         textNode.setBillboard(0)
         textNode.setBillboard(0)
         textNode.setTextColor(0.0, 0.0, 0.0, 1.0)
         textNode.setTextColor(0.0, 0.0, 0.0, 1.0)
         textNode.setCardColor(1.0, 1.0, 1.0, 1.0)
         textNode.setCardColor(1.0, 1.0, 1.0, 1.0)