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#include "flint/audio/audio.h"
5#include "flint/core/asset-loader.h"
6#include "flint/core/config.h"
7#include "flint/core/state.h"
8#include "flint/resource/assets-manager.h"
9#include "flint/ui/ui-canvas.h"
10#include "flint/ui/ui-system.h"
11#include "flint/window/IWindow.h"
12
13#include <memory>
14#include <string>
15
16namespace Flint {
17 class GPURenderer;
18
23 public:
33 Application(const FlintConfig &config, IAssetLoader *assetLoader = nullptr);
34
35 Application(const FlintConfig &config, IAssetLoader &assetLoader)
36 : Application(config, &assetLoader) {
37 }
38
39 virtual ~Application();
40 void run();
41
44 return *m_window;
45 }
46
49 return *m_gpuRenderer;
50 }
51
54 return m_uiSystem;
55 }
56
59 return *m_uiCanvas;
60 }
61
62 std::string loadUIContent(const std::string &filePath);
63
66 return m_stateManager;
67 }
68
71 return m_audioEngine;
72 }
73
76 return *m_assetLoader;
77 }
78
79 AssetManager &getAssetManager() {
80 return *m_assetManager;
81 }
82
83 const AssetManager &getAssetManager() const {
84 return *m_assetManager;
85 }
86
87 const FlintConfig &getConfig() const {
88 return m_config;
89 }
90
91 virtual void close();
92
93 protected:
101 virtual std::unique_ptr<State> createInitialState() = 0;
102
108 virtual void onInit() {
109 }
110
116 virtual void onShutdown() {
117 }
118
119 private:
120 void init();
121 void setupGlobalEvents();
122 void updateDisplayScale();
123
124 SDL_GPUPresentMode getPresentMode(GRAPHICS_PRESENT_MODE presentMode);
125
126 FlintConfig m_config;
127 GRAPHICS_BACKEND m_backend;
128 std::unique_ptr<IAssetLoader> m_ownedAssetLoader;
129 IAssetLoader *m_assetLoader;
130 std::unique_ptr<IWindow> m_window;
131 Audio m_audioEngine;
132 std::unique_ptr<GPURenderer> m_gpuRenderer;
133 std::unique_ptr<AssetManager> m_assetManager;
134 UISystem m_uiSystem;
135 std::unique_ptr<UICanvas> m_uiCanvas;
136 StateManager m_stateManager;
137 bool m_minimized = false;
138 };
139}
StateManager & getStateManager()
returns A reference to the state manager.
Definition application.h:65
IAssetLoader & getAssetLoader()
returns A reference to the asset loader
Definition application.h:75
UICanvas & getUICanvas()
Returns the UI renderer.
Definition application.h:58
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:43
UISystem & getUISystem()
Returns the UI system.
Definition application.h:53
virtual void onInit()
Optional hook called after engine is fully initialized.
GPURenderer & getRenderer() const
returns A reference to the GPU renderer.
Definition application.h:48
Application(const FlintConfig &config, IAssetLoader *assetLoader=nullptr)
Construct and initialize a Flint application.
virtual void onShutdown()
Optional hook called just before the engine shuts down.
Audio & getAudioEngine()
returns A reference to the audio engine.
Definition application.h:70
Entry-point base class for a Flint application.
Definition application.h:22
Central resource cache and hot-reload coordinator.
Manages audio playback via SDL3_mixer.
Definition audio.h:18
High-level SDL GPU renderer managing pipeline state, batching, and frame presentation.
Definition renderer.h:39
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:72
Dynamic 2D batching engine processing shape vector geometry and hardware-accelerated text strings....
Definition ui-canvas.h:106
Central gateway subsystem managing UI multi-context lifetimes, resolution scaling,...
Definition ui-system.h:24
Aggregate configuration passed to the engine bootstrap code.
Definition config.h:131