Browse Source

*** empty log message ***

Jesse Schell 25 years ago
parent
commit
c534bcaa87

+ 10 - 0
direct/src/distributed/ClientDistClass.py

@@ -13,6 +13,7 @@ class ClientDistClass:
         self.allCDU = self.createAllCDU(self.allFields)
         self.number2CDU = self.createNumber2CDUDict(self.allCDU)
         self.name2CDU = self.createName2CDUDict(self.allCDU)
+        self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
         return None
 
     def parseFields(self, dcClass):
@@ -39,6 +40,15 @@ class ClientDistClass:
             dict[i.name] = i
         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):
         # Get the update field id
         fieldId = di.getArg(ST_uint8)

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

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

+ 21 - 41
direct/src/distributed/ClientRepository.py

@@ -8,9 +8,10 @@ import DirectNotifyGlobal
 import ClientDistClass
 # The repository must import all known types of Distributed Objects
 import DistributedObject
+import DistributedToon
+import DirectObject
 
-class ClientRepository:
-    defaultServerPort = 5150
+class ClientRepository(DirectObject.DirectObject):
     notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository")
 
     def __init__(self, dcFileName, AIClientFlag=0):
@@ -38,8 +39,7 @@ class ClientRepository:
             self.name2cdc[dcClass.getName()]=clientDistClass
         return None
 
-    def connect(self, serverName="localhost",
-                serverPort=defaultServerPort):
+    def connect(self, serverName, serverPort):
         self.qcm=QueuedConnectionManager()
         self.tcpConn = self.qcm.openTCPClientConnection(
             serverName, serverPort, 1000)
@@ -71,38 +71,26 @@ class ClientRepository:
         return availGetVal
 
     def handleDatagram(self, datagram):
-        di = DatagramIterator(datagram)
-        msgType = di.getArg(STUint16)
-
-        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))
+        # This class is meant to be pure virtual, and any classes that
+        # inherit from it need to make their own handleDatagram method
+        pass
 
     def handleGenerateWithRequired(self, di):
         # Get the class Id
-        classId = di.getArg(STUint8);
+        classId = di.getArg(STUint16);
         # Get the DO Id
         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)
+        distObj = self.generateWithRequiredFields(cdc,
+                                                  eval(cdc.name + \
+                                                       "." + \
+                                                       cdc.name),
+                                                  doId, di)
         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
         # objects to see if this object is in there, and pull it
         # out if necessary. For now, we'll just check to see if
@@ -114,10 +102,15 @@ class ClientRepository:
             ClientRepository.notify.warning("doId: " +
                                             str(doId) +
                                             " was generated again")
-            distObj = self.doId2do(doId)
+            distObj = self.doId2do[doId]
+            distObj.updateRequiredFields(cdc, di)
         else:
             # 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
             self.doId2do[doId] = distObj
             self.doId2cdc[doId] = cdc
@@ -136,19 +129,6 @@ class ClientRepository:
         # Let the cdc finish the job
         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):
         # Get the DO id
         doId = do.doId

+ 9 - 3
direct/src/distributed/DistributedActor.py

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

+ 23 - 3
direct/src/distributed/DistributedNode.py

@@ -1,7 +1,27 @@
 """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:"""
-    pass
+
+    def __init__(self):
+        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])

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

@@ -4,10 +4,24 @@ from PandaObject import *
 
 class DistributedObject(PandaObject):
     """Distributed Object class:"""
-    def __init__(self, doId, di):
-        self.doId=doId
-        self.zone=di.getUint32()
-        assert(di.getRemainingSize() == 0)
+    def __init__(self):
+        pass
+    
+    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):
         cr.sendupdate(self, fieldName, args)
+
+    def taskName(self, taskString):
+        return (taskString + "-" + str(self.getDoId))
+    
+
+

+ 8 - 0
direct/src/distributed/MsgTypes.py

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

+ 16 - 13
direct/src/showbase/FSM.py

@@ -32,7 +32,8 @@ class FSM(DirectObject):
         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.__enter(self.__initialState)
         
@@ -41,7 +42,7 @@ class FSM(DirectObject):
         return "FSM: name = %s \n states = %s \n initial = %s \n final = %s \n current = %s" % (self.__name, self.__states, self.__initialState, self.__finalState, self.__currentState)
 
 
-    #setters and getters
+    # setters and getters
     
     def getName(self):
         """getName(self)"""
@@ -88,45 +89,47 @@ class FSM(DirectObject):
         for state in self.__states:
             if (state.getName() == stateName):
                 return state
-        FSM.notify.warning("getStateNamed: no such state")
+        FSM.notify.warning("getStateNamed: " + str(stateName) + " no such state")
 
 
     # basic FSM functionality
     
-    def __exitCurrent(self):
+    def __exitCurrent(self, argList):
         """__exitCurrent(self)
         Exit the current state"""
         FSM.notify.info("exiting %s" % self.__currentState.getName())
+        self.__currentState.exit(argList)
         messenger.send(self.getName() + '_' +
                        self.__currentState.getName() + '_exited')
-        self.__currentState.exit()
         self.__currentState = None
                     
-    def __enter(self, aState):
+    def __enter(self, aState, argList=[]):
         """__enter(self, State)
         Enter a given state, if it exists"""
         if (aState in self.__states):
             self.__currentState = aState
-            aState.enter()
+            aState.enter(argList)
             messenger.send(self.getName() + '_' +
                            aState.getName() + '_entered')
             FSM.notify.info("entering %s" % aState.getName())
         else:
             FSM.notify.error("enter: no such state")
 
-    def __transition(self, aState):
-        """__transition(self, State)
+    def __transition(self, aState, enterArgList=[], exitArgList=[]):
+        """__transition(self, State, enterArgList, exitArgList)
         Exit currentState and enter given one"""
-        self.__exitCurrent()
-        self.__enter(aState)
+        self.__exitCurrent(exitArgList)
+        self.__enter(aState, enterArgList)
         
-    def request(self, aStateName):
+    def request(self, aStateName, enterArgList=[], exitArgList=[]):
         """request(self, string)
         Attempt transition from currentState to given one.
         Return true is transition exists to given state,
         false otherwise"""
         if (aStateName in self.__currentState.getTransitions()):
-            self.__transition(self.getStateNamed(aStateName))
+            self.__transition(self.getStateNamed(aStateName),
+                              enterArgList,
+                              exitArgList)
             return 1
         else:
             FSM.notify.info("no transition exists to %s" % aStateName)

+ 10 - 10
direct/src/showbase/State.py

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

+ 12 - 0
direct/src/tkpanels/FSMInspector.py

@@ -459,6 +459,17 @@ def enterState():
 
 def 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
 # automagically position states on startup
@@ -526,5 +537,6 @@ from ShowBaseGlobal import *
 import FSMInspector
 inspector = FSMInspector.FSMInspector(fsm, title = fsm.getName())
 
+>>>>>>> 1.7
 """