Original Post
Greetings! I really have a design problem on that one. Feel free to post any better suggestions or hints. So I was wondering, how could I implement virtual sub applications in my game like a state machine? The idea is as follows: Let us say, we have 3 states, Menu, Configuration and Game Play. I would like a class from which everything is derived like this:
class CMenu : public CApplet etc...
class COptions : public CApplet etc...
class CPlaytime : public CApplat etc..
And then in the main loop:
CApplication app;
app.add(new CMenu(), 100);
app.add(new COptions(), 200);
app.add(new CPlaytime(), 300);
The main problem is, how should the CMenu for example tell CApplication that it is time to go to CPlaytime ? One of my ideas was as following:
bool CMenu::Update(float fTimeElapsed, int* changeID)
{
//if anything went wrong, return false it will safe tear down the game
if (KeyDown(DIK_F1)) *changeID = 300;
return true; //update slice was successful
}
And now the CApplication class would check was the update successful? If yes then check if changeID != 0, if so, then change the state. In case that the update failed tear down the game. Does anyone have a better suggestion? I would like to avoid something like that:
int WINAPI ProcessMessages(....)
{
switch (uMsg)
{
case WM_PAINT:
if (State == MENU) DrawMenu();
if (State == GAME) DrawGame();
break;
}
}
The idea is allso that the CApplet does not need to now about the CApplication. I would like to avoid useless parameter passing all the way long. Each CApplet could have an uniqe ID and so the applets could switch. Perhaps there is allready a state machine implemented that does exactly that? Each game dev book I read uses its own state machine for just one state - game play. I do not need a state machine for just one state. I want several states. Thank you in advance!