Skip to content

Instantly share code, notes, and snippets.

@Zal0
Created November 2, 2018 17:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zal0/925bbfaaf2af70be4664d2656b2b89bc to your computer and use it in GitHub Desktop.
Save Zal0/925bbfaaf2af70be4664d2656b2b89bc to your computer and use it in GitHub Desktop.
C++ FSM implementation
#include "FSM.h"
FSM::FSM() :
state(0)
{
}
void FSM::Update()
{
if(state)
{
state->Update();
}
}
void FSM::FixedUpdate()
{
if(state)
{
state->FixedUpdate();
}
}
void FSM::SetStateCommon(State* new_state)
{
if(state)
{
state->Exit();
state->fsm = 0;
}
state = new_state;
if(state)
{
state->fsm = this;
}
}
void FSM::SetState(State0Params* state)
{
State* old_state = this->state;
SetStateCommon(state);
if(state)
state->Enter();
OnStatusChanged(old_state, state);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment