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

#include <GameBase.hpp>

Public Member Functions

virtual ~GameBase ()
virtual void AddScene (SceneBase *scene)
 Registers a scene; the game takes ownership.
virtual void Begin ()=0
 Called once after Initialize(), before the first Loop().
virtual SceneBaseGetActiveScene ()
virtual bool GetIsGameRunning ()=0
virtual bool Initialize ()=0
 One-time setup before the loop starts. Return false to abort the run.
virtual void Loop (float DeltaTime)=0
 Per-frame update, called after the active scene's own update.
virtual void RemoveScene (SceneBase *scene)
 Unloads, destroys, and drops a scene from the registry.
virtual void SetActiveScene (int index)
 Activates the scene at the given index in the registry.
virtual void SetActiveScene (SceneBase *scene)
 Deactivates the current scene and activates the given one.

Protected Attributes

SceneBaseActiveScene = nullptr
Sleak::List< Sleak::SceneBase * > Scenes

Detailed Description

Base class the game's top-level object derives from. Owns the scene list and the currently active scene; Application drives it each frame.

This is the root of your game. Subclass it, register your scenes in Initialize(), and hand an instance to Application::Run(). Three methods are pure virtual and must be implemented: Initialize() for one-time setup (return false to abort the run), Begin() for work that needs the first scene already active, and Loop() for per-frame logic that is not tied to any single scene.

GameBase owns every scene passed to AddScene() and unloads and deletes all of them in its destructor. Never delete a registered scene yourself; call RemoveScene() instead. When swapping scenes at runtime, call Application::WaitGPUIdle() first so the GPU is not still reading resources you are about to free.

class SLEAK_API Game : public Sleak::GameBase {
public:
bool Initialize() override {
auto* menu = new MenuScene();
auto* world = new WorldScene();
AddScene(menu);
AddScene(world);
return true;
}
void Begin() override {}
void Loop(float deltaTime) override {}
bool GetIsGameRunning() override { return bIsGameRunning; }
private:
bool bIsGameRunning = true;
};
void SetVSync(bool enabled)
static Application * GetInstance()
The one Application for this process, or null before construction.
virtual void Loop(float DeltaTime)=0
Per-frame update, called after the active scene's own update.
virtual bool GetIsGameRunning()=0
virtual bool Initialize()=0
One-time setup before the loop starts. Return false to abort the run.
virtual void SetActiveScene(SceneBase *scene)
Deactivates the current scene and activates the given one.
Definition GameBase.hpp:93
virtual void AddScene(SceneBase *scene)
Registers a scene; the game takes ownership.
Definition GameBase.hpp:74
virtual void Begin()=0
Called once after Initialize(), before the first Loop().
See also
Application, Scene, SceneBase

Definition at line 51 of file GameBase.hpp.

Constructor & Destructor Documentation

◆ ~GameBase()

virtual Sleak::GameBase::~GameBase ( )
inlinevirtual

Definition at line 53 of file GameBase.hpp.

Member Function Documentation

◆ AddScene()

virtual void Sleak::GameBase::AddScene ( SceneBase * scene)
inlinevirtual

Registers a scene; the game takes ownership.

Definition at line 74 of file GameBase.hpp.

◆ Begin()

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

Called once after Initialize(), before the first Loop().

◆ GetActiveScene()

virtual SceneBase * Sleak::GameBase::GetActiveScene ( )
inlinevirtual

Definition at line 105 of file GameBase.hpp.

◆ GetIsGameRunning()

virtual bool Sleak::GameBase::GetIsGameRunning ( )
pure virtual

◆ Initialize()

virtual bool Sleak::GameBase::Initialize ( )
pure virtual

One-time setup before the loop starts. Return false to abort the run.

◆ Loop()

virtual void Sleak::GameBase::Loop ( float DeltaTime)
pure virtual

Per-frame update, called after the active scene's own update.

◆ RemoveScene()

virtual void Sleak::GameBase::RemoveScene ( SceneBase * scene)
inlinevirtual

Unloads, destroys, and drops a scene from the registry.

Definition at line 79 of file GameBase.hpp.

◆ SetActiveScene() [1/2]

virtual void Sleak::GameBase::SetActiveScene ( int index)
inlinevirtual

Activates the scene at the given index in the registry.

Definition at line 101 of file GameBase.hpp.

◆ SetActiveScene() [2/2]

virtual void Sleak::GameBase::SetActiveScene ( SceneBase * scene)
inlinevirtual

Deactivates the current scene and activates the given one.

Definition at line 93 of file GameBase.hpp.

Member Data Documentation

◆ ActiveScene

SceneBase* Sleak::GameBase::ActiveScene = nullptr
protected

Definition at line 109 of file GameBase.hpp.

◆ Scenes

Sleak::List<Sleak::SceneBase*> Sleak::GameBase::Scenes
protected

Definition at line 108 of file GameBase.hpp.