@DevReign Maybe an easier example: I wrote a chemical drawing program, which responds differently to mousemove and LMB down messages depending on the tool the user selected. My first draft looked like this:
select (ToolType)
{
case DrawingTool: DrawStuff(); break;
case LassoTool: SelectStuff(); break;
case EraserTool: EraseStuff(); break;
[a ton more case statements]
}
Now, I just set a pointer when the user selects the tool. The whole switch statement gets replaced with
if (pTool≠nullptr)
pTool→DoStuff();
It's a programming pattern, I can't remember the name.
I did the same thing with my ‘Game Stages’. In my game loop, I had another switch statement like:
Select (MyStage)
{
case: GameStage: PlayGame(); break;
case HiScoresStage: ShowHighScores(); break;
case TitleStage: ShowGameTitle(); break;
}
Now, I have a BaseStage, and the GameStage, TitleStage, HiScoreStage, PauseStage,CreditsStage that all inherit from it.
The big switch statement in my game loop is replace by
pCurrentStage→Update(DeltaTime);
If the user hits ‘Escape’ in the GameStage, then pCurrentStage = pGameStage(); and the game is paused. When the user hits escape in the pause stage, then pCurrentStage=pGameStage and the game continues.
You can do the same thing with FSMs. For example if a robot spots the player while in the PatrolState, then pRobotState = pPursueState(pPlayer). If the Robot looses line of sight with the player while in the PursueState, then pRobotState = pSearchState.
It's maybe a little more complicated than it sounds, but it's explained well in that book I mentioned.