Panda3D
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
FourStateAI Class Reference

Public Member Functions

def __init__
 
def changedOnState
 
def debugPrint
 
def delete
 
def distributeStateChange
 
def enterState0
 state 0 ##### More...
 
def enterState1
 state 1 ##### More...
 
def enterState2
 state 2 ##### More...
 
def enterState3
 state 3 ##### More...
 
def enterState4
 state 4 ##### More...
 
def enterStateN
 
def exitState0
 
def exitState1
 
def exitState2
 
def exitState3
 
def exitState4
 
def exitStateN
 
def getState
 
def isOn
 
def sendState
 
def setIsOn
 
def switchToNextStateTask
 states ##### More...
 

Public Attributes

 doLaterTask
 
 durations
 
 fsm
 
 names
 
 nextStateIndex
 
 stateIndex
 
 states
 

Static Public Attributes

tuple notify = DirectNotifyGlobal.directNotify.newCategory('FourStateAI')
 

Detailed Description

Generic four state ClassicFSM base class.

This is a mix-in class that expects that your derived class
is a DistributedObjectAI.

Inherit from FourStateFSM and pass in your states.  Two of 
the states should be oposites of each other and the other 
two should be the transition states between the first two.
E.g.

                +--------+
             -->| closed | --
            |   +--------+   |
            |                |
            |                v
      +---------+       +---------+
      | closing |<----->| opening |
      +---------+       +---------+
            ^                |
            |                |
            |    +------+    |
             ----| open |<---
                 +------+

There is a fifth off state, but that is an implementation
detail (and that's why it's not called a five state ClassicFSM).

I found that this pattern repeated in several things I was
working on, so this base class was created.

Constructor & Destructor Documentation

def __init__ (   self,
  names,
  durations = [0,
  None 
)
names is a list of state names
    E.g.
['off', 'opening', 'open', 'closing', 'closed',]

    e.g. 2:
['off', 'locking', 'locked', 'unlocking', 'unlocked',]

    e.g. 3:
['off', 'deactivating', 'deactive', 'activating', 'activated',]

durations is a list of durations in seconds or None values.
    The list of duration values should be the same length
    as the list of state names and the lists correspond.
    For each state, after n seconds, the ClassicFSM will move to 
    the next state.  That does not happen for any duration
    values of None.

More Details

Here is a diagram showing the where the names from the list
are used:

    +---------+
    | 0 (off) |----> (any other state and vice versa).
    +---------+

       +--------+
    -->| 4 (on) |---
   |   +--------+   |
   |                |
   |                v
     +---------+       +---------+
     | 3 (off) |<----->| 1 (off) |
     +---------+       +---------+
   ^                |
   |                |
   |  +---------+   |
    --| 2 (off) |<--
      +---------+

Each states also has an associated on or off value.  The only
state that is 'on' is state 4.  So, the transition states
between off and on (states 1 and 3) are also considered 
off (and so is state 2 which is oposite of state 4 and therefore 
oposite of 'on').

Member Function Documentation

def changedOnState (   self,
  isOn 
)
Allow derived classes to overide this.
The self.isOn value has toggled.  Call getIsOn() to
get the current state.
def debugPrint (   self,
  message 
)
for debugging
def delete (   self)
def distributeStateChange (   self)
This function is intentionaly simple so that derived classes 
may easily alter the network message.
def enterState0 (   self)

state 0 #####

def enterState1 (   self)

state 1 #####

def enterState2 (   self)

state 2 #####

def enterState3 (   self)

state 3 #####

def enterState4 (   self)

state 4 #####

def enterStateN (   self,
  stateIndex,
  nextStateIndex 
)
def exitState0 (   self)
def exitState1 (   self)
def exitState2 (   self)
def exitState3 (   self)
def exitState4 (   self)
def exitStateN (   self)
def getState (   self)
def isOn (   self)
def sendState (   self)
def setIsOn (   self,
  isOn 
)
def switchToNextStateTask (   self,
  task 
)

states #####

Member Data Documentation

doLaterTask
durations
fsm
names
nextStateIndex
tuple notify = DirectNotifyGlobal.directNotify.newCategory('FourStateAI')
static
stateIndex
states