Files changed (4)
+A statemachine has certain input it has to process. Depending on the current state and the kind of input, the statemachine can might perform some actions whether it changes state or not. There are three types of actions: entry, exit and transition action. The entry and exit actions are bound to a state and are executed whenever that state is entered of left (also when an external self transition is done).
+So to use sympleHFSM you will have to define the input and the actions it can perform. The input are just symbols that are passed to the 'event_handle' method of the statemachine instance. This method will handle the input and perform the corresponding actions. Therefore you need to pass in an instance of the actions class you want to use at creation time of the statemachine instance (this way you can use different 'backends', especially for testing). The second thing the statemachine instance needs to know is the structure. By structure I mean the number of states that exists and their relationship between them. This is the parent-child relationship and of course the transitions between them.
+The mousefollower example has a pretty simple statemachine: just three states: idle, following and a parent state
+ 1. The input events are define. The mouse follower has a sensor that give the event 'in_range' if the mouse is in
+ range. Otherwise it will generate an 'out_of_range' event. There is also the 'update' event because it should
+ behave differently depending in which state it is. In idle state it will just do nothing (there is no action
+ 2. The actions the state machine can perform are defined. There are two entry actions defined and an update action.
+ The entry action for the idle state named as 'idle_entry' and entry action for the following state named
+ 3. Points 1 and 2 just define the 'interfaces' of the state machine, what its input is and what actions
+ (sort of output) it will perform. Now in point 3 the structure and the transitions are defined. First
+ the states are added. The spaces before 'idle' and 'following' state identifier should indicate that they are
+ both children of the 'parent' state. The only state that has no parent is the root state (here called 'parent').
+ The initial flag is to determine which leaf state the state machine should change in case a transition ends in
+ a state that is not a leaf. So in this case if a transition would end at the 'parent' state then it would
+ change to the idle state. For each level there can only be one initial state. In those lines of code also
+ the entry actions are defined (explanation methodcaller seel _). In the next three lines the transitions
+ are added. There are three transitions (this are the arrows in the picture). Only the self transitions in
+ the 'following' state for the update event has an action to call. Its the 'following_update' action. Now
+ 4. Here the actual actions for the entity are implemented. The 'following_update' action just does move the
+ entity in direction of the mouse. The other two actions are the entry actions for the two substates, they
+ 5. Now here the state machine will be instantiated. The structure is passed in and the well an instance of
+ the actions pointing to that instance of the entity (so the action can manipulate the entity). To make
+ the state machine work, input events need to be passed to the state machine. This will happen in the
+ update method of the entity. There the proximity sensor will detect the mouse and then a corresponding
+ event (in_range or out_of_range) is generated and passed to the state machine. This might change the state,
+ depending in which state it is and what event it gets. Then the update event is also passed to the state
+I hope this made some things clear. There is much more to it. Take a look at the symplehfsm_demo _ for a more
+..  https://bitbucket.org/dr0id/symplehfsm/src/d9229897f4e6/trunk/symplehfsm/examples/mousefollower/mousefollower.py
+..  https://bitbucket.org/dr0id/symplehfsm/src/d9229897f4e6/trunk/symplehfsm/examples/TestHFSM/symplehfsm_demo.py
+ .. todo:: rename to SympleHFSM ?? (dict does explain an implementationdetail..., symple is actually also not good)
# TODO: redo tests using a real states and a fully implemented statemachine (event-, action-interface, etc)