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

#include <Scene.hpp>

Inheritance diagram for Sleak::Scene:

Public Member Functions

 Scene (const std::string &name)
 ~Scene () override=default
void Begin () override
 Activates every owned object; runs once after Initialize().
void FixedUpdate (float fixedDeltaTime) override
 Advances all active, root-level objects on the fixed timestep.
bool Initialize () override
 Runs once before the scene's first Begin()/Update().
bool IsFixedUpdateEnabled () const
void LateUpdate (float deltaTime) override
 Advances all active, root-level objects after the main Update pass.
void OnActivate () override
 Override for logic that should run when the scene becomes active.
void OnDeactivate () override
 Override for logic that should run when the scene stops being active.
void OnLoad () override
 Override to load scene-specific assets; called once from Load().
void OnUnload () override
 Override to release scene-specific assets; called from Unload().
void SetFixedUpdateEnabled (bool enabled)
void Update (float deltaTime) override
 Advances all active, root-level objects by deltaTime, then steps lighting and physics.
Public Member Functions inherited from Sleak::SceneBase
 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.
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.
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
bool IsActive () const
bool IsLoaded () const
void Load ()
 Moves Unloaded -> Loading -> Active, calling OnLoad() and Initialize().
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.

Additional Inherited Members

Protected Member Functions inherited from Sleak::SceneBase
void DestroyAllObjects ()
 Destroys every object still owned by the scene, e.g. during Unload().
void ProcessPendingDestroy ()
 Actually deletes objects queued by DestroyObject().
Protected Attributes inherited from Sleak::SceneBase
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

Concrete scene type games subclass. Adds an opt-out switch for the fixed-timestep update on top of SceneBase's lifecycle.

This is the class your levels, menus, and screens derive from. Override the hooks you need and call the base implementation from each one: OnLoad() and OnUnload() for assets, OnActivate() and OnDeactivate() for entering and leaving, Begin() to build the object graph, and Update() / FixedUpdate() / LateUpdate() for per-frame work.

The scene owns every object handed to AddObject(), including lights and cameras, and destroys all of them on unload. It also owns a LightManager and a Physics::PhysicsWorld, reachable through GetLightManager() and GetPhysicsWorld(), and registers added objects with both automatically.

Call SetFixedUpdateEnabled(false) on scenes that do not simulate anything, such as menus, to skip the fixed-timestep pass entirely.

class WorldScene : public Sleak::Scene {
public:
WorldScene() : Sleak::Scene("WorldScene") {}
void Begin() override {
Sleak::Math::Vector3D(0.0f, 0.0f, 0.0f));
AddObject(cube);
auto* sun = new Sleak::DirectionalLight("Sun");
sun->SetDirection(Sleak::Math::Vector3D(-0.5f, -0.8f, -0.3f));
sun->SetIntensity(4.0f);
AddObject(sun);
auto* cam = new Sleak::Camera("MainCamera");
AddObject(cam);
Sleak::Scene::Begin(); // activates everything added above
}
void Update(float deltaTime) override {
}
};
static GameObject * CreateCube(Math::Vector3D position)
void SetActiveCamera(Camera *cam)
virtual void AddObject(GameObject *object)
Takes ownership of object, registering it with lighting and physics as needed.
void Begin() override
Activates every owned object; runs once after Initialize().
Definition Scene.cpp:26
Scene(const std::string &name)
Definition Scene.hpp:58
void Update(float deltaTime) override
Advances all active, root-level objects by deltaTime, then steps lighting and physics.
Definition Scene.cpp:30
Root namespace for everything the engine exposes.
Definition Camera.hpp:10
See also
SceneBase, GameBase, GameObject, LightManager

Definition at line 56 of file Scene.hpp.

Constructor & Destructor Documentation

◆ Scene()

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

Definition at line 58 of file Scene.hpp.

◆ ~Scene()

Sleak::Scene::~Scene ( )
overridedefault

Member Function Documentation

◆ Begin()

void Sleak::Scene::Begin ( )
overridevirtual

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

Implements Sleak::SceneBase.

Definition at line 26 of file Scene.cpp.

◆ FixedUpdate()

void Sleak::Scene::FixedUpdate ( float fixedDeltaTime)
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 34 of file Scene.cpp.

◆ Initialize()

bool Sleak::Scene::Initialize ( )
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 22 of file Scene.cpp.

◆ IsFixedUpdateEnabled()

bool Sleak::Scene::IsFixedUpdateEnabled ( ) const
inline

Definition at line 80 of file Scene.hpp.

◆ LateUpdate()

void Sleak::Scene::LateUpdate ( float deltaTime)
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 39 of file Scene.cpp.

◆ OnActivate()

void Sleak::Scene::OnActivate ( )
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 14 of file Scene.cpp.

◆ OnDeactivate()

void Sleak::Scene::OnDeactivate ( )
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 18 of file Scene.cpp.

◆ OnLoad()

void Sleak::Scene::OnLoad ( )
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 6 of file Scene.cpp.

◆ OnUnload()

void Sleak::Scene::OnUnload ( )
overridevirtual

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

Reimplemented from Sleak::SceneBase.

Definition at line 10 of file Scene.cpp.

◆ SetFixedUpdateEnabled()

void Sleak::Scene::SetFixedUpdateEnabled ( bool enabled)
inline

Definition at line 79 of file Scene.hpp.

◆ Update()

void Sleak::Scene::Update ( float deltaTime)
overridevirtual

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

Implements Sleak::SceneBase.

Definition at line 30 of file Scene.cpp.