Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Application.h
Go to the documentation of this file.
1/**
2 * @file Application.h
3 * @ingroup mnd_core
4 * @brief Abstract base class for the user-defined game or lab application.
5 *
6 * ## How to use
7 * 1. Subclass Application and implement Init(), Update(), and Destroy().
8 * 2. Pass an instance to Engine::SetApplication() before calling Engine::Init().
9 * 3. Engine::Run() calls Update() once per frame and stops when
10 * NeedsToBeClosed() returns true or the OS window is closed.
11 *
12 * @code
13 * class Game : public mnd::Application {
14 * public:
15 * bool Init() override { ... return true; }
16 * void Update(float dt) override { ... }
17 * void Destroy() override { ... }
18 * };
19 * @endcode
20 *
21 * @see Engine
22 */
23
24#pragma once
25
26namespace mnd
27{
28
29/**
30 * @brief Interface that every runnable game or lab must implement.
31 *
32 * The Engine singleton owns the Application instance (via std::unique_ptr)
33 * and drives its lifecycle through the three virtual methods below.
34 */
36{
37public:
38 /**
39 * @brief Called once by Engine::Init() after the GL context is ready.
40 * @return true if initialisation succeeded; false aborts startup.
41 */
42 virtual bool Init() = 0;
43
44 virtual void RegisterTypes() = 0;
45
46 /**
47 * @brief Called every frame by Engine::Run() with the elapsed time.
48 * @param deltaTime Seconds since the previous frame. Use this to make
49 * movement and animations frame-rate independent.
50 */
51 virtual void Update(float deltaTime) = 0;
52
53 /**
54 * @brief Called by Engine::Destroy() before the GL context is torn down.
55 * Release GPU resources (meshes, textures, shaders) here.
56 */
57 virtual void Destroy() = 0;
58
59 /**
60 * @brief Request the engine to stop after the current frame.
61 * @param value true to signal shutdown, false to keep running.
62 */
63 void SetNeedsToBeClosed(bool value);
64
65 /**
66 * @brief Returns true when the application has requested shutdown.
67 * Engine::Run() checks this each frame to know when to exit.
68 */
69 [[nodiscard]] bool NeedsToBeClosed() const;
70
71private:
72 bool m_needsToBeClosed = false; ///< Shutdown flag polled by the main loop.
73};
74
75} // namespace mnd
Interface that every runnable game or lab must implement.
Definition Application.h:36
virtual bool Init()=0
Called once by Engine::Init() after the GL context is ready.
bool NeedsToBeClosed() const
Returns true when the application has requested shutdown. Engine::Run() checks this each frame to kno...
virtual void Update(float deltaTime)=0
Called every frame by Engine::Run() with the elapsed time.
void SetNeedsToBeClosed(bool value)
Request the engine to stop after the current frame.
virtual void RegisterTypes()=0
virtual void Destroy()=0
Called by Engine::Destroy() before the GL context is torn down. Release GPU resources (meshes,...