Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
SceneManagement.hpp
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <memory>
4#include <atomic>
5#include <functional>
6#include <vector>
7#include "core/EngineAPI.hpp"
8
9class SceneManager;
10
19
25 int id = -1;
26 std::string name;
27 std::string path;
28 bool isLoaded = false;
29};
30
36 std::atomic<float> progress{0.0f};
37 std::atomic<bool> isDone{false};
39
41 std::function<void(const SceneInfo&)> onComplete;
42};
43
77public:
78
79 // -------------------------------------------------------------------------
80 // Load — deferred to start of next frame, safe to call from update()
81 // -------------------------------------------------------------------------
82
89 static void loadScene(const std::string& nameOrPath,
91 bool discardPendingAsync = true);
92
99 static void loadScene(int sceneId,
101 bool discardPendingAsync = true);
102
103 // -------------------------------------------------------------------------
104 // Async Load
105 // -------------------------------------------------------------------------
106
114 static std::shared_ptr<AsyncOperation> loadSceneAsync(const std::string& nameOrPath,
116 bool discardPendingAsync = true);
117
125 static std::shared_ptr<AsyncOperation> loadSceneAsync(int sceneId,
127 bool discardPendingAsync = true);
128
129 // -------------------------------------------------------------------------
130 // Unload
131 // -------------------------------------------------------------------------
132
137 static void unloadScene(const std::string& nameOrPath);
138
143 static void unloadScene(int sceneId);
144
145 // -------------------------------------------------------------------------
146 // Events
147 // -------------------------------------------------------------------------
148
153 static void onSceneLoaded(std::function<void(const SceneInfo&)> callback);
154
159 static void onSceneUnloaded(std::function<void(const SceneInfo&)> callback);
160
161 // -------------------------------------------------------------------------
162 // Query
163 // -------------------------------------------------------------------------
164
168 static std::vector<SceneInfo> getLoadedScenes();
169
173 static SceneInfo getSceneInfo(int sceneId);
174
178 static SceneInfo getSceneInfo(const std::string& nameOrPath);
179
180 // -------------------------------------------------------------------------
181 // Internal engine API
182 // -------------------------------------------------------------------------
183
185 static void setSceneManager(SceneManager* manager);
186
187private:
189};
#define ENGINE_API
Definition EngineAPI.hpp:10
LoadSceneMode
Determines whether loading a scene replaces or adds to the current set.
Definition SceneManagement.hpp:15
@ Additive
Load the new scene alongside existing ones.
Definition SceneManagement.hpp:17
@ Single
Unload all current scenes, then load the new one.
Definition SceneManagement.hpp:16
Static Unity-style API for scene loading, unloading, and event subscriptions.
Definition SceneManagement.hpp:76
static std::shared_ptr< AsyncOperation > loadSceneAsync(const std::string &nameOrPath, LoadSceneMode mode=LoadSceneMode::Single, bool discardPendingAsync=true)
Load a scene asynchronously by name or path.
Definition SceneManagement.cpp:69
static SceneInfo getSceneInfo(int sceneId)
Get scene info by integer ID.
Definition SceneManagement.cpp:136
static void unloadScene(const std::string &nameOrPath)
Unload a scene by its name or path.
Definition SceneManagement.cpp:103
static void onSceneUnloaded(std::function< void(const SceneInfo &)> callback)
Subscribe a callback to be fired whenever any scene is unloaded.
Definition SceneManagement.cpp:122
static void loadScene(const std::string &nameOrPath, LoadSceneMode mode=LoadSceneMode::Single, bool discardPendingAsync=true)
Load a scene by name or path.
Definition SceneManagement.cpp:41
static SceneManager * s_sceneManager
Definition SceneManagement.hpp:188
static std::vector< SceneInfo > getLoadedScenes()
Returns all currently loaded scenes.
Definition SceneManagement.cpp:131
static void onSceneLoaded(std::function< void(const SceneInfo &)> callback)
Subscribe a callback to be fired whenever any scene finishes loading.
Definition SceneManagement.cpp:117
static void setSceneManager(SceneManager *manager)
Called once at engine boot to wire the SceneManager.
Definition SceneManagement.cpp:21
Manages a set of simultaneously loaded Scenes. Supports Single and Additive loading,...
Definition SceneManager.hpp:54
Handle returned from loadSceneAsync(). Tracks async load progress.
Definition SceneManagement.hpp:35
std::atomic< float > progress
0.0 (start) to 1.0 (complete).
Definition SceneManagement.hpp:36
std::atomic< bool > isDone
True when the scene is fully loaded.
Definition SceneManagement.hpp:37
SceneInfo sceneInfo
Info about the scene being loaded.
Definition SceneManagement.hpp:38
std::function< void(const SceneInfo &)> onComplete
Optional per-operation callback fired when load completes.
Definition SceneManagement.hpp:41
Lightweight descriptor for a known or loaded scene.
Definition SceneManagement.hpp:24
bool isLoaded
True if the scene is currently active in the world.
Definition SceneManagement.hpp:28
std::string name
Scene base name (e.g. "level1").
Definition SceneManagement.hpp:26
std::string path
Full scene file path (e.g. "assets/scenes/level1.json").
Definition SceneManagement.hpp:27