ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::scene::SceneManager< T > Class Template Reference

Forward declaration of the SceneManager class. More...

#include <scene.h>

Public Member Functions

 SceneManager ()
 Constructor for the SceneManager class.
 
template<typename SceneType , typename... Args>
void register_scene (const T scene_id, Args &&... args)
 Register a scene to be managed by the scene engine.
 
void set_next_scene (const T scene_id)
 Set the next scene.
 
void start ()
 Main loop for the scene engine. If this is not enough, or you want to define your own loop, you can use the update and draw functions directly.
 
void cleanup ()
 Destroy the scene manager and clean up resources. This function is called when the scene manager is destroyed to clean up any resources used by the scene engine.
 
void update (const float dt)
 Update the current scene.
 
void draw ()
 Draw the current scene.
 
void set_timestep (std::chrono::nanoseconds ts)
 Set the fixed timestep for the game loop.
 
std::chrono::nanoseconds get_timestep () const
 Get the current timestep.
 
int get_fps () const
 Get the current FPS. Only applies to the managed loop.
 

Private Member Functions

void change_scene ()
 Change the current scene to the next scene.
 

Private Attributes

std::shared_ptr< Scene< T > > _active_scene { nullptr }
 The current scene of the scene engine.
 
_next_scene
 The next scene of the scene engine.
 
bool _has_next_scene { false }
 Flag to indicate if there is a next scene to change to.
 
std::unordered_map< T, std::shared_ptr< Scene< T > > > _scenes
 Collection of all scenes registered in the scene engine.
 
std::chrono::nanoseconds _timestep { DEFAULT_TIMESTEP }
 Fixed timestep for the game loop.
 
int _fps { 0 }
 FPS Counter for managed loop.
 

Detailed Description

template<typename T>
class asw::scene::SceneManager< T >

Forward declaration of the SceneManager class.

SceneManager class for managing game scenes.

Template Parameters
TThe type of the scene ID.

This class manages the registration, updating, and drawing of game scenes. It also handles the transition between scenes.

Definition at line 189 of file scene.h.

Constructor & Destructor Documentation

◆ SceneManager()

template<typename T >
asw::scene::SceneManager< T >::SceneManager ( )
inline

Constructor for the SceneManager class.

Definition at line 193 of file scene.h.

Member Function Documentation

◆ change_scene()

template<typename T >
void asw::scene::SceneManager< T >::change_scene ( )
inlineprivate

Change the current scene to the next scene.

Definition at line 349 of file scene.h.

◆ cleanup()

template<typename T >
void asw::scene::SceneManager< T >::cleanup ( )
inline

Destroy the scene manager and clean up resources. This function is called when the scene manager is destroyed to clean up any resources used by the scene engine.

Definition at line 277 of file scene.h.

◆ draw()

template<typename T >
void asw::scene::SceneManager< T >::draw ( )
inline

Draw the current scene.

Definition at line 306 of file scene.h.

◆ get_fps()

template<typename T >
int asw::scene::SceneManager< T >::get_fps ( ) const
inline

Get the current FPS. Only applies to the managed loop.

Returns
The current FPS.

Definition at line 341 of file scene.h.

◆ get_timestep()

template<typename T >
std::chrono::nanoseconds asw::scene::SceneManager< T >::get_timestep ( ) const
inline

Get the current timestep.

Returns
The current timestep duration.

Definition at line 332 of file scene.h.

◆ register_scene()

template<typename T >
template<typename SceneType , typename... Args>
void asw::scene::SceneManager< T >::register_scene ( const T scene_id,
Args &&... args )
inline

Register a scene to be managed by the scene engine.

Parameters
scene_idThe unique identifier for the scene.
scenePointer to the Scene object to be registered.

Definition at line 207 of file scene.h.

◆ set_next_scene()

template<typename T >
void asw::scene::SceneManager< T >::set_next_scene ( const T scene_id)
inline

Set the next scene.

Parameters
scene_idThe unique identifier for the scene.

Definition at line 222 of file scene.h.

◆ set_timestep()

template<typename T >
void asw::scene::SceneManager< T >::set_timestep ( std::chrono::nanoseconds ts)
inline

Set the fixed timestep for the game loop.

Parameters
tsTimestep duration (default: 8ms).

Definition at line 323 of file scene.h.

◆ start()

template<typename T >
void asw::scene::SceneManager< T >::start ( )
inline

Main loop for the scene engine. If this is not enough, or you want to define your own loop, you can use the update and draw functions directly.

This function is called to start the main loop of the scene engine.

Definition at line 234 of file scene.h.

◆ update()

template<typename T >
void asw::scene::SceneManager< T >::update ( const float dt)
inline

Update the current scene.

Parameters
dtThe time in seconds since the last update.

Definition at line 290 of file scene.h.

Member Data Documentation

◆ _active_scene

template<typename T >
std::shared_ptr<Scene<T> > asw::scene::SceneManager< T >::_active_scene { nullptr }
private

The current scene of the scene engine.

Definition at line 368 of file scene.h.

◆ _fps

template<typename T >
int asw::scene::SceneManager< T >::_fps { 0 }
private

FPS Counter for managed loop.

Definition at line 383 of file scene.h.

◆ _has_next_scene

template<typename T >
bool asw::scene::SceneManager< T >::_has_next_scene { false }
private

Flag to indicate if there is a next scene to change to.

Definition at line 374 of file scene.h.

◆ _next_scene

template<typename T >
T asw::scene::SceneManager< T >::_next_scene
private

The next scene of the scene engine.

Definition at line 371 of file scene.h.

◆ _scenes

template<typename T >
std::unordered_map<T, std::shared_ptr<Scene<T> > > asw::scene::SceneManager< T >::_scenes
private

Collection of all scenes registered in the scene engine.

Definition at line 377 of file scene.h.

◆ _timestep

template<typename T >
std::chrono::nanoseconds asw::scene::SceneManager< T >::_timestep { DEFAULT_TIMESTEP }
private

Fixed timestep for the game loop.

Definition at line 380 of file scene.h.


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