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::Scene< T > Class Template Reference

Base class for game scenes. More...

#include <scene.h>

Public Member Functions

 Scene (SceneManager< T > &manager)
 Constructor for the Scene class.
 
virtual ~Scene ()=default
 Destructor for the Scene class.
 
virtual void init ()
 Initialize the game scene.
 
virtual void update (float dt)
 Update the game scene.
 
virtual void draw ()
 Draw the game scene.
 
virtual void cleanup ()
 Clean up the game scene.
 
void register_object (const std::shared_ptr< game::GameObject > &obj)
 Add a game object to the scene.
 
template<typename ObjectType , typename... Args>
std::shared_ptr< ObjectType > create_object (Args &&... args)
 Create a new game object in the scene.
 
const std::vector< std::shared_ptr< game::GameObject > > & get_objects () const
 Get game objects in the scene.
 
template<typename ObjectType >
std::vector< std::shared_ptr< ObjectType > > get_object_view ()
 Get game objects of a specific type in the scene.
 

Protected Attributes

SceneManager< T > & manager
 Reference to the scene manager.
 

Private Attributes

std::vector< std::shared_ptr< game::GameObject > > _objects
 Collection of game objects in the scene.
 
std::vector< std::shared_ptr< game::GameObject > > _obj_to_create
 Objects to be created in the next frame.
 

Detailed Description

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

Base class for game scenes.

Template Parameters
TThe type of the scene ID.

This class defines the interface for game scenes in the scene engine.

Definition at line 46 of file scene.h.

Constructor & Destructor Documentation

◆ Scene()

template<typename T >
asw::scene::Scene< T >::Scene ( SceneManager< T > & manager)
inlineexplicit

Constructor for the Scene class.

Parameters
managerReference to the SceneManager object.

This constructor initializes the scene engine reference.

Definition at line 52 of file scene.h.

◆ ~Scene()

template<typename T >
virtual asw::scene::Scene< T >::~Scene ( )
virtualdefault

Destructor for the Scene class.

Member Function Documentation

◆ cleanup()

template<typename T >
virtual void asw::scene::Scene< T >::cleanup ( )
inlinevirtual

Clean up the game scene.

Called when the game switches away from this scene. Removes all objects by default, including ones queued by create_object() that have not been added yet.

Definition at line 128 of file scene.h.

◆ create_object()

template<typename T >
template<typename ObjectType , typename... Args>
std::shared_ptr< ObjectType > asw::scene::Scene< T >::create_object ( Args &&... args)
inline

Create a new game object in the scene.

Parameters
gameObjectThe game object to add to the scene.

Definition at line 148 of file scene.h.

◆ draw()

template<typename T >
virtual void asw::scene::Scene< T >::draw ( )
inlinevirtual

Draw the game scene.

This function is called every frame to draw the scene.

Definition at line 105 of file scene.h.

◆ get_object_view()

template<typename T >
template<typename ObjectType >
std::vector< std::shared_ptr< ObjectType > > asw::scene::Scene< T >::get_object_view ( )
inline

Get game objects of a specific type in the scene.

Template Parameters
ObjectTypeThe type of the game object to get.
Returns
A vector of shared pointers to game objects of the specified type in the scene.

Definition at line 175 of file scene.h.

◆ get_objects()

template<typename T >
const std::vector< std::shared_ptr< game::GameObject > > & asw::scene::Scene< T >::get_objects ( ) const
inline

Get game objects in the scene.

Returns
A vector of shared pointers to game objects in the scene.

Definition at line 164 of file scene.h.

◆ init()

template<typename T >
virtual void asw::scene::Scene< T >::init ( )
inlinevirtual

Initialize the game scene.

Called each time the scene becomes the active scene, so it runs again when the game returns to this scene.

Definition at line 65 of file scene.h.

◆ register_object()

template<typename T >
void asw::scene::Scene< T >::register_object ( const std::shared_ptr< game::GameObject > & obj)
inline

Add a game object to the scene.

Parameters
gameObjectThe game object to add to the scene.

Definition at line 138 of file scene.h.

◆ update()

template<typename T >
virtual void asw::scene::Scene< T >::update ( float dt)
inlinevirtual

Update the game scene.

Parameters
dtThe time in seconds since the last update.

This function is called every frame to update the scene.

Definition at line 74 of file scene.h.

Member Data Documentation

◆ _obj_to_create

template<typename T >
std::vector<std::shared_ptr<game::GameObject> > asw::scene::Scene< T >::_obj_to_create
private

Objects to be created in the next frame.

Definition at line 198 of file scene.h.

◆ _objects

template<typename T >
std::vector<std::shared_ptr<game::GameObject> > asw::scene::Scene< T >::_objects
private

Collection of game objects in the scene.

Definition at line 195 of file scene.h.

◆ manager

template<typename T >
SceneManager<T>& asw::scene::Scene< T >::manager
protected

Reference to the scene manager.

Definition at line 191 of file scene.h.


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