Original Post
Greetings! I was wondering if there is allready a simple C++ State Machine implemented allready? I would need just some interfaces for:
class IState
{
public:
virtual void Enter() = 0;
virtual void Exit() = 0;
virtual void Input() = 0;
virtual void Transition() = 0;
};
class StateMachine
{
private:
std::vector< IState* > m_States;
IState* m_pActive;
public:
void Add( IState* pState ) { m_States.push_back( pState ); }
void Select( IState* pState ) { m_pActive = pState; }
void Pulse( void ) { m_pActive->Input(); }
};
The question is, is there any predesigned template that I could use? My problem is, how should the IState manage to change a State? It must call the StateMachine or perhaps does it need to return a number or something like that? I would like to achive reusable code altough Input() might mislead that it gets called when a player hits a key or mouse or joystick device? What Actions should be implemented and which parameters should be passed? Thank you in advance!