Public Types | Public Member Functions | List of all members
ime::SceneManager Class Referencefinal

Manages game scenes. More...

#include <SceneManager.h>

Public Types

using ScenePtr = std::shared_ptr< Scene >
 

Public Member Functions

void pushScene (ScenePtr scene, bool enterScene=false)
 Add a Scene. More...
 
void popScene ()
 Remove the current active scene. More...
 
std::size_t getSceneCount () const
 Get the current number of scenes. More...
 
void enterTopScene () const
 Enter the scene at the top of the stack. More...
 
void clear ()
 Destroy all scenes. More...
 
bool isEmpty () const
 Check if the scene manager is empty or not. More...
 
void render (Window &window)
 Render the current scene. More...
 
void preUpdate (Time deltaTime)
 Update the scene manager. More...
 
void update (Time deltaTime)
 Update the current scene using a variable time step. More...
 
void fixedUpdate (Time deltaTime)
 Update the current scene using a fixed time step. More...
 
void handleEvent (Event event)
 Handle a system event. More...
 
void forEachScene (const Callback< const ScenePtr & > &callback)
 Execute a callback for every scene in the scene manager. More...
 

Detailed Description

Manages game scenes.

The transition between scenes is managed using the Last In First Out (LIFO) technique (The same way std::stack works). Therefore you cannot transition between scenes at random. The order in which scenes are added to the Engine is important.

For example, if while in the "gameplay" scene, you push a "pause" scene to the game engine, the "gameplay" scene will be paused (onPause called) and the "pause" scene will be entered (onEnter called on the pause scene instance) and the "pause" scene will become the active scene (gets system events, updates and rendered). If you pop the "pause" scene, the engine will destroy it (onExit called on the pause scene instance) and return to the "gameplay" scene (onResume called on the gameplay scene instance). However, if you push (transition to) another scene while in the "pause" scene, the process repeats; the "pause" scene gets paused and the the new scene becomes active)

This class is used internally and it is not meant to be instantiated directly. However, it is available to be used if you want to implement some sort of scene management within a scene (sub scenes within the main scene; maybe instead of having the pause scene as a standalone scene, you make it a sub scene of the gameplay scene. This functionality is not supported in IME. All scenes are standalone and have no knowledge of each other)

Definition at line 66 of file SceneManager.h.

Member Function Documentation

◆ clear()

void ime::SceneManager::clear ( )

Destroy all scenes.

◆ enterTopScene()

void ime::SceneManager::enterTopScene ( ) const

Enter the scene at the top of the stack.

This function will enter the last scene to be added and set it as the active scene. This function has no effect if the scene is already entered or the manager has no scenes to manage

◆ fixedUpdate()

void ime::SceneManager::fixedUpdate ( Time  deltaTime)

Update the current scene using a fixed time step.

Parameters
deltaTimeTime passed since last update

◆ forEachScene()

void ime::SceneManager::forEachScene ( const Callback< const ScenePtr & > &  callback)

Execute a callback for every scene in the scene manager.

Parameters
callbackThe callback to be executed

◆ getSceneCount()

std::size_t ime::SceneManager::getSceneCount ( ) const

Get the current number of scenes.

Returns
The current number of scenes

◆ handleEvent()

void ime::SceneManager::handleEvent ( Event  event)

Handle a system event.

Parameters
eventEvent to be handled

◆ isEmpty()

bool ime::SceneManager::isEmpty ( ) const

Check if the scene manager is empty or not.

Returns
True if the scene manager is empty, otherwise false

◆ popScene()

void ime::SceneManager::popScene ( )

Remove the current active scene.

◆ preUpdate()

void ime::SceneManager::preUpdate ( Time  deltaTime)

Update the scene manager.

Parameters
deltaTimeTime passed since last update

This function is called by the engine before event/input handling and scene update takes place

◆ pushScene()

void ime::SceneManager::pushScene ( ScenePtr  scene,
bool  enterScene = false 
)

Add a Scene.

Parameters
sceneScene to be added
enterSceneTrue to immediately enter the scene or false to delay entry

The scene maybe be added and entered immediately or delayed. By default the scene is delayed. This option allows multiple scenes to be pushed at once to the game engine

for example you may want to add multiple scenes in one frame but only enter the last one first as follows:

sceneManager.pushScene(MainMenu);
sceneManager.pushScene(Loading);
sceneManager.pushScene(Splash, true);
// Because of LIFO, the scenes will be arranged in reverse order:
// Splash -> Loading -> MainMenu.
//
// Because the enter flag is set to true when pushing the "Splash"
// scene, the scene will be added and entered immediately. Let's
// assume that the "Splash" and the "Loading" scenes pop themselves
// from the game engine when ready. The game flow will be as follows:
//
// The "Splash" scene shows for some time then pops/removes itself
// from the game engine, this triggers the engine to check for the
// next available scene. It finds the "Loading" scene and enters it.
// After the "Loading" scene has finished (say, loading some resources),
// it pops/removes itself. This again triggers the engine to check
// for the next available scene, it finds the "MainMenu" scene and
// enters it. From here the user may transition to the "Gameplay"
// or "Quit" scene
Note
A scene can only belong to one scene manager and it cannot be added more than once to the scene manager that owns it
Warning
The pointer must not be null
See also
enterTopScene

◆ render()

void ime::SceneManager::render ( Window window)

Render the current scene.

Parameters
windowThe window to render the scene on

◆ update()

void ime::SceneManager::update ( Time  deltaTime)

Update the current scene using a variable time step.

Parameters
deltaTimeTime passed since last update

The documentation for this class was generated from the following file: