guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
scene.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 <memory>
26#include <stdexcept>
27#include <typeindex>
28
29#include <utility/logging/loggable.hpp>
30#include <utility/logging/default_logger.hpp>
31
32#include <utility/ressource_provider.hpp>
33
34#include <utility/graphic/view.hpp>
35
36#include "guillaume/ecs/component_registry.hpp"
37#include "guillaume/ecs/entity_registry.hpp"
38#include "guillaume/ecs/entity_builder_manager_filler.hpp"
39#include "guillaume/ecs/entity_registry_container.hpp"
40
41#include "guillaume/local_storage.hpp"
42#include "guillaume/session_storage.hpp"
43
44namespace guillaume
45{
113 class Scene:
115 public utility::logging::Loggable<Scene,
116 utility::logging::DefaultLogger>
117 {
118 public:
134 void placeEntitiesInFrontOfView(const utility::graphic::ViewF &view);
135
147 template<typename NextScene> void goToScene(void);
161 Scene(std::shared_ptr<utility::RessourceProvider> ressourceProvider,
162 LocalStorage &localStorage, SessionStorage &sessionStorage);
163
167 virtual ~Scene(void);
168
176
183
189 bool wantsToSwitch(void) const noexcept;
190
196 std::type_index getNextSceneType(void) const noexcept;
197
203 void clearNextScene(void) noexcept;
204
212 virtual void onEnter(void);
213
222 virtual void onExit(void);
223
224 protected:
230 std::shared_ptr<utility::RessourceProvider> getRessourceProvider(void);
231
245
260 void addRootEntity(const std::string &name,
261 std::shared_ptr<ecs::Entity> entity);
262
271 template<ecs::InheritFromEntity EntityType>
272 std::shared_ptr<EntityType> getRootEntity(const std::string &name);
273
274 private:
275 std::shared_ptr<utility::RessourceProvider>
276 _ressourceProvider;
278 &_localStorage;
280 &_sessionStorage;
282 _componentRegistry;
283 std::unique_ptr<ecs::EntityBuilderManager>
284 _entityBuilderManager;
285 std::type_index _nextSceneType;
287 std::map<std::string, std::shared_ptr<ecs::Entity>>
288 _rootEntities;
289 };
290
295 template<typename Type>
296 concept InheritFromScene = std::is_base_of_v<Scene, Type>;
297
305 template<typename... Types> inline constexpr bool areDistinct = true;
306
313 template<typename First, typename... Rest>
314 inline constexpr bool areDistinct<First, Rest...> =
315 (!std::is_same_v<First, Rest> && ...) && areDistinct<Rest...>;
316
324 template<typename... Types>
325 concept AllDistinct = areDistinct<Types...>;
326
327} // namespace guillaume
328
329// Include the goToScene template implementation
330#include "guillaume/scene.tpp"
Key-value storage kept in a file: the place for data that must be found again at the next start (pref...
ecs::ComponentRegistry & getComponentRegistry(void)
Get the registry holding the components of every entity of this scene.
std::shared_ptr< EntityType > getRootEntity(const std::string &name)
Find an entity by the name given to addRootEntity().
bool wantsToSwitch(void) const noexcept
Tell whether goToScene() was called and the switch has not happened yet.
virtual void onExit(void)
Called each time the scene stops being the active one, before onEnter() of the next scene.
std::type_index getNextSceneType(void) const noexcept
Get the scene type asked for by goToScene().
ecs::EntityBuilderManager & getBuilderManager(void)
Get the builders of this scene, one per widget of the library.
void placeEntitiesInFrontOfView(const utility::graphic::ViewF &view)
Line up the scene's entities in front of a view.
void goToScene(void)
Ask to leave this scene for another one.
ecs::EntityRegistry & getEntityRegistry(void)
Get the scene as the registry that owns its entities.
std::shared_ptr< utility::RessourceProvider > getRessourceProvider(void)
Get the resource provider given to the constructor.
virtual ~Scene(void)
Destroy the scene with its entities and components.
void clearNextScene(void) noexcept
Forget the pending switch request, if any.
Scene(std::shared_ptr< utility::RessourceProvider > ressourceProvider, LocalStorage &localStorage, SessionStorage &sessionStorage)
Create an empty scene with its registries and its builders.
void addRootEntity(const std::string &name, std::shared_ptr< ecs::Entity > entity)
Give an entity a name, to find it again with getRootEntity().
virtual void onEnter(void)
Called each time the scene becomes the active one: at start-up for the default scene,...
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...
Holds one builder per builder type and hands them out by type.
An EntityRegistry that is not itself an entity: the top of an ownership tree.
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.
constexpr bool areDistinct
True when no type appears twice in a parameter pack.
Definition scene.hpp:305