SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::SceneBase Class Referenceabstract

#include <SceneBase.hpp>

Inheritance diagram for Sleak::SceneBase:

Public Member Functions

 SceneBase (const std::string &name)
virtual ~SceneBase ()
void Activate ()
 Marks the scene active and calls OnActivate().
virtual void AddObject (GameObject *object)
 Takes ownership of object, registering it with lighting and physics as needed.
virtual void Begin ()=0
 Activates every owned object; runs once after Initialize().
void Deactivate ()
 Marks the scene inactive and calls OnDeactivate().
void DestroyObject (GameObject *object)
 Queues an object for destruction; actually freed on the next ProcessPendingDestroy().
GameObjectFindObjectByID (uint64_t id)
 Linear search for the object with a matching unique ID.
GameObjectFindObjectByName (const std::string &name)
 Linear search for the first object with a matching name.
List< GameObject * > FindObjectsByTag (const std::string &tag)
 Collects every object whose tag matches.
virtual void FixedUpdate (float fixedDeltaTime)
 Advances all active, root-level objects on the fixed timestep.
CameraGetActiveCamera () const
LightManagerGetLightManager () const
const std::string & GetName () const
size_t GetObjectCount () const
const List< GameObject * > & GetObjects () const
Physics::PhysicsWorldGetPhysicsWorld () const
SkyboxGetSkybox () const
SceneState GetState () const
virtual bool Initialize ()
 Runs once before the scene's first Begin()/Update().
bool IsActive () const
bool IsLoaded () const
virtual void LateUpdate (float deltaTime)
 Advances all active, root-level objects after the main Update pass.
void Load ()
 Moves Unloaded -> Loading -> Active, calling OnLoad() and Initialize().
virtual void OnActivate ()
 Override for logic that should run when the scene becomes active.
virtual void OnDeactivate ()
 Override for logic that should run when the scene stops being active.
virtual void OnLoad ()
 Override to load scene-specific assets; called once from Load().
virtual void OnUnload ()
 Override to release scene-specific assets; called from Unload().
void Pause ()
 Freezes the scene without tearing it down; leaves it in the Paused state.
virtual void RemoveObject (GameObject *object)
 Unregisters and deletes object immediately.
void Resume ()
 Reactivates a paused scene without re-running OnActivate().
void SetActiveCamera (Camera *cam)
void SetSkybox (Skybox *skybox)
 Replaces the scene's skybox, deleting the previous one.
void Unload ()
 Deactivates if active, calls OnUnload(), and destroys all owned objects.
virtual void Update (float deltaTime)=0
 Advances all active, root-level objects by deltaTime, then steps lighting and physics.

Protected Member Functions

void DestroyAllObjects ()
 Destroys every object still owned by the scene, e.g. during Unload().
void ProcessPendingDestroy ()
 Actually deletes objects queued by DestroyObject().

Protected Attributes

bool bActive
bool bInitialized
Cameram_activeCamera = nullptr
LightManagerm_lightManager = nullptr
List< GameObject * > m_pendingDestroy
Physics::PhysicsWorldm_physicsWorld = nullptr
Skyboxm_skybox = nullptr
std::string name
List< GameObject * > Objects
SceneState state

Detailed Description

Non-templated scene interface: object ownership, state machine, and per-frame update hooks. Game scenes derive from Scene, not this directly.

SceneBase defines what every scene can do regardless of subclass: hold objects, move through the SceneState machine, and answer queries. GameBase stores scenes by SceneBase*, so this is the type you see in the scene registry API.

Ownership is strict. AddObject() transfers ownership to the scene. RemoveObject() unregisters and deletes immediately, which is unsafe from inside that object's own update. DestroyObject() queues the object (and its children) for deletion at the end of the frame, which is the safe choice while iterating.

Objects added to the scene are registered with the LightManager if they report IsLight(), and their colliders are registered with the PhysicsWorld, hierarchy included.

// Destroy safely from inside an update
if (auto* target = FindObjectByName("Crate")) {
DestroyObject(target);
}
// Act on a group
for (size_t i = 0; i < enemies.GetSize(); ++i) {
enemies[i]->SetActive(false);
}
// Scene-wide services
if (auto* lm = GetLightManager()) lm->SetAmbientIntensity(0.6f);
if (auto* pw = GetPhysicsWorld()) {
auto hit = pw->Raycast(origin, direction, 100.0f);
}
Implements a dynamic array-like list for storing and managing a collection of elements.
Definition List.hpp:20
size_t GetSize() const
Definition List.hpp:151
List< GameObject * > FindObjectsByTag(const std::string &tag)
Collects every object whose tag matches.
LightManager * GetLightManager() const
Physics::PhysicsWorld * GetPhysicsWorld() const
GameObject * FindObjectByName(const std::string &name)
Linear search for the first object with a matching name.
void DestroyObject(GameObject *object)
Queues an object for destruction; actually freed on the next ProcessPendingDestroy().
See also
Scene, GameBase, GameObject, SceneState, Physics::PhysicsWorld

