Skip to content
opatut edited this page Jul 31, 2011 · 1 revision

The Game

The game is responsible for the main game loop. It cares about timesteps, framerates, initialization and deinitialization of the Root and everything else that is required to simulate and render frame per frame. The usage is very simple:

int main(int argc, char** argv) {
    dt::Game game;
    game.Run(new Main(), argc, argv);
    return 0;
}

The State

A State class is used for every game state, e.g. the menu, a character selection screen, the actual level(s), etc. For each State, the State class is inherited, and the OnInitialize() and OnDeinitialize() methods can be overridden to create the custom scenes, nodes and components.

Every State can have multiple scenes (see State::AddScene()).

The states are managed by the StateManager, which holds them on a stack. When a new state is added, the current frame is finished, then the old state is deinitialized and the new state is initialized. When the state is being popped again (via StateManager::Pop), the state is deinitialized and destructed, and the state below is being initialized again. When the last state is removed, the Game loop ends.

The starting state is passed into the Game::Run method, which is then pushed onto the StateManager's stack just before the loop starts (but after the Root initialization).

Clone this wiki locally