Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
SceneService Class Referencefinal

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>

Inheritance diagram for SceneService:
[legend]

Public Member Functions

 SceneService ()
 
 SceneService (const std::string &initial_scene_name)
 
 SceneService (const SceneService &)=delete
 
SceneServiceoperator= (const SceneService &)=delete
 
 ~SceneService () override
 
void run_current ()
 This method runs the current scene its game loop directly.
 
bool is_running () const
 Shows if the SceneService is currently running scenes.
 
void stop ()
 Stops the SceneService and the current scene.
 
Sceneadd_scene (const std::string &name)
 Adds a new scene with the given name.
 
SceneServiceload_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.
 
SceneServiceadd_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.
 
SceneServiceremove_scene (const std::string &name)
 Removes the scene with the given name.
 
std::set< std::string > contained_scene_names () const
 Checks if a scene with the given name exists.
 
Scenecurrent_scene () const
 Gets the current active scene.
 
SceneServiceset_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.
 
const std::string & fallback_scene () const
 Gets the fallback scene name.
 
- Public Member Functions inherited from IEngineService
virtual ~IEngineService ()=default
 

Static Public Attributes

static constexpr auto DEFAULT_SCENE_NAME = "DefaultScene"
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SceneService() [1/3]

SceneService::SceneService ( )

◆ SceneService() [2/3]

SceneService::SceneService ( const std::string &  initial_scene_name)
explicit

◆ SceneService() [3/3]

SceneService::SceneService ( const SceneService )
delete

◆ ~SceneService()

SceneService::~SceneService ( )
override

Member Function Documentation

◆ add_scene()

Scene & SceneService::add_scene ( const std::string &  name)

Adds a new scene with the given name.

Parameters
nameThe 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
nameThe 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
nameThe 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_errorif 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

Shows if the SceneService is currently running scenes.

◆ 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
nameThe name of the scene to load.
Returns
A reference to this SceneService for chaining.

◆ operator=()

SceneService & SceneService::operator= ( const SceneService )
delete

◆ remove_scene()

SceneService & SceneService::remove_scene ( const std::string &  name)

Removes the scene with the given name.

Parameters
nameThe 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.

Remarks
Only call this function when selecting an initial scene to run. Use SceneService::load_scene and SceneService::add_scene_and_load to switch between active scenes.
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
nameThe name of the fallback scene.
Returns
A reference to this SceneService for chaining.

◆ stop()

void SceneService::stop ( )

Stops the SceneService and the current scene.

Member Data Documentation

◆ DEFAULT_SCENE_NAME

constexpr auto SceneService::DEFAULT_SCENE_NAME = "DefaultScene"
staticconstexpr

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