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 Class Reference

Static Unity-style API for scene loading, unloading, and event subscriptions. More...

#include <SceneManagement.hpp>

Static Public Member Functions

static void loadScene (const std::string &nameOrPath, LoadSceneMode mode=LoadSceneMode::Single, bool discardPendingAsync=true)
 Load a scene by name or path.
static void loadScene (int sceneId, LoadSceneMode mode=LoadSceneMode::Single, bool discardPendingAsync=true)
 Load a scene by its integer ID (from a previously loaded scene).
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.
static std::shared_ptr< AsyncOperation > loadSceneAsync (int sceneId, LoadSceneMode mode=LoadSceneMode::Single, bool discardPendingAsync=true)
 Load a scene asynchronously by its integer ID.
static void unloadScene (const std::string &nameOrPath)
 Unload a scene by its name or path.
static void unloadScene (int sceneId)
 Unload a scene by its integer ID.
static void onSceneLoaded (std::function< void(const SceneInfo &)> callback)
 Subscribe a callback to be fired whenever any scene finishes loading.
static void onSceneUnloaded (std::function< void(const SceneInfo &)> callback)
 Subscribe a callback to be fired whenever any scene is unloaded.
static std::vector< SceneInfo > getLoadedScenes ()
 Returns all currently loaded scenes.
static SceneInfo getSceneInfo (int sceneId)
 Get scene info by integer ID.
static SceneInfo getSceneInfo (const std::string &nameOrPath)
 Get scene info by name or path.
static void setSceneManager (SceneManager *manager)
 Called once at engine boot to wire the SceneManager.

Static Private Attributes

static SceneManager * s_sceneManager = nullptr

Detailed Description

Static Unity-style API for scene loading, unloading, and event subscriptions.

Usage:

// Load by name, path, or id
SceneManagement::loadScene("assets/scenes/level1.json");
// Additive loading
// Async loading with progress tracking
auto op = SceneManagement::loadSceneAsync("level2");
if (op->isDone) { ... }
op->onComplete = [](const SceneInfo& info) { ... };
// Unload a specific scene
// Subscribe to global events
SceneManagement::onSceneLoaded([](const SceneInfo& info) { ... });
SceneManagement::onSceneUnloaded([](const SceneInfo& info) { ... });
// Query
SceneInfo info = SceneManagement::getSceneInfo("level1");
@ Additive
Load the new scene alongside existing ones.
Definition SceneManagement.hpp:17
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 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
Lightweight descriptor for a known or loaded scene.
Definition SceneManagement.hpp:24

Member Function Documentation

◆ getLoadedScenes()

std::vector< SceneInfo > SceneManagement::getLoadedScenes ( )
static

Returns all currently loaded scenes.

◆ getSceneInfo() [1/2]

SceneInfo SceneManagement::getSceneInfo ( const std::string & nameOrPath)
static

Get scene info by name or path.

◆ getSceneInfo() [2/2]

SceneInfo SceneManagement::getSceneInfo ( int sceneId)
static

Get scene info by integer ID.

◆ loadScene() [1/2]

void SceneManagement::loadScene ( const std::string & nameOrPath,
LoadSceneMode mode = LoadSceneMode::Single,
bool discardPendingAsync = true )
static

Load a scene by name or path.

Parameters
nameOrPathScene name (e.g. "level1") or path (e.g. "assets/scenes/level1.json").
modeSingle replaces all scenes; Additive adds alongside existing ones.
discardPendingAsyncIf true, cancels any in-flight async loads before proceeding.

◆ loadScene() [2/2]

void SceneManagement::loadScene ( int sceneId,
LoadSceneMode mode = LoadSceneMode::Single,
bool discardPendingAsync = true )
static

Load a scene by its integer ID (from a previously loaded scene).

Parameters
sceneIdThe numeric ID of the scene to load/reload.
modeSingle replaces all scenes; Additive adds alongside existing ones.
discardPendingAsyncIf true, cancels any in-flight async loads before proceeding.

◆ loadSceneAsync() [1/2]

std::shared_ptr< AsyncOperation > SceneManagement::loadSceneAsync ( const std::string & nameOrPath,
LoadSceneMode mode = LoadSceneMode::Single,
bool discardPendingAsync = true )
static

Load a scene asynchronously by name or path.

Parameters
nameOrPathScene name or path.
modeSingle or Additive.
discardPendingAsyncIf true, cancels any in-flight async loads before proceeding.
Returns
Shared handle to track load progress.

◆ loadSceneAsync() [2/2]

std::shared_ptr< AsyncOperation > SceneManagement::loadSceneAsync ( int sceneId,
LoadSceneMode mode = LoadSceneMode::Single,
bool discardPendingAsync = true )
static

Load a scene asynchronously by its integer ID.

Parameters
sceneIdThe numeric ID of the scene to reload.
modeSingle or Additive.
discardPendingAsyncIf true, cancels any in-flight async loads before proceeding.
Returns
Shared handle to track load progress.

◆ onSceneLoaded()

void SceneManagement::onSceneLoaded ( std::function< void(const SceneInfo &)> callback)
static

Subscribe a callback to be fired whenever any scene finishes loading.

Parameters
callbackReceives the SceneInfo of the loaded scene.

◆ onSceneUnloaded()

void SceneManagement::onSceneUnloaded ( std::function< void(const SceneInfo &)> callback)
static

Subscribe a callback to be fired whenever any scene is unloaded.

Parameters
callbackReceives the SceneInfo of the unloaded scene.

◆ setSceneManager()

void SceneManagement::setSceneManager ( SceneManager * manager)
static

Called once at engine boot to wire the SceneManager.

◆ unloadScene() [1/2]

void SceneManagement::unloadScene ( const std::string & nameOrPath)
static

Unload a scene by its name or path.

Parameters
nameOrPathScene name (e.g. "level1") or full path.

◆ unloadScene() [2/2]

void SceneManagement::unloadScene ( int sceneId)
static

Unload a scene by its integer ID.

Parameters
sceneIdNumeric scene ID.

Member Data Documentation

◆ s_sceneManager

SceneManager * SceneManagement::s_sceneManager = nullptr
staticprivate

The documentation for this class was generated from the following files: