State Machine System.
More...
State Machine System.
In one of my lame ideas, I created this state machine system. It is overly complex. The idea was that with a simple script, I could create state machine code. The problem is that I made it too complex and confusing. For now, it's in the code, but I want to remove it.
- See Also
- http://www.amuletsandarmor.com/AALicense.txt
#define STATE_MACHINE_INSTANCE_DEAD_TAG (*((T_word32 *)"DsMi")) |
#define STATE_MACHINE_INSTANCE_TAG (*((T_word32 *)"SmIt")) |
#define STATE_MACHINE_STATE_NONE 0xFFFF |
StateMachineCreate starts up an instance of a state machine. Just pass in the state machine you want to execute. Then make calls to StateMachineUpdate.
NOTE: None
- Parameters
-
p_stateMachine | – "Form" of state machine to start up |
- Returns
- Handle to state machine being worked
StateMachineDestroy gets rid of all allocated memory related to a state machine after calling the finish callback.
NOTE: This routine does not do a MemFree on the extra data attached to the the state machine. If there is allocated memory attached, it is up to the caller to maker sure it is either disposed before this routine is called or in the finish callback.
- Parameters
-
handle | – Handle to state machine being worked |
StateMachineGetExtraData returns a pointer to the data associated with this instance of the state machine.
- Parameters
-
handle | – Handle to state machine being worked |
- Returns
- A pointer to the attached data
StateMachineGetState returns the current state number of the given state machine.
NOTE: You should try not to call this routine unless you have very specific states. Should you edit the order of states in the state list, your state indexes/ids are not invalid.
- Parameters
-
handle | – Handle to state machine being worked |
- Returns
- State number
StateMachineGotoState does the work of switching between states and executing callback routines as necessary.
- Parameters
-
handle | – Handle to state machine being worked |
stateNumber | – Number of state to go to |
StateMachineSetExtraData declares what piece of data is attached to the given state machine.
- Parameters
-
handle | – Handle to state machine being worked |
p_data | – Pointer to data |
StateMachineUpdate does the "action" for a state. It checks all the conditions that transition a state to another state. Idle callbacks are only called when there was no state change.
NOTE: This routine will only transition from one state to another. It never does two at a time or string together transitions. If multiple state changes is needed, call this routine multiple times, checking to see if the state changes after each call.
- Parameters
-
handle | – Handle to state machine being worked |