Brunot
Loading...
Searching...
No Matches
SceneManager.h
Go to the documentation of this file.
1// File: SceneManager.h
2// Description: Manages loading and unloading scenes, is an ancestor to every entity
3// Author(s): Aidan Hartman (aidan.hartman@digipen.edu) Base Implementation
4// Marcelo Escamilla (marcelo.escamilla@digipen.edu) ImGui Integration
5// 2025 / 10 / 20
6// (C) Digipen 2025
7// SceneManager.h
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16
17#include "Framework/System.h"
18
19struct Message;
20class Scene;
21class Node;
22
23
25{
26 enum state : char
27 {
28 T = 'T',
29 F = 'F',
31 };
32
36
37 friend auto to_json(json& j, const SceneState& p) -> void
38 {
39 j = json{
40 {"renders", p.renders},
41 {"updates", p.updates},
42 {"messages", p.messages}
43 };
44
45 }
46
47 friend auto from_json(const json& j, SceneState& p) -> void
48 {
49 j.at("renders").get_to(p.renders);
50 j.at("updates").get_to(p.updates);
51 j.at("messages").get_to(p.messages);
52 }
53};
54
55namespace sys
56{
57class SceneManager : public System
58{
59public:
60 friend Scene;
61
62#pragma region static_functions
63
67 static auto getEnum() -> Type
68 {
69 return Type::SceneManager;
70 }
71
76 static auto LoadScene(std::unique_ptr<Node> scene) -> void;
77
82 static auto LoadScene(const std::string& name) -> void;
83
84#pragma endregion
85
87 ~SceneManager() override = default;
88
90 SceneManager(const SceneManager& other);
92 SceneManager(SceneManager&& other) noexcept = default;
94 auto operator=(const SceneManager& other) -> SceneManager&;
96 auto operator=(SceneManager&& other) noexcept -> SceneManager& = default;
97
98#pragma region overridden_functions
99
100 auto clone() const -> std::unique_ptr<GameObject> override
101 {
102 return std::make_unique<SceneManager>(*this);
103 }
104
105protected:
106 auto systemShowMenu() -> void override;
107
108public:
109 auto onUpdate(float dt) -> void override;
110
111 auto endWindow() -> void override
112 {
113 }; // for debug ImGUI
114 auto onRender() -> void override;
115 auto load(const Stream& stream) -> void override;
116 auto save(Stream& stream) const -> void override;
117 [[nodiscard("adding child may fail")]] auto addChild(std::unique_ptr<GameObject> newChild) -> bool override;
118
119
120#pragma endregion
121
122#pragma region SceneManager_functions
123
124
129 auto loadScene(std::unique_ptr<Node> scene) -> void;
130
135 auto loadScene(const std::string& name) -> void;
136
141 auto getCurrentScene() const -> GameObject*;
142
143 auto registerScene(Scene& scene) -> void;
144 auto deregisterScene(Scene& scene) -> void;
145
146 auto saveScene(Stream& stream) const -> void;
147
148#pragma endregion
149
150#pragma region messaging_functions
151
152 auto linkMessages() -> void;
153 auto receiveResetKeyPressed(const Message* message) -> Message;
154
155#pragma endregion
156
157private:
158#pragma region member_variables
159
160 std::vector<Scene*> scenes;
161
162 bool shouldLoadScene = false;
163 std::unique_ptr<Node> sceneToLoad;
164
165
166#pragma endregion
167
168#pragma region helper_functions
169
171 auto pushCorrectState(const Scene& sceneToKeep, SceneState newState, SceneState keepSceneState,
172 std::vector<Scene*>::iterator::value_type scene) -> void;
174 auto toAllSceneChildren(Scene* parent, std::function<void(Scene*)> func) -> void;
175 auto pushStateToOtherScenes(const Scene& sceneToKeep, SceneState othersState, SceneState keepSceneState) -> void;
176
177 auto popAllScenes(const Scene& sceneToKeep) -> void;
178
180 auto removeOldScene(GameObject* oldScene) const -> void;
181
182#pragma endregion
183
184#pragma region static_variables
185
186#pragma endregion
187
188
189};
190}
sys::Json Stream
Definition AudioObject.h:20
nlohmann::json json
Definition Json.cpp:19
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Manages the heirarchical structure between Systems and Entities.
Definition Node.h:41
Definition Scene.h:24
Type
Definition System.h:20
@ SceneManager
Definition System.h:34
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition SceneManager.h:100
auto saveScene(Stream &stream) const -> void
Definition SceneManager.cpp:228
std::unique_ptr< Node > sceneToLoad
Definition SceneManager.h:163
friend Scene
Definition SceneManager.h:60
auto linkMessages() -> void
Definition SceneManager.cpp:238
bool shouldLoadScene
Definition SceneManager.h:162
auto toAllSceneChildren(Scene *parent, std::function< void(Scene *)> func) -> void
apply a function to all children of a specific scene
Definition SceneManager.cpp:271
auto operator=(SceneManager &&other) noexcept -> SceneManager &=default
default move assingment operator
static auto LoadScene(std::unique_ptr< Node > scene) -> void
loads a scene by taking the scene directly
Definition SceneManager.cpp:182
auto pushCorrectState(const Scene &sceneToKeep, SceneState newState, SceneState keepSceneState, std::vector< Scene * >::iterator::value_type scene) -> void
Helper function for pushStateToOtherScenes.
Definition SceneManager.cpp:258
auto pushStateToOtherScenes(const Scene &sceneToKeep, SceneState othersState, SceneState keepSceneState) -> void
Definition SceneManager.cpp:280
auto registerScene(Scene &scene) -> void
Definition SceneManager.cpp:217
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition SceneManager.cpp:64
std::vector< Scene * > scenes
Definition SceneManager.h:160
SceneManager()
Definition SceneManager.cpp:39
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition SceneManager.cpp:112
auto loadScene(std::unique_ptr< Node > scene) -> void
loads a scene by taking the scene directly
Definition SceneManager.cpp:193
auto onUpdate(float dt) -> void override
called once every frame.
Definition SceneManager.cpp:95
auto addChild(std::unique_ptr< GameObject > newChild) -> bool override
loads a scene
Definition SceneManager.cpp:128
auto popAllScenes(const Scene &sceneToKeep) -> void
Definition SceneManager.cpp:294
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition SceneManager.h:111
auto operator=(const SceneManager &other) -> SceneManager &
non-default copy assignment operator because we have a unique pointer, but b/c this is a singleton,...
Definition SceneManager.cpp:50
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition SceneManager.cpp:117
static auto getEnum() -> Type
function required by all systems
Definition SceneManager.h:67
auto deregisterScene(Scene &scene) -> void
Definition SceneManager.cpp:222
auto onRender() -> void override
called every frame after update has been called for every object.
Definition SceneManager.cpp:108
auto getCurrentScene() const -> GameObject *
Definition SceneManager.cpp:205
auto removeOldScene(GameObject *oldScene) const -> void
remove the old root node, as well as call onSceneExit()
Definition SceneManager.cpp:305
SceneManager(SceneManager &&other) noexcept=default
default move ctor
~SceneManager() override=default
auto receiveResetKeyPressed(const Message *message) -> Message
Definition SceneManager.cpp:247
the type of elements in a basic_json container
Definition GameObject.h:37
Definition Message.h:35
Definition SceneManager.h:25
state updates
Definition SceneManager.h:34
state messages
Definition SceneManager.h:35
friend auto from_json(const json &j, SceneState &p) -> void
Definition SceneManager.h:47
state
Definition SceneManager.h:27
@ F
Definition SceneManager.h:29
@ T
Definition SceneManager.h:28
@ noEffect
Definition SceneManager.h:30
state renders
Definition SceneManager.h:33
friend auto to_json(json &j, const SceneState &p) -> void
Definition SceneManager.h:37