Service responsible for managing scenes within the engine. This service allows for adding, removing, loading, and running scenes. It also handles the transition of GameObjects marked as "don't destroy on
load" between scenes.
More...
#include <scene_service.h>
Service responsible for managing scenes within the engine. This service allows for adding, removing, loading, and running scenes. It also handles the transition of GameObjects marked as "don't destroy on
load" between scenes.
- Note
- Only one scene can be active and running at a time.
-
The SceneService must be started by calling run_current() to begin the game loop of the current scene.
-
The SceneService can be stopped by calling stop(), which will stop the current scene and exit the game loop.
◆ SceneService() [1/3]
| SceneService::SceneService |
( |
| ) |
|
◆ SceneService() [2/3]
| SceneService::SceneService |
( |
const std::string & |
initial_scene_name | ) |
|
|
explicit |
◆ SceneService() [3/3]
◆ ~SceneService()
| SceneService::~SceneService |
( |
| ) |
|
|
override |
◆ add_scene()
| Scene & SceneService::add_scene |
( |
const std::string & |
name | ) |
|
Adds a new scene with the given name.
- Parameters
-
| name | The name of the scene to add. |
- Returns
- A reference to the newly added Scene.
◆ add_scene_and_load()
| SceneService & SceneService::add_scene_and_load |
( |
const std::string & |
name | ) |
|
Adds a new scene with the given name and sets it as the next scene to load. The scene will be loaded at the end of the current scene's game loop.
- Parameters
-
| name | The name of the scene to add and load. |
- Returns
- A reference to this SceneService for chaining.
◆ contained_scene_names()
| std::set< std::string > SceneService::contained_scene_names |
( |
| ) |
const |
Checks if a scene with the given name exists.
- Parameters
-
| name | The name of the scene to check. |
- Returns
- true if the scene exists, false otherwise.
◆ current_scene()
| Scene & SceneService::current_scene |
( |
| ) |
const |
Gets the current active scene.
- Returns
- A reference to the current Scene.
- Exceptions
-
| std::runtime_error | if no scene is currently active. |
◆ fallback_scene()
| const std::string & SceneService::fallback_scene |
( |
| ) |
const |
Gets the fallback scene name.
- Returns
- The name of the fallback scene.
◆ is_running()
| bool SceneService::is_running |
( |
| ) |
const |
◆ load_scene()
| SceneService & SceneService::load_scene |
( |
const std::string & |
name | ) |
|
set the scene with the given name as the next scene to load. The scene will be loaded at the end of the current scene's game loop.
- Parameters
-
| name | The name of the scene to load. |
- Returns
- A reference to this SceneService for chaining.
◆ operator=()
◆ remove_scene()
| SceneService & SceneService::remove_scene |
( |
const std::string & |
name | ) |
|
Removes the scene with the given name.
- Parameters
-
| name | The name of the scene to remove. |
- Returns
- A reference to this SceneService for chaining.
◆ run_current()
| void SceneService::run_current |
( |
| ) |
|
This method runs the current scene its game loop directly.
- Warning
- Never call this method more than once, and never call it from within another scene's game loop. This method runs a new game loop directly on the thread where it's called from, meaning it is blocking and stack-frames will pile up if called recursively.
◆ set_fallback_scene()
| SceneService & SceneService::set_fallback_scene |
( |
const std::string & |
name | ) |
|
Sets the fallback scene name. The fallback scene is loaded if the requested scene to load does not exist.
- Parameters
-
| name | The name of the fallback scene. |
- Returns
- A reference to this SceneService for chaining.
◆ stop()
| void SceneService::stop |
( |
| ) |
|
◆ DEFAULT_SCENE_NAME
| constexpr auto SceneService::DEFAULT_SCENE_NAME = "DefaultScene" |
|
staticconstexpr |
The documentation for this class was generated from the following file: