Panda3D

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
FourState Class Reference

## Public Member Functions
| __init__ (self, names, durations=[0, 1, None, 1, 1])
| changedOnState (self, isOn)
| enterState0 (self)
| state 0 #####
| enterState1 (self)
| state 1 #####
| enterState2 (self)
| state 2 #####
| enterState3 (self)
| state 3 #####
| enterState4 (self)
| state 4 #####
| enterStateN (self, stateIndex)
| exitState0 (self)
| exitState1 (self)
| exitState2 (self)
| exitState3 (self)
| exitState4 (self)
| isOn (self)
| setTrack (self, track)

## Public Attributes
float | duration = self.durations[stateIndex] or 0.0
| durations = durations
| fsm
| names = names
int | stateIndex = 0
dict | states
float | stateTime = 0.0
| track = None

## Static Public Attributes
| notify = DirectNotifyGlobal.directNotify.newCategory('FourState')

## Detailed Description

    Generic four state ClassicFSM base class.

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

    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

## ◆ __init__()

__init__ | ( |  | self,
|  |  | names,
|  |  | durations = [0, 1, None, 1, 1] )

    Names is a list of state names.  Some examples are::

        ['off', 'opening', 'open', 'closing', 'closed',]

        ['off', 'locking', 'locked', 'unlocking', 'unlocked',]

        ['off', 'deactivating', 'deactive', 'activating', 'activated',]

    durations is a list of time values (floats) or None values.

    Each list must have five entries.

    .. rubric:: 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 4 and therefore
    oposite of 'on').

## Member Function Documentation

## ◆ changedOnState()

changedOnState | ( |  | self,
|  |  | isOn )

    Allow derived classes to overide this.

## ◆ enterState0()

enterState0 | ( |  | self | ) |

state 0 #####

## ◆ enterState1()

enterState1 | ( |  | self | ) |

state 1 #####

## ◆ enterState2()

enterState2 | ( |  | self | ) |

state 2 #####

## ◆ enterState3()

enterState3 | ( |  | self | ) |

state 3 #####

## ◆ enterState4()

enterState4 | ( |  | self | ) |

state 4 #####

## ◆ enterStateN()

enterStateN | ( |  | self,
|  |  | stateIndex )

## ◆ exitState0()

exitState0 | ( |  | self | ) |

## ◆ exitState1()

exitState1 | ( |  | self | ) |

## ◆ exitState2()

exitState2 | ( |  | self | ) |

## ◆ exitState3()

exitState3 | ( |  | self | ) |

## ◆ exitState4()

exitState4 | ( |  | self | ) |

## ◆ isOn()

isOn | ( |  | self | ) |

## ◆ setTrack()

setTrack | ( |  | self,
|  |  | track )

## Member Data Documentation

## ◆ duration

float duration = self.durations[stateIndex] or 0.0

## ◆ durations

durations = durations

## ◆ fsm

fsm

Initial value:
= ClassicFSM.ClassicFSM('FourState',
list(self.states.values()),
# Initial State
names[0],
# Final State
names[0],
)

## ◆ names

names = names

## ◆ notify

notify = DirectNotifyGlobal.directNotify.newCategory('FourState')
| static

## ◆ stateIndex

int stateIndex = 0

## ◆ states

dict states

Initial value:
= {
0: State.State(names[0],
self.enterState0,
self.exitState0,
[names[1],
names[2],
names[3],
names[4]]),
1: State.State(names[1],
self.enterState1,
self.exitState1,
[names[2], names[3]]),
2: State.State(names[2],
self.enterState2,
self.exitState2,
[names[3]]),
3: State.State(names[3],
self.enterState3,
self.exitState3,
[names[4], names[1]]),
4: State.State(names[4],
self.enterState4,
self.exitState4,
[names[1]]),
}

## ◆ stateTime

stateTime = 0.0

## ◆ track

track = None