Amulets & Armor  v1.02
Open Source Game
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Functions
SMACHINE

State Machine System. More...

Data Structures

struct  T_stateMachineInstance
 

Macros

#define STATE_MACHINE_INSTANCE_DEAD_TAG   (*((T_word32 *)"DsMi"))
 
#define STATE_MACHINE_INSTANCE_TAG   (*((T_word32 *)"SmIt"))
 
#define STATE_MACHINE_STATE_NONE   0xFFFF
 

Functions

T_stateMachineHandle StateMachineCreate (T_stateMachine *p_stateMachine)
 
T_void StateMachineDestroy (T_stateMachineHandle handle)
 
T_voidStateMachineGetExtraData (T_stateMachineHandle handle)
 
T_word16 StateMachineGetState (T_stateMachineHandle handle)
 
T_void StateMachineGotoState (T_stateMachineHandle handle, T_word16 stateNumber)
 
T_void StateMachineSetExtraData (T_stateMachineHandle handle, T_void *p_data)
 
T_void StateMachineUpdate (T_stateMachineHandle handle)
 

Detailed Description

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

Macro Definition Documentation

#define STATE_MACHINE_INSTANCE_DEAD_TAG   (*((T_word32 *)"DsMi"))
#define STATE_MACHINE_INSTANCE_TAG   (*((T_word32 *)"SmIt"))
#define STATE_MACHINE_STATE_NONE   0xFFFF

Function Documentation

T_stateMachineHandle StateMachineCreate ( T_stateMachine p_stateMachine)

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
T_void StateMachineDestroy ( T_stateMachineHandle  handle)

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
T_void* StateMachineGetExtraData ( T_stateMachineHandle  handle)

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
T_word16 StateMachineGetState ( T_stateMachineHandle  handle)

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
T_void StateMachineGotoState ( T_stateMachineHandle  handle,
T_word16  stateNumber 
)

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
T_void StateMachineSetExtraData ( T_stateMachineHandle  handle,
T_void p_data 
)

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
T_void StateMachineUpdate ( T_stateMachineHandle  handle)

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