#include <StateControl.h>
Description
Adds a state machine mechanism to the entity.
Each StateControl instance is effectively a dynamic state machine. After desgnating what states exist within the machine using CreateState(), the machine can be run using Execute(). Using each state's StepFunc, the states will transition until an invalid state is returned. Referring to an invalid state halts the state machine.
It is also entirely valid to modify the state machine mid-execution.
Data Structures | |
struct | StateLoop |
Functions | |
void | CreateState (const std::string &tag, StateLoop) |
void | ConnectState (const std::string &tag, StateLoop) |
void | RemoveState (const std::string &tag) |
void | RemoveLoop (const std::string &tag, StateLoop) |
void | Execute (const std::string &beginState) |
void | Halt () |
bool | IsHalted () |
std::string | GetCurrentState () |
void | OnStep () |
void | OnDraw () |
std::string | GetInfo () |
![]() | |
std::string | GetTag () |
Entity * | GetHost () const |
template<typename T > | |
T * | GetHostAs () const |
Entity::ID | GetHostID () const |
bool | EmitEvent (const std::string &eventName, Entity::ID source=Entity::ID(), const std::vector< std::string > &args={}) |
bool | CanHandleEvent (const std::string &eventName) |
void | InstallHook (const std::string &eventName, EventHandler, void *data=nullptr) |
void | UninstallHook (const std::string &eventName, EventHandler) |
void | InstallHandler (const std::string &eventName, EventHandler, void *data=nullptr) |
void | UninstallHandler (const std::string &eventName, EventHandler) |
std::vector< std::string > | GetKnownEvents () const |
Additional Inherited Members | |
![]() | |
using | EventHandler = bool(*)(void *, Component *component, Entity::ID self, Entity::ID source, const std::vector< std::string > &args) |
![]() | |
virtual void | OnAttach () |
void | InstallEvent (const std::string &eventName, EventHandler mainHandler=nullptr, void *data=nullptr) |
void | UninstallEvent (const std::string &) |
Member Function Documentation
void CreateState | ( | const std::string & | tag, |
StateLoop | |||
) |
void ConnectState | ( | const std::string & | tag, |
StateLoop | |||
) |
Adds an additional StateLoop to be associated with a state.
In addition of any existing state loops associated with the given state tag, this StateLoop will be run as well. The order of state functions is from newest to oldest. If no state yet exists ofthe given tag, this call is equivalent to CreateState()
void RemoveState | ( | const std::string & | tag | ) |
Removes the state.
No action is taken if the tag does not refer to a valid state.
void RemoveLoop | ( | const std::string & | tag, |
StateLoop | |||
) |
Specifically removes the given stateloop if associated with the given state tag.
If tag and StateLoop dont correspond to an existing relationship, no action is taken.
void Execute | ( | const std::string & | beginState | ) |
Begins the state machine execution loop from the given state.
If begin state does not refer to a valid state, no action is taken. If done in the middle of a state loop function, any queued function calls are cancelled.
void Halt | ( | ) |
stops all current execution.
If done during a state loop, all remaining state loop functions that would have executed are cancelled.
bool IsHalted | ( | ) |
Returns whether or not the machine is in a halted state.
std::string GetCurrentState | ( | ) |
Returns the current state tag. If no execution state is active, the empty string is returned.
|
virtual |
|
virtual |
|
virtual |
Returns a string containing human-readable information on the state of the component.
Reimplemented from Component.
The documentation for this class was generated from the following file:
- /home/jc/git/Dynacoe/DynacoeSrc/includes/Dynacoe/Components/StateControl.h