Definition at line 70 of file SceneBase.hpp.

Constructor & Destructor Documentation

◆ SceneBase()

Sleak::SceneBase::SceneBase ( const std::string & name)
inlineexplicit

Definition at line 72 of file SceneBase.hpp.

◆ ~SceneBase()

Sleak::SceneBase::~SceneBase ( )
virtual

Definition at line 40 of file SceneBase.cpp.

Member Function Documentation

◆ Activate()

void Sleak::SceneBase::Activate ( )

Marks the scene active and calls OnActivate().

Definition at line 74 of file SceneBase.cpp.

◆ AddObject()

void Sleak::SceneBase::AddObject ( GameObject * object)
virtual

Takes ownership of object, registering it with lighting and physics as needed.

Definition at line 234 of file SceneBase.cpp.

◆ Begin()

void Sleak::SceneBase::Begin ( )
pure virtual

Activates every owned object; runs once after Initialize().

Implemented in Sleak::Scene.

Definition at line 137 of file SceneBase.cpp.

◆ Deactivate()

void Sleak::SceneBase::Deactivate ( )

Marks the scene inactive and calls OnDeactivate().

Definition at line 87 of file SceneBase.cpp.

◆ DestroyAllObjects()

void Sleak::SceneBase::DestroyAllObjects ( )
protected

Destroys every object still owned by the scene, e.g. during Unload().

Definition at line 340 of file SceneBase.cpp.

◆ DestroyObject()

void Sleak::SceneBase::DestroyObject ( GameObject * object)

Queues an object for destruction; actually freed on the next ProcessPendingDestroy().

Definition at line 271 of file SceneBase.cpp.

◆ FindObjectByID()

GameObject * Sleak::SceneBase::FindObjectByID ( uint64_t id)

Linear search for the object with a matching unique ID.

Definition at line 295 of file SceneBase.cpp.

◆ FindObjectByName()

GameObject * Sleak::SceneBase::FindObjectByName ( const std::string & name)

Linear search for the first object with a matching name.

Definition at line 286 of file SceneBase.cpp.

◆ FindObjectsByTag()

List< GameObject * > Sleak::SceneBase::FindObjectsByTag ( const std::string & tag)

Collects every object whose tag matches.

Definition at line 304 of file SceneBase.cpp.

◆ FixedUpdate()

void Sleak::SceneBase::FixedUpdate ( float fixedDeltaTime)
virtual

Advances all active, root-level objects on the fixed timestep.

Reimplemented in Sleak::Scene.

Definition at line 214 of file SceneBase.cpp.

◆ GetActiveCamera()

Camera * Sleak::SceneBase::GetActiveCamera ( ) const
inline

Definition at line 142 of file SceneBase.hpp.

◆ GetLightManager()

LightManager * Sleak::SceneBase::GetLightManager ( ) const
inline

Definition at line 145 of file SceneBase.hpp.

◆ GetName()

const std::string & Sleak::SceneBase::GetName ( ) const
inline

Definition at line 105 of file SceneBase.hpp.

◆ GetObjectCount()

size_t Sleak::SceneBase::GetObjectCount ( ) const
inline

Definition at line 140 of file SceneBase.hpp.

◆ GetObjects()

const List< GameObject * > & Sleak::SceneBase::GetObjects ( ) const
inline

Definition at line 131 of file SceneBase.hpp.

◆ GetPhysicsWorld()

Physics::PhysicsWorld * Sleak::SceneBase::GetPhysicsWorld ( ) const
inline

Definition at line 149 of file SceneBase.hpp.

◆ GetSkybox()

Skybox * Sleak::SceneBase::GetSkybox ( ) const
inline

Definition at line 155 of file SceneBase.hpp.

◆ GetState()

SceneState Sleak::SceneBase::GetState ( ) const
inline

Definition at line 106 of file SceneBase.hpp.

◆ Initialize()

bool Sleak::SceneBase::Initialize ( )
virtual

Runs once before the scene's first Begin()/Update().

Reimplemented in Sleak::Scene.

Definition at line 106 of file SceneBase.cpp.

◆ IsActive()

bool Sleak::SceneBase::IsActive ( ) const
inline

Definition at line 107 of file SceneBase.hpp.

◆ IsLoaded()

