Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Scene Class Referenceabstract

Base class representing a game scene that manages actors and rendering. Scenes handle actor lifecycles (add, update, remove) and are tied to a specific window and renderer. Derived classes should override Load and Start to define behavior. More...

#include <Scene.h>

Public Member Functions

 Scene ()
 
virtual ~Scene ()
 Scene destructor. Cleans up all actors and clears loaded assets.
 
virtual void Load ()
 Called once before the scene starts. Override to load assets or initialize data.
 
virtual void Start ()=0
 Called once after Load. Must be implemented to initialize gameplay logic.
 
virtual void Update (float deltaTime)
 Updates all actors in the scene. Handles actor lifecycle: updates active ones, removes dead ones, and adds any newly pending actors.
 
void SetWindow (Window *pWindow)
 Sets the window associated with the scene.
 
WindowGetWindow ()
 Gets the window in which the scene in showing.
 
void SetRenderer (IRenderer *pRenderer)
 Sets the renderer used by the scene.
 
IRendererGetRenderer ()
 Gets the renderer associated with the scene.
 
void Reload ()
 Reloads the scene. This is safe to call during an update since the operation happens at the end of an update.
 
void AddActor (Actor *pActor)
 Adds a new actor to the scene. If called during actor updates, the addition is deferred until the update cycle ends.
 
void RemoveActor (Actor *pActor)
 Removes an actor from the scene, either from the active or pending actor lists.
 

Protected Attributes

WindowmWindow
 Pointer to the window the scene uses.
 
IRenderermRenderer
 Renderer responsible for drawing.
 
std::vector< Actor * > mActors {}
 List of currently active actors.
 

Detailed Description

Base class representing a game scene that manages actors and rendering. Scenes handle actor lifecycles (add, update, remove) and are tied to a specific window and renderer. Derived classes should override Load and Start to define behavior.

Constructor & Destructor Documentation

◆ Scene()

Scene::Scene ( )

◆ ~Scene()

Scene::~Scene ( )
virtual

Scene destructor. Cleans up all actors and clears loaded assets.

Member Function Documentation

◆ AddActor()

void Scene::AddActor ( Actor * pActor)

Adds a new actor to the scene. If called during actor updates, the addition is deferred until the update cycle ends.

Parameters
pActorPointer to the actor to add.

◆ GetRenderer()

IRenderer * Scene::GetRenderer ( )

Gets the renderer associated with the scene.

Returns
Pointer to the IRenderer instance used by the scene.

◆ GetWindow()

Window * Scene::GetWindow ( )

Gets the window in which the scene in showing.

Returns
Pointer to the Window instance used by the scene.

◆ Load()

virtual void Scene::Load ( )
inlinevirtual

Called once before the scene starts. Override to load assets or initialize data.

◆ Reload()

void Scene::Reload ( )

Reloads the scene. This is safe to call during an update since the operation happens at the end of an update.

◆ RemoveActor()

void Scene::RemoveActor ( Actor * pActor)

Removes an actor from the scene, either from the active or pending actor lists.

Parameters
pActorPointer to the actor to be removed.

The function searches for the actor in both mPendingActors and mActors, swaps it with the last element if found, and then removes it from the list. This avoids invalidating iterators and ensures efficient removal.

◆ SetRenderer()

void Scene::SetRenderer ( IRenderer * pRenderer)

Sets the renderer used by the scene.

Parameters
pRendererPointer to the IRenderer implementation.

◆ SetWindow()

void Scene::SetWindow ( Window * pWindow)

Sets the window associated with the scene.

Parameters
pWindowPointer to the Window instance.

◆ Start()

virtual void Scene::Start ( )
pure virtual

Called once after Load. Must be implemented to initialize gameplay logic.

◆ Update()

void Scene::Update ( float deltaTime)
virtual

Updates all actors in the scene. Handles actor lifecycle: updates active ones, removes dead ones, and adds any newly pending actors.

Parameters
deltaTimeTime elapsed since the last frame.

Member Data Documentation

◆ mActors

std::vector<Actor*> Scene::mActors {}
protected

List of currently active actors.

◆ mRenderer

IRenderer* Scene::mRenderer
protected

Renderer responsible for drawing.

◆ mWindow

Window* Scene::mWindow
protected

Pointer to the window the scene uses.


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