*** empty log message ***

This commit is contained in:
Jesse Schell 2000-10-18 00:27:00 +00:00
parent fb4a5381fe
commit dd0210b095
10 changed files with 120 additions and 61 deletions

View File

@ -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"""

View File

@ -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

View File

@ -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

View File

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

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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)