State Manager/Machine?

I can not figure out how to make one thing happen after another in OpenGL. The way i do it(www.gametutorial.com’s base code) makes things happen every frame, so i couldnt go from an intro into a spinning cube to something else. gametutorial’s said that you would use a State Manager/Machine but i have no idea what they are. Could anyone help?

Hi !

A very simple example, create an integer variable, initialize it to zero and then fire away the rendering, increment it for each frame or something like that.

When this variable (let’s call it “state”) is less then 20 for example you display the intro (if it is 20 frames) and depending on the value of state (0-19) you display the correct frame for the intro, when state comes to 20, the intro is over and the application can start.

This is a pretty useless example and not in any way how you should do it, it was just a very simple example on how you could do it.

You just keep one or more variables that contains the “state” of you application at one specific point in time, and as your application goes on running the “state” is updated to reflect the current state at all time.

Hmmmm, hope you get the idea here, it’s a bit tricky to explain.

Mikael

Here is an example, of one way to do it. This example could be writen a many diffrent ways:

My_state_machine()
{
int My_state;

while ( My_state < number_of_states_to_process )
{

if (My_state == 0)
{
Open_scene(run_time); // run_time is how long you want each scene to run or could be number of frames to loop before returning…
My_state++;
}
if (My_state == 1)
{
Cube_scene(run_time);
My_state++;
}
if (My_state == 2)
{
End_scene(run_time);
exit; // Exit Demo
}
}
}

Originally posted by Tazar:
I can not figure out how to make one thing happen after another in OpenGL. The way i do it(www.gametutorial.com’s base code) makes things happen every frame, so i couldnt go from an intro into a spinning cube to something else. gametutorial’s said that you would use a State Manager/Machine but i have no idea what they are. Could anyone help?

[This message has been edited by nexusone (edited 05-20-2002).]

[This message has been edited by nexusone (edited 05-20-2002).]

If you are feeling brave, you could use a pointer to a static virtual function as your event handler' - rather than an ever increasing set ofif time > x then’ statements. However, if you just want an intro and a spinning cube afterwards, that method is fine.

Hardcoding engine states sucks imo. The engine should only have one mode: real app.
Menu can be added as a dummy map with foreground (as you can have the menu even when currently running the app), intro’s sound like being well done with scripted features of the engine.
Also switching the state on a frame basis instead of a time basis sounds like a bad idea.
A good design imo is to have even the startup scripted so that one, if one wishes skips the intro and for example wants to immedeatly start a savegame, can do it properly.