ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Imago::Engine::SceneManager Class Reference

The manager is the only object that creates, switches, and updates Scenes. More...

#include <Imago/Engine/SceneManager.hpp>

Public Types

using SceneFactoryFn = std::unique_ptr<Scene>(*)(const SceneContext&)
 A function pointer to a function that builds one specific Scene type. One is instantiated per registered type.

Public Member Functions

 SceneManager (const SceneContext &gameCtx)
 Construct a new SceneManager object, instantiating gameCtx so it can be copied into every Scene it builds.
 ~SceneManager ()
 Unloads the active scene then destroys every live scene in _scenes.
 SceneManager (const SceneManager &)=delete
SceneManager & operator= (const SceneManager &)=delete
 SceneManager (SceneManager &&)=delete
SceneManager & operator= (SceneManager &&)=delete
template<typename T>
void register_scene (const std::string &name)
 Registers a Scene type under a name. The scene is not build on registration but instead a factory to a method that builds the Scene is stored and then called when that Scene is switched to for the first time.
void request_switch (const std::string &name, bool persist)
 Records a request to switch scenes. The switch is not actually applied until the end of the frame. If several switch requests occur during the same frame, the last one wins.
bool apply_pending_switch ()
 Actually switch the pending Scene. Called by Game at the end of each frame.
void update (float dt)
 Updates the active scene. Does nothing if there is no active Scene.

Detailed Description

The manager is the only object that creates, switches, and updates Scenes.

Scenes are registered by name with register_scene and built on first use. Only one Scene can be active at a time. Switching is defferred to the end of the current frame.

Constructor & Destructor Documentation

◆ SceneManager()

Imago::Engine::SceneManager::SceneManager ( const SceneContext & gameCtx)
explicit

Construct a new SceneManager object, instantiating gameCtx so it can be copied into every Scene it builds.

Parameters
gameCtxSceneContext filled with the global engine objecst that the Game owns

Member Function Documentation

◆ apply_pending_switch()

bool Imago::Engine::SceneManager::apply_pending_switch ( )

Actually switch the pending Scene. Called by Game at the end of each frame.

Returns
true if there was a pending switch that was applied

◆ register_scene()

template<typename T>
void Imago::Engine::SceneManager::register_scene ( const std::string & name)

Registers a Scene type under a name. The scene is not build on registration but instead a factory to a method that builds the Scene is stored and then called when that Scene is switched to for the first time.

Template Parameters
TType of Scene to register.
Parameters
nameName of the Scene.

◆ request_switch()

void Imago::Engine::SceneManager::request_switch ( const std::string & name,
bool persist )

Records a request to switch scenes. The switch is not actually applied until the end of the frame. If several switch requests occur during the same frame, the last one wins.

Parameters
nameThe name of the registered scene to switch to.
persistWhether or not the scene should be suspended (true) or completely destroyed (false).

◆ update()

void Imago::Engine::SceneManager::update ( float dt)

Updates the active scene. Does nothing if there is no active Scene.

Parameters
dtReal time since the last frame in seconds.

The documentation for this class was generated from the following files:
  • engine/include/Imago/Engine/SceneManager.hpp
  • engine/src/Engine/SceneManager.cpp