5#include "NonCopyable.hpp"
10#include <unordered_map>
22class Scene :
public NonCopyable<>
26 virtual ~Scene() =
default;
35 virtual void Update(
const float deltaT) = 0;
42 virtual void Draw()
const;
89 template <
typename SceneT,
typename... Args>
90 requires std::is_base_of_v<Scene, SceneT>
93 auto ptr = std::make_unique<SceneT>(std::forward<Args>(args)...);
95 std::unique_lock lock(m_mutex);
97 m_scenes.emplace(
typeid(SceneT), std::move(ptr));
107 template <
typename SceneT>
108 requires std::is_base_of_v<Scene, SceneT>
111 std::unique_lock lock(m_mutex);
113 auto it = m_scenes.find(
typeid(SceneT));
114 if (it != m_scenes.end())
116 Assert(it->second.get() != m_currentScene,
"Cannot delete the current scene");
131 template <
typename SceneT>
132 requires std::is_base_of_v<Scene, SceneT>
135 std::unique_lock lock(m_mutex);
137 auto it = m_scenes.find(
typeid(SceneT));
138 Assert(it != m_scenes.end(),
"Scene ", Demangle<SceneT>().c_str(),
" does not exist");
139 Assert(it->second.get() != m_currentScene,
"Cannot change to the current scene");
141 m_nextSceneType =
typeid(SceneT);
142 m_changeScene =
true;
159 void Update(
const float deltaT);
171 void CheckForChange();
173 Scene* m_currentScene =
nullptr;
175 bool m_changeScene =
false;
176 std::type_index m_nextSceneType =
typeid(void);
180 std::unordered_map<std::type_index, std::unique_ptr<Scene>> m_scenes;
Core engine.
Definition Engine.hpp:90
Manages scenes and the execution of the current active scene.
Definition SceneManager.hpp:71
void ClearScenes()
Removes all scenes and clears the active scene pointer.
Definition SceneManager.cpp:35
void RemoveScene()
Removes a scene from the manager.
Definition SceneManager.hpp:109
void ChangeScene()
Queues a scene transition to be applied at the end of the current frame.
Definition SceneManager.hpp:133
void AddScene(Args &&... args)
Adds a scene to the manager.
Definition SceneManager.hpp:91
Base class for all scenes.
Definition SceneManager.hpp:23
virtual void Draw() const
Renders the scene.
Definition SceneManager.cpp:5
virtual void OnExit()
Called by the engine just before this scene is replaced by another.
Definition SceneManager.cpp:13
virtual void OnEnter()
Called by the engine when this scene becomes the active scene.
Definition SceneManager.cpp:9
virtual void Update(const float deltaT)=0
Updates the scene.