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

Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecycle, including running the game loop, stopping, and destroying the scene. More...

#include <scene.h>

Public Member Functions

virtual ~Scene ()
 
void on_run (listener_function_t &&listener)
 Registers a listener function to be called when the scene starts running.
 
void on_stop (listener_function_t &&listener)
 Registers a listener function to be called when the scene stops.
 
void on_destroy (listener_function_t &&listener)
 Registers a listener function to be called when the scene is destroyed.
 
void stop ()
 marks the scene to be stopped.
 
bool marked_for_stopping () const
 Checks if the scene is marked for stopping.
 
void mark_for_stopping () noexcept
 Marks the scene to be stopped.
 
Scenetime_scale (float modifier)
 Sets the time scale modifier for the scene.
 
float time_scale () const
 Retrieves the current time scale modifier for the scene.
 
const std::string & name () const
 Retrieves the name of the scene.
 
bool is_running () const
 Checks if the scene is currently running.
 
std::reference_wrapper< GameObjectget_game_object (const std::string &id) const
 Retrieves a GameObject by its unique identifier.
 
std::vector< std::reference_wrapper< GameObject > > game_objects () const
 Retrieves all GameObjects in the scene.
 
std::vector< std::reference_wrapper< GameObject > > active_game_objects () const
 Retrieves all active GameObjects in the scene.
 
template<typename T , typename... Args>
T & add_game_object (Args &&... args)
 Adds a new GameObject of type T to the scene.
 
GameObjectadd_game_object (const std::string &name)
 Adds a new GameObject with the given name to the scene.
 
Sceneadd_game_object (std::unique_ptr< GameObject > game_object)
 Adds an existing GameObject to the scene.
 
Sceneadd_game_objects (std::vector< std::unique_ptr< GameObject > > game_objects)
 Adds multiple existing GameObjects to the scene.
 
std::unique_ptr< GameObjectextract_game_object (GameObject &game_object)
 Extracts a GameObject from the scene without deleting it.
 
bool remove_game_object (GameObject &game_object)
 Removes a GameObject from the scene and deletes it.
 
void cleanup_destroyed_game_objects ()
 Cleans up and deletes all GameObjects that are marked for deletion.
 
std::optional< std::reference_wrapper< Camera > > main_camera () const
 Retrieves the main camera of the scene.
 

Friends

class SceneService
 

Detailed Description

Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecycle, including running the game loop, stopping, and destroying the scene.

Note
A scene can have multiple cameras, but only one main camera.
GameObjects can be marked as "don't destroy on load" to persist between scene loads.

Constructor & Destructor Documentation

◆ ~Scene()

virtual Scene::~Scene ( )
virtual

Member Function Documentation

◆ active_game_objects()

std::vector< std::reference_wrapper< GameObject > > Scene::active_game_objects ( ) const

Retrieves all active GameObjects in the scene.

Returns
A vector of references to all active GameObjects in the scene.

◆ add_game_object() [1/3]

template<typename T , typename... Args>
T & Scene::add_game_object ( Args &&...  args)
inline

Adds a new GameObject of type T to the scene.

Template Parameters
TThe type of the GameObject to add. Must be derived from GameObject
Parameters
argsThe arguments to forward to the GameObject's constructor.
Returns
A reference to the added GameObject.

◆ add_game_object() [2/3]

GameObject & Scene::add_game_object ( const std::string &  name)

Adds a new GameObject with the given name to the scene.

Parameters
nameThe name of the GameObject to add.
Returns
A reference to the added GameObject.

◆ add_game_object() [3/3]

Scene & Scene::add_game_object ( std::unique_ptr< GameObject game_object)

Adds an existing GameObject to the scene.

Parameters
game_objectThe unique pointer to the GameObject to add.
Returns
A reference to the added GameObject.

◆ add_game_objects()

Scene & Scene::add_game_objects ( std::vector< std::unique_ptr< GameObject > >  game_objects)

Adds multiple existing GameObjects to the scene.

Parameters
game_objectsA vector of unique pointers to the GameObjects to add.
Returns
A reference to the added GameObjects.

◆ cleanup_destroyed_game_objects()

void Scene::cleanup_destroyed_game_objects ( )

Cleans up and deletes all GameObjects that are marked for deletion.

◆ extract_game_object()

std::unique_ptr< GameObject > Scene::extract_game_object ( GameObject game_object)

Extracts a GameObject from the scene without deleting it.

Parameters
game_objectThe GameObject to extract.
Returns
A unique pointer to the extracted GameObject.

◆ game_objects()

std::vector< std::reference_wrapper< GameObject > > Scene::game_objects ( ) const

Retrieves all GameObjects in the scene.

Returns
A vector of references to all GameObjects in the scene.

◆ get_game_object()

std::reference_wrapper< GameObject > Scene::get_game_object ( const std::string &  id) const

Retrieves a GameObject by its unique identifier.

Parameters
idThe unique identifier of the GameObject.
Returns
A reference to the GameObject with the specified ID.
Exceptions
std::runtime_errorif no GameObject with the given ID exists in the scene.

◆ is_running()

bool Scene::is_running ( ) const

Checks if the scene is currently running.

Returns
true if the scene is running, false otherwise.

◆ main_camera()

std::optional< std::reference_wrapper< Camera > > Scene::main_camera ( ) const

Retrieves the main camera of the scene.

Returns
An optional reference to the main Camera if it exists, std::nullopt otherwise.

◆ mark_for_stopping()

void Scene::mark_for_stopping ( )
noexcept

Marks the scene to be stopped.

◆ marked_for_stopping()

bool Scene::marked_for_stopping ( ) const

Checks if the scene is marked for stopping.

Returns
true if the scene is marked for stopping, false otherwise.

◆ name()

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

Retrieves the name of the scene.

Returns
The name of the scene as a string.

◆ on_destroy()

void Scene::on_destroy ( listener_function_t &&  listener)

Registers a listener function to be called when the scene is destroyed.

Parameters
listenerThe function to be called when the scene is destroyed.

◆ on_run()

void Scene::on_run ( listener_function_t &&  listener)

Registers a listener function to be called when the scene starts running.

Parameters
listenerThe function to be called when the scene starts.

◆ on_stop()

void Scene::on_stop ( listener_function_t &&  listener)

Registers a listener function to be called when the scene stops.

Parameters
listenerThe function to be called when the scene stops.

◆ remove_game_object()

bool Scene::remove_game_object ( GameObject game_object)

Removes a GameObject from the scene and deletes it.

Parameters
game_objectThe GameObject to remove.
Returns
true if the GameObject was found and removed, false otherwise.

◆ stop()

void Scene::stop ( )

marks the scene to be stopped.

◆ time_scale() [1/2]

float Scene::time_scale ( ) const

Retrieves the current time scale modifier for the scene.

Returns
The time scale modifier.

◆ time_scale() [2/2]

Scene & Scene::time_scale ( float  modifier)

Sets the time scale modifier for the scene.

Parameters
modifierThe time scale modifier. A value of 1.0 represents normal time, values greater than 1.0 speed up time, and values less than 1.0 slow down time.
Returns
A reference to this Scene for chaining.

Friends And Related Symbol Documentation

◆ SceneService

friend class SceneService
friend

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