11#include <unordered_map>
16namespace Imago::Engine
47 static std::unique_ptr<Scene> create_scene(
const SceneContext& gameCtx);
60 std::unordered_map<std::string, SceneFactoryFn> _factories;
61 std::unordered_map<std::string, std::unique_ptr<Scene>> _scenes;
62 Scene* _active =
nullptr;
63 std::string _activeName;
67 bool _switchPending =
false;
68 std::string _pendingName;
69 bool _pendingPersist =
false;
124 template <
typename T>
125 std::unique_ptr<Scene> SceneManager::create_scene(
const SceneContext& gameCtx)
127 return std::make_unique<T>(gameCtx);
130 template <
typename T>
134 static_assert(std::is_base_of_v<Scene, T>,
"[SceneManager] You cannot register an object that does not extend Scene!");
137 static_assert(!std::is_abstract_v<T>,
"[SceneManager] You cannot register a Scene that has not overridden on_load()!");
140 static_assert(std::is_constructible_v<T, const SceneContext&>,
"[SceneManager] The Scene you are trying to register is not constructible. Use 'using Scene::Scene'");
143 add_factory(name, &create_scene<T>);
Defines the Scene, the abstract world that owns a Nexus, Broadcaster, and SystemScheduler.
~SceneManager()
Unloads the active scene then destroys every live scene in _scenes.
Definition SceneManager.cpp:14
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 ...
Definition SceneManager.hpp:131
SceneManager(const SceneContext &gameCtx)
Construct a new SceneManager object, instantiating gameCtx so it can be copied into every Scene it bu...
Definition SceneManager.cpp:10
void update(float dt)
Updates the active scene. Does nothing if there is no active Scene.
Definition SceneManager.cpp:26
std::unique_ptr< Scene >(*)(const SceneContext &) SceneFactoryFn
A function pointer to a function that builds one specific Scene type. One is instantiated per registe...
Definition SceneManager.hpp:36
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....
Definition SceneManager.cpp:50
bool apply_pending_switch()
Actually switch the pending Scene. Called by Game at the end of each frame.
Definition SceneManager.cpp:70
Abstract Base Class for every Scene. Users inherit from this class and override on_load() and optiona...
Definition Scene.hpp:24
Gives systems access to the persistent engine objects they could need.
Definition SceneContext.hpp:30