Skip to content

Class Engine::SceneManager

ClassList > Engine > SceneManager

Switches between scenes while the game runs. More...

  • #include <SceneManager.hpp>

Public Types

Type Name
typedef std::function< void(Registry &)> Builder
Creates the entities of a code scene.
typedef std::function< bool(Registry &, const std::string &)> FileLoader
Loads a scene file into the registry. Returns false on failure.
typedef std::function< void(Registry &, const std::string &)> LoadedCallback
Runs after a scene was built. Receives the scene name.

Public Functions

Type Name
bool ApplyPending (Registry & registry)
Applies the pending switch, if any. Called by Application .
const std::string & Current () const
Name of the scene currently loaded, or empty if none.
bool HasFileLoader () const
True once a file loader is installed.
bool HasPendingLoad () const
True while a switch is waiting to be applied.
bool IsRegistered (const std::string & name) const
True if name was registered withRegister .
void Load (const std::string & name)
Asks to switch to name at the end of the current frame.
void OnLoaded (LoadedCallback callback)
Adds a callback that runs after every successful switch.
void Register (const std::string & name, Builder builder)
Registers a code scene. Replaces any scene with the same name.
void SetFileLoader (FileLoader loader)
Installs the function used to load scene files.

Detailed Description

A scene is either: * a code scene: a C++ function registered with Register that creates the entities, or * a scene file (e.g. "Level1.scene") made in the editor. Loading files needs a loader installed with SetFileLoader. The Engine cannot depend on Serialization, so Serialization installs it (same pattern as PrefabSpawner).

Load only queues the switch. Application applies it between frames, so no system ever sees a half-loaded world: * every system gets System::OnSceneUnloaded, * all entities are destroyed and IDs restart at 1 (Registry::ClearEntities), * the new scene is built, * the OnLoaded callbacks run.

Resources (score, lives, settings...) are not touched, so use them for data that must survive a switch.

auto& scenes = app.GetRegistry().AddResource<Engine::SceneManager>();
scenes.Register("menu", [](Engine::Registry& r) { ... });
scenes.Load("menu");
app.Run();

Public Types Documentation

typedef Builder

Creates the entities of a code scene.

using Engine::SceneManager::Builder =  std::function<void(Registry&)>;


typedef FileLoader

Loads a scene file into the registry. Returns false on failure.

using Engine::SceneManager::FileLoader =  std::function<bool(Registry&, const std::string&)>;

Receives the resolved path (see ResolveAssetPath), already checked to exist. The registry is empty when it is called.


typedef LoadedCallback

Runs after a scene was built. Receives the scene name.

using Engine::SceneManager::LoadedCallback =  std::function<void(Registry&, const std::string&)>;


Public Functions Documentation

function ApplyPending

Applies the pending switch, if any. Called by Application .

bool Engine::SceneManager::ApplyPending (
    Registry & registry
) 

If the scene can't be found (unknown name, no file loader, or missing file), the request is dropped with an error and the current scene keeps running.

Returns:

True if a scene was switched.


function Current

Name of the scene currently loaded, or empty if none.

const std::string & Engine::SceneManager::Current () const


function HasFileLoader

True once a file loader is installed.

bool Engine::SceneManager::HasFileLoader () const


function HasPendingLoad

True while a switch is waiting to be applied.

bool Engine::SceneManager::HasPendingLoad () const


function IsRegistered

True if name was registered withRegister .

bool Engine::SceneManager::IsRegistered (
    const std::string & name
) const


function Load

Asks to switch to name at the end of the current frame.

void Engine::SceneManager::Load (
    const std::string & name
) 

Code scenes are checked first, then name is treated as a scene file path. Calling it again in the same frame replaces the earlier request.


function OnLoaded

Adds a callback that runs after every successful switch.

void Engine::SceneManager::OnLoaded (
    LoadedCallback callback
) 


function Register

Registers a code scene. Replaces any scene with the same name.

void Engine::SceneManager::Register (
    const std::string & name,
    Builder builder
) 


function SetFileLoader

Installs the function used to load scene files.

void Engine::SceneManager::SetFileLoader (
    FileLoader loader
) 



The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/Resources/SceneManager.hpp