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.
public:
auto* menu = new MenuScene();
auto* world = new WorldScene();
return true;
}
void Loop(
float deltaTime)
override {}
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.
virtual void AddScene(SceneBase *scene)
Registers a scene; the game takes ownership.
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.