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... | |
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.
void ime::SceneManager::clear | ( | ) |
Destroy all scenes.
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
void ime::SceneManager::fixedUpdate | ( | Time | deltaTime | ) |
Update the current scene using a fixed time step.
deltaTime | Time passed since last update |
void ime::SceneManager::forEachScene | ( | const Callback< const ScenePtr & > & | callback | ) |
Execute a callback for every scene in the scene manager.
callback | The callback to be executed |
std::size_t ime::SceneManager::getSceneCount | ( | ) | const |
Get the current number of scenes.
void ime::SceneManager::handleEvent | ( | Event | event | ) |
Handle a system event.
event | Event to be handled |
bool ime::SceneManager::isEmpty | ( | ) | const |
Check if the scene manager is empty or not.
void ime::SceneManager::popScene | ( | ) |
Remove the current active scene.
void ime::SceneManager::preUpdate | ( | Time | deltaTime | ) |
Update the scene manager.
deltaTime | Time passed since last update |
This function is called by the engine before event/input handling and scene update takes place
void ime::SceneManager::pushScene | ( | ScenePtr | scene, |
bool | enterScene = false |
||
) |
Add a Scene.
scene | Scene to be added |
enterScene | True 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:
void ime::SceneManager::render | ( | Window & | window | ) |
Render the current scene.
window | The window to render the scene on |
void ime::SceneManager::update | ( | Time | deltaTime | ) |
Update the current scene using a variable time step.
deltaTime | Time passed since last update |