guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
scene_manager.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <map>
26#include <memory>
27#include <stdexcept>
28#include <string>
29#include <typeindex>
30
31#include <utility/logging/loggable.hpp>
32#include <utility/logging/default_logger.hpp>
33
34#include <utility/ressource_provider.hpp>
35
36#include <utility/engine.hpp>
37
38#include "guillaume/scene.hpp"
39
40#include "guillaume/ecs/component_registry.hpp"
41#include "guillaume/ecs/entity_registry.hpp"
42#include "guillaume/ecs/system_registry.hpp"
43
44#include "guillaume/local_storage.hpp"
45#include "guillaume/session_storage.hpp"
46
47namespace guillaume
48{
49
79 template<InheritFromScene DefaultSceneType, InheritFromScene... SceneTypes>
80 requires AllDistinct<DefaultSceneType, SceneTypes...>
82 public utility::logging::Loggable<
83 SceneManager<DefaultSceneType, SceneTypes...>,
84 utility::logging::DefaultLogger>
85 {
86 public:
101 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
102 utility::Engine &engine);
103
109
117
123 bool hasScenes(void) const noexcept;
124
130 bool hasActiveScene(void) const noexcept;
131
143
157
170 template<InheritFromScene SceneType> void switchToScene(void);
171
179
187
193 std::vector<std::type_index> getRegisteredSceneTypes(void) const;
194
195 protected:
204 template<InheritFromScene SceneType> void addScene(void);
205
206 private:
207 std::shared_ptr<utility::RessourceProvider>
208 _ressourceProvider;
209 std::map<std::type_index, std::unique_ptr<Scene>>
210 _scenes;
212 std::type_index _activeSceneType;
214 _localStorage;
216 _sessionStorage;
217 utility::Engine &_engine;
218
228 void transitionTo(std::type_index nextType);
229 };
230} // namespace guillaume
231
232// Include the SceneManager template implementation
233#include "guillaume/scene_manager.tpp"
Key-value storage kept in a file: the place for data that must be found again at the next start (pref...
void enterActiveScene(void)
Enter the active scene: call its onEnter(), then place its entities in front of the engine's current ...
void addScene(void)
Create the instance of one scene type and keep it.
bool hasActiveScene(void) const noexcept
Tell whether an active scene is selected.
SceneManager(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create one instance of every scene type and make DefaultSceneType the active one.
std::vector< std::type_index > getRegisteredSceneTypes(void) const
List the scene types this manager holds.
~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.
ecs::ComponentRegistry & getActiveComponentRegistry(void)
Get the component registry of the active scene.
void processSceneTransition(void)
Carry out the switch requested by the active scene with Scene::goToScene, if any.
ecs::EntityRegistry & getActiveEntityRegistry(void)
Get the entity registry of the active scene.
void switchToScene(void)
Switch to another scene immediately, without waiting for the end of the frame.
One screen of the application: it owns the entities shown and the components that hold their state.
Definition scene.hpp:117
Key-value storage that lasts as long as the process: the place for data shared between scenes that ne...
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
Constrains a parameter pack to types that are all different.
Definition scene.hpp:325
Constrains a template parameter to a type derived from Scene.
Definition scene.hpp:296
A C++20 UI framework for desktop and XR, built as an entity-component-system.