guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::SceneManager< DefaultSceneType, SceneTypes > Class Template Reference

Owns the scenes of an application, knows which one is active, and performs the switches between them. More...

#include <headers/guillaume/scene_manager.hpp>

Inheritance diagram for guillaume::SceneManager< DefaultSceneType, SceneTypes >:
Collaboration diagram for guillaume::SceneManager< DefaultSceneType, SceneTypes >:

Public Member Functions

 SceneManager (std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
 Create one instance of every scene type and make DefaultSceneType the active one.
 ~SceneManager (void)
 Destroy the manager and every scene. onExit() is not called on the active scene.
Scene * getActiveScene (void)
 Get the active scene.
bool hasScenes (void) const noexcept
 Tell whether the manager holds at least one scene.
bool hasActiveScene (void) const noexcept
 Tell whether an active scene is selected.
void enterActiveScene (void)
 Enter the active scene: call its onEnter(), then place its entities in front of the engine's current view (Scene::placeEntitiesInFrontOfView).
void processSceneTransition (void)
 Carry out the switch requested by the active scene with Scene::goToScene, if any.
template<InheritFromScene SceneType>
void switchToScene (void)
 Switch to another scene immediately, without waiting for the end of the frame.
ecs::EntityRegistry & getActiveEntityRegistry (void)
 Get the entity registry of the active scene.
ecs::ComponentRegistry & getActiveComponentRegistry (void)
 Get the component registry of the active scene.
std::vector< std::type_index > getRegisteredSceneTypes (void) const
 List the scene types this manager holds.

Protected Member Functions

template<InheritFromScene SceneType>
void addScene (void)
 Create the instance of one scene type and keep it.

Detailed Description

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
requires AllDistinct<DefaultSceneType, SceneTypes...>
class guillaume::SceneManager< DefaultSceneType, SceneTypes >

Owns the scenes of an application, knows which one is active, and performs the switches between them.

Application creates one manager. The manager builds one instance of every scene type at construction and keeps them all until it is destroyed: switching scenes changes which one is active, it does not create or destroy scenes. Each frame, Application asks it for the registries of the active scene, runs the systems on them, then calls processSceneTransition() to honor a Scene::goToScene request.

Every switch goes through the same steps: onExit() on the active scene, then onEnter() on the new one, then Scene::placeEntitiesInFrontOfView with the engine's view.

The manager also owns the LocalStorage and the SessionStorage handed to every scene. The LocalStorage uses its default path, so constructing a manager opens (and creates if needed) the file given by LocalStorage::defaultStoragePath.

Note
Application code normally switches scenes with Scene::goToScene and does not use this class directly.
Template Parameters
DefaultSceneTypeThe scene activated when the application starts.
SceneTypesThe other scenes of the application. Every scene type must inherit from Scene and appear only once.
See also
Scene
Application

Definition at line 81 of file scene_manager.hpp.

Constructor & Destructor Documentation

◆ SceneManager()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
guillaume::SceneManager< DefaultSceneType, SceneTypes >::SceneManager ( std::shared_ptr< utility::RessourceProvider > ressourceProvider,
utility::Engine & engine )

Create one instance of every scene type and make DefaultSceneType the active one.

No scene is entered yet: call enterActiveScene() once the manager is built.

Parameters
ressourceProviderThe resource provider handed to every scene.
engineThe engine asked for the current view each time a scene is entered. It must outlive the manager.
Exceptions
std::runtime_errorWhen the local storage cannot be opened at all (see LocalStorage).

Member Function Documentation

◆ addScene()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
template<InheritFromScene SceneType>
void guillaume::SceneManager< DefaultSceneType, SceneTypes >::addScene ( void )
protected

Create the instance of one scene type and keep it.

The scene receives the resource provider and the two storages. A scene of the same type already held is replaced.

Template Parameters
SceneTypeThe scene type to instantiate. It must be constructible from the arguments of the Scene constructor.

◆ enterActiveScene()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
void guillaume::SceneManager< DefaultSceneType, SceneTypes >::enterActiveScene ( void )

Enter the active scene: call its onEnter(), then place its entities in front of the engine's current view (Scene::placeEntitiesInFrontOfView).

onEnter() comes first because that is where the scene builds the entities to place. Application calls this once at start-up for the default scene; later entries happen through the switches.

Exceptions
std::runtime_errorWhen the manager holds no scene.

◆ getActiveComponentRegistry()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
ecs::ComponentRegistry & guillaume::SceneManager< DefaultSceneType, SceneTypes >::getActiveComponentRegistry ( void )

Get the component registry of the active scene.

Returns
Reference to the registry of the active scene. It designates another scene's registry after a switch.
Exceptions
std::runtime_errorWhen the manager holds no scene.

◆ getActiveEntityRegistry()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
ecs::EntityRegistry & guillaume::SceneManager< DefaultSceneType, SceneTypes >::getActiveEntityRegistry ( void )

Get the entity registry of the active scene.

Returns
Reference to the active scene, seen as the registry that owns its entities. It designates another scene after a switch.
Exceptions
std::runtime_errorWhen the manager holds no scene.

◆ getActiveScene()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
Scene * guillaume::SceneManager< DefaultSceneType, SceneTypes >::getActiveScene ( void )

Get the active scene.

Returns
Pointer to the active scene, never nullptr. It stays valid as long as the manager.
Exceptions
std::runtime_errorWhen the manager holds no scene.

◆ getRegisteredSceneTypes()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
std::vector< std::type_index > guillaume::SceneManager< DefaultSceneType, SceneTypes >::getRegisteredSceneTypes ( void ) const

List the scene types this manager holds.

Returns
One std::type_index per scene, in the ordering of std::type_index (not the order of the template arguments).

◆ hasActiveScene()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
bool guillaume::SceneManager< DefaultSceneType, SceneTypes >::hasActiveScene ( void ) const
noexcept

Tell whether an active scene is selected.

Returns
True when scenes exist and one of them is the active one, which is always the case after construction.

◆ hasScenes()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
bool guillaume::SceneManager< DefaultSceneType, SceneTypes >::hasScenes ( void ) const
noexcept

Tell whether the manager holds at least one scene.

Returns
True when one or more scenes exist, which is always the case after construction.

◆ processSceneTransition()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
void guillaume::SceneManager< DefaultSceneType, SceneTypes >::processSceneTransition ( void )

Carry out the switch requested by the active scene with Scene::goToScene, if any.

Does nothing when no switch is pending. Otherwise the request is cleared, onExit() is called on the active scene, the requested scene becomes active and is entered (enterActiveScene()). Application calls it once per frame, after the systems ran.

Exceptions
std::runtime_errorWhen the requested scene type is not one of this manager's scenes. The request is dropped and the active scene stays active, without onExit() being called.

◆ switchToScene()

template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
template<InheritFromScene SceneType>
void guillaume::SceneManager< DefaultSceneType, SceneTypes >::switchToScene ( void )

Switch to another scene immediately, without waiting for the end of the frame.

Same steps as a switch requested by the scene itself: onExit() on the active scene, then the new scene becomes active and is entered. Switching to the scene that is already active exits and re-enters it.

Template Parameters
SceneTypeThe scene type to switch to.
Exceptions
std::runtime_errorWhen SceneType is not one of this manager's scenes; the active scene is left as it was.

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