Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
application.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/audio/audio.h"
6#include "flint/core/api.h"
7#include "flint/core/asset-loader.h"
8#include "flint/core/config.h"
9#include "flint/core/state.h"
10#include "flint/resource/assets-manager.h"
11#include "flint/ui/ui-canvas.h"
12#include "flint/ui/ui-system.h"
13#include "flint/window/IWindow.h"
14
15#include <memory>
16#include <string>
17
18namespace Flint {
19 namespace Internal {
20 class CodeHotReloadHost;
21 }
22
23 class GPURenderer;
24
29 public:
39 FLINT_API Application(const FlintConfig &config, IAssetLoader *assetLoader = nullptr);
40
41 FLINT_API Application(const FlintConfig &config, IAssetLoader &assetLoader)
42 : Application(config, &assetLoader) {
43 }
44
45 virtual FLINT_API ~Application();
46 FLINT_API void run();
47
50 return *m_window;
51 }
52
55 return *m_gpuRenderer;
56 }
57
60 return m_uiSystem;
61 }
62
65 return *m_uiCanvas;
66 }
67
68 FLINT_API std::string loadUIContent(const std::string &filePath);
69
72 return m_stateManager;
73 }
74
77 return m_audioEngine;
78 }
79
82 return *m_assetLoader;
83 }
84
85 AssetManager &getAssetManager() {
86 return *m_assetManager;
87 }
88
89 const AssetManager &getAssetManager() const {
90 return *m_assetManager;
91 }
92
93 const FlintConfig &getConfig() const {
94 return m_config;
95 }
96
97 virtual FLINT_API void close();
98
99 protected:
107 virtual std::unique_ptr<State> createInitialState() = 0;
108
114 virtual void onInit() {
115 }
116
117 virtual void onUpdate(float deltaTime) {
118 (void)deltaTime;
119 }
120
126 virtual void onShutdown() {
127 }
128
129 private:
130 void init();
131 void setupGlobalEvents();
132 void updateDisplayScale();
133
134 void initializeCodeHotReload();
135 void updateCodeHotReload();
136 void shutdownCodeHotReload();
137
138 SDL_GPUPresentMode getPresentMode(GRAPHICS_PRESENT_MODE presentMode);
139
140 FlintConfig m_config;
141 GRAPHICS_BACKEND m_backend;
142 std::unique_ptr<IAssetLoader> m_ownedAssetLoader;
143 IAssetLoader *m_assetLoader;
144 std::unique_ptr<IWindow> m_window;
145 Audio m_audioEngine;
146 std::unique_ptr<GPURenderer> m_gpuRenderer;
147 std::unique_ptr<AssetManager> m_assetManager;
148 UISystem m_uiSystem;
149 std::unique_ptr<UICanvas> m_uiCanvas;
150 StateManager m_stateManager;
151 bool m_minimized = false;
152
153 std::unique_ptr<Internal::CodeHotReloadHost> m_codeHotReloadHost;
154 };
155}
Entry-point base class for a Flint application.
Definition application.h:28
StateManager & getStateManager()
returns A reference to the state manager.
Definition application.h:71
IAssetLoader & getAssetLoader()
returns A reference to the asset loader
Definition application.h:81
UICanvas & getUICanvas()
Returns the UI renderer.
Definition application.h:64
virtual std::unique_ptr< State > createInitialState()=0
Factory method that creates the game state pushed into the stack.
IWindow & getWindow()
returns A window reference.
Definition application.h:49
UISystem & getUISystem()
Returns the UI system.
Definition application.h:59
virtual void onInit()
Optional hook called after engine is fully initialized.
GPURenderer & getRenderer() const
returns A reference to the GPU renderer.
Definition application.h:54
virtual void onShutdown()
Optional hook called just before the engine shuts down.
Audio & getAudioEngine()
returns A reference to the audio engine.
Definition application.h:76
FLINT_API Application(const FlintConfig &config, IAssetLoader *assetLoader=nullptr)
Construct and initialize a Flint application.
Central resource cache and hot-reload coordinator.
Manages audio playback via SDL3_mixer.
Definition audio.h:20
High-level SDL GPU renderer managing pipeline state, batching, and frame presentation.
Definition renderer.h:40
Abstract interface for loading raw asset data by path.
Abstract interface for a platform window.
Definition IWindow.h:27
Manages a stack of States and applies queued transitions.
Definition state.h:77
Dynamic 2D batching engine processing shape vector geometry and hardware-accelerated text strings....
Definition ui-canvas.h:107
Central gateway subsystem managing UI multi-context lifetimes, resolution scaling,...
Definition ui-system.h:25
Aggregate configuration passed to the engine bootstrap code.
Definition config.h:141