bool Sleak::SceneBase::IsLoaded ( ) const
inline

Definition at line 108 of file SceneBase.hpp.

◆ LateUpdate()

void Sleak::SceneBase::LateUpdate ( float deltaTime)
virtual

Advances all active, root-level objects after the main Update pass.

Reimplemented in Sleak::Scene.

Definition at line 224 of file SceneBase.cpp.

◆ Load()

void Sleak::SceneBase::Load ( )

Moves Unloaded -> Loading -> Active, calling OnLoad() and Initialize().

Definition at line 50 of file SceneBase.cpp.

◆ OnActivate()

virtual void Sleak::SceneBase::OnActivate ( )
inlinevirtual

Override for logic that should run when the scene becomes active.

Reimplemented in Sleak::Scene.

Definition at line 86 of file SceneBase.hpp.

◆ OnDeactivate()

virtual void Sleak::SceneBase::OnDeactivate ( )
inlinevirtual

Override for logic that should run when the scene stops being active.

Reimplemented in Sleak::Scene.

Definition at line 88 of file SceneBase.hpp.

◆ OnLoad()

virtual void Sleak::SceneBase::OnLoad ( )
inlinevirtual

Override to load scene-specific assets; called once from Load().

Reimplemented in Sleak::Scene.

Definition at line 80 of file SceneBase.hpp.

◆ OnUnload()

virtual void Sleak::SceneBase::OnUnload ( )
inlinevirtual

Override to release scene-specific assets; called from Unload().

Reimplemented in Sleak::Scene.

Definition at line 82 of file SceneBase.hpp.

◆ Pause()

void Sleak::SceneBase::Pause ( )

Freezes the scene without tearing it down; leaves it in the Paused state.

Definition at line 94 of file SceneBase.cpp.

◆ ProcessPendingDestroy()

void Sleak::SceneBase::ProcessPendingDestroy ( )
protected

Actually deletes objects queued by DestroyObject().

Definition at line 314 of file SceneBase.cpp.

◆ RemoveObject()

void Sleak::SceneBase::RemoveObject ( GameObject * object)
virtual

Unregisters and deletes object immediately.

Definition at line 255 of file SceneBase.cpp.

◆ Resume()

void Sleak::SceneBase::Resume ( )

Reactivates a paused scene without re-running OnActivate().

Definition at line 100 of file SceneBase.cpp.

◆ SetActiveCamera()

void Sleak::SceneBase::SetActiveCamera ( Camera * cam)
inline

Definition at line 143 of file SceneBase.hpp.

◆ SetSkybox()

void Sleak::SceneBase::SetSkybox ( Skybox * skybox)

Replaces the scene's skybox, deleting the previous one.

Definition at line 350 of file SceneBase.cpp.

◆ Unload()

void Sleak::SceneBase::Unload ( )

Deactivates if active, calls OnUnload(), and destroys all owned objects.

Definition at line 57 of file SceneBase.cpp.

◆ Update()

void Sleak::SceneBase::Update ( float deltaTime)
pure virtual

Advances all active, root-level objects by deltaTime, then steps lighting and physics.

Implemented in Sleak::Scene.

Definition at line 143 of file SceneBase.cpp.

Member Data Documentation

◆ bActive

bool Sleak::SceneBase::bActive
protected

Definition at line 161 of file SceneBase.hpp.

◆ bInitialized

bool Sleak::SceneBase::bInitialized
protected

Definition at line 160 of file SceneBase.hpp.

◆ m_activeCamera

Camera* Sleak::SceneBase::m_activeCamera = nullptr
protected

Definition at line 166 of file SceneBase.hpp.

◆ m_lightManager

LightManager* Sleak::SceneBase::m_lightManager = nullptr
protected

Definition at line 168 of file SceneBase.hpp.

◆ m_pendingDestroy

List<GameObject*> Sleak::SceneBase::m_pendingDestroy
protected

Definition at line 164 of file SceneBase.hpp.

◆ m_physicsWorld

Physics::PhysicsWorld* Sleak::SceneBase::m_physicsWorld = nullptr
protected

Definition at line 169 of file SceneBase.hpp.

◆ m_skybox

Skybox* Sleak::SceneBase::m_skybox = nullptr
protected

Definition at line 170 of file SceneBase.hpp.

◆ name

std::string Sleak::SceneBase::name
protected

Definition at line 158 of file SceneBase.hpp.

◆ Objects

List<GameObject*> Sleak::SceneBase::Objects
protected

Definition at line 163 of file SceneBase.hpp.

◆ state

SceneState Sleak::SceneBase::state
protected

Definition at line 159 of file SceneBase.hpp.