Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Application.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_CORE_APPLICATION_H_
34#define DVD_CORE_APPLICATION_H_
35
36#include "WindowManager.h"
38
39namespace Divide {
40
41struct Task;
42struct Configuration;
43struct SizeChangeParams;
44struct DisplayManager;
45
46class Kernel;
47class GL_API;
48class VK_API;
49
50namespace Attorney
51{
54
58};
59
60enum class AppStepResult : U32
61{
62 OK = 0,
63 RESTART,
65 STOP,
67 ERROR,
68 COUNT
69};
70
71
72namespace Names
73{
74 static const char* appStepResult[] = {
75 "OK",
76 "RESTART",
77 "RESTART AND CLEAR CACHE",
78 "STOP",
79 "STOP AND CLEAR CACHE",
80 "ERROR",
81 "UNKNOWN"
82 };
83} //namespace Names
84
85static_assert(std::size( Names::appStepResult ) == to_base( AppStepResult::COUNT ) + 1u, "AppStepResult name array out of sync!");
86
87namespace TypeUtil
88{
89 [[nodiscard]] inline const char* AppStepResultToString( const AppStepResult err ) noexcept
90 {
91 return Names::appStepResult[to_base( err )];
92 }
93}
94
96class Application final : public SDLEventListener
97{
100
101public:
102 Application() noexcept;
103 ~Application() override;
104
105 [[nodiscard]] ErrorCode start(const string& entryPoint, I32 argc, char** argv);
106 void stop( const AppStepResult stepResult );
107 [[nodiscard]] AppStepResult step();
108
109 inline void RequestShutdown( bool clearCache ) noexcept;
110 inline void CancelShutdown() noexcept;
111
112 inline void RequestRestart( bool clearCache ) noexcept;
113 inline void CancelRestart() noexcept;
114
115 [[nodiscard]] inline bool ShutdownRequested() const noexcept;
116 [[nodiscard]] inline bool RestartRequested() const noexcept;
117
118 [[nodiscard]] inline WindowManager& windowManager() noexcept;
119 [[nodiscard]] inline const WindowManager& windowManager() const noexcept;
120
121 [[nodiscard]] bool onWindowSizeChange(const SizeChangeParams& params) const;
122 [[nodiscard]] bool onResolutionChange(const SizeChangeParams& params) const;
123
124 [[nodiscard]] inline ErrorCode errorCode() const noexcept;
125
126 PROPERTY_RW( U8, maxMSAASampleCount, 0u );
127 PROPERTY_R(Time::ApplicationTimer, timer);
128
129 inline bool mainLoopPaused() const { return _mainLoopPaused; }
130 inline bool mainLoopActive() const { return _mainLoopActive; }
131 inline bool freezeRendering() const { return _freezeRendering; }
132
133 [[nodiscard]] Time::ApplicationTimer& timer() noexcept;
134 void mainLoopPaused(const bool state) noexcept;
135 void mainLoopActive(const bool state) noexcept;
136 void freezeRendering(const bool state) noexcept;
137
138protected:
139 bool onProfilerStateChanged(Profiler::State state);
140
141private:
142 [[nodiscard]] ErrorCode setRenderingAPI( const RenderAPI api );
143 [[nodiscard]] bool onSDLEvent( SDL_Event event ) noexcept override;
144
145private:
147
148 std::unique_ptr<Kernel> _kernel;
149
150 std::atomic_bool _requestShutdown{ false };
151 std::atomic_bool _requestRestart{ false };
152 std::atomic_bool _stepLoop{ false };
153 std::atomic_bool _mainLoopPaused{false};
154 std::atomic_bool _mainLoopActive{false};
155 std::atomic_bool _freezeRendering{false};
157 bool _clearCacheOnExit{ false };
158};
159
161
163{
165 {
166 string _formatName{};
170 };
171
175
176 static constexpr U8 g_maxDisplayOutputs = 4u;
177
179
180 [[nodiscard]] static const OutputDisplayPropertiesContainer& GetDisplayModes( const size_t displayIndex ) noexcept;
181 [[nodiscard]] static U8 ActiveDisplayCount() noexcept;
182 [[nodiscard]] static U8 MaxMSAASamples() noexcept;
183
184private:
185 static void MaxMSAASamples( const U8 maxSampleCount ) noexcept;
186 static void SetActiveDisplayCount( const U8 displayCount );
187 static void RegisterDisplayMode( const U8 displayIndex, const OutputDisplayProperties& mode );
188
189 static void Reset() noexcept;
190
191private:
195};
196
197bool operator==( const DisplayManager::OutputDisplayProperties& lhs, const DisplayManager::OutputDisplayProperties& rhs ) noexcept;
198
199namespace Attorney
200{
202 {
203 [[nodiscard]] static ErrorCode SetRenderingAPI( Application& app, const RenderAPI api )
204 {
205 return app.setRenderingAPI(api);
206 }
207
208 friend class Divide::Kernel;
209 };
210
212 {
213 [[nodiscard]] static bool onProfilerStateChanged( Application* app, const Profiler::State state )
214 {
215 return app->onProfilerStateChanged(state);
216 }
217
218 friend bool Profiler::OnProfilerStateChanged( const Profiler::State state);
219 };
220
222 {
223 static void SetActiveDisplayCount( const U8 displayCount )
224 {
226 }
227
228 static void RegisterDisplayMode( const U8 displayIndex, const DisplayManager::OutputDisplayProperties& mode )
229 {
230 DisplayManager::RegisterDisplayMode(displayIndex, mode);
231 }
232
234 };
235
237 {
238 static void MaxMSAASamples( const U8 maxSampleCount ) noexcept
239 {
240 DisplayManager::MaxMSAASamples(maxSampleCount);
241 }
242
243 friend class Divide::GL_API;
244 friend class Divide::VK_API;
245 };
246
248 {
249 static void Reset() noexcept
250 {
252 }
253
255 };
256};
257
258}; // namespace Divide
259
260#endif //DVD_CORE_APPLICATION_H_
261
262#include "Application.inl"
#define PROPERTY_RW(...)
Convenience method to add a class member with public read access and write access.
#define PROPERTY_R(...)
Convenience method to add a class member with public read access but protected write access.
#define FWD_DECLARE_MANAGED_CLASS(T)
char * argv[]
Definition: main.cpp:8
Class that provides an interface between our framework and the OS (start/stop, display support,...
Definition: Application.h:97
bool mainLoopActive() const
Definition: Application.h:130
bool onSDLEvent(SDL_Event event) noexcept override
bool mainLoopPaused() const
Definition: Application.h:129
bool RestartRequested() const noexcept
Definition: Application.inl:72
std::atomic_bool _freezeRendering
Definition: Application.h:155
std::atomic_bool _mainLoopPaused
Definition: Application.h:153
std::unique_ptr< Kernel > _kernel
Definition: Application.h:148
void CancelShutdown() noexcept
Definition: Application.inl:51
std::atomic_bool _stepLoop
Definition: Application.h:152
void stop(const AppStepResult stepResult)
WindowManager & windowManager() noexcept
Definition: Application.inl:77
bool onResolutionChange(const SizeChangeParams &params) const
ErrorCode start(const string &entryPoint, I32 argc, char **argv)
Definition: Application.cpp:30
bool freezeRendering() const
Definition: Application.h:131
void RequestRestart(bool clearCache) noexcept
Definition: Application.inl:61
std::atomic_bool _mainLoopActive
Definition: Application.h:154
ErrorCode _errorCode
Definition: Application.h:156
bool ShutdownRequested() const noexcept
Definition: Application.inl:56
ErrorCode setRenderingAPI(const RenderAPI api)
WindowManager _windowManager
Definition: Application.h:146
bool onProfilerStateChanged(Profiler::State state)
Definition: Application.cpp:74
bool onWindowSizeChange(const SizeChangeParams &params) const
void RequestShutdown(bool clearCache) noexcept
Definition: Application.inl:45
std::atomic_bool _requestShutdown
Definition: Application.h:150
AppStepResult step()
std::atomic_bool _requestRestart
Definition: Application.h:151
void CancelRestart() noexcept
Definition: Application.inl:67
ErrorCode errorCode() const noexcept
Definition: Application.inl:87
Application() noexcept
Definition: Application.cpp:18
Time::ApplicationTimer & timer() noexcept
Definition: Application.inl:92
static ErrorCode SetRenderingAPI(Application &app, const RenderAPI api)
Definition: Application.h:203
static bool onProfilerStateChanged(Application *app, const Profiler::State state)
Definition: Application.h:213
static void MaxMSAASamples(const U8 maxSampleCount) noexcept
Definition: Application.h:238
static void RegisterDisplayMode(const U8 displayIndex, const DisplayManager::OutputDisplayProperties &mode)
Definition: Application.h:228
static void SetActiveDisplayCount(const U8 displayCount)
Definition: Application.h:223
OpenGL implementation of the RenderAPIWrapper.
Definition: GLWrapper.h:65
The kernel is the main system that connects all of our various systems: windows, gfx,...
Definition: Kernel.h:81
static const char * appStepResult[]
Definition: Application.h:74
const char * AppStepResultToString(const AppStepResult err) noexcept
Definition: Application.h:89
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
AppStepResult
Definition: Application.h:61
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
uint32_t U32
constexpr auto to_base(const Type value) -> Type
U8 _maxRefreshRate
As returned by SDL_GetPixelFormatName.
Definition: Application.h:169
vector< OutputDisplayProperties > OutputDisplayPropertiesContainer
Definition: Application.h:178
static void SetActiveDisplayCount(const U8 displayCount)
static U8 ActiveDisplayCount() noexcept
static void RegisterDisplayMode(const U8 displayIndex, const OutputDisplayProperties &mode)
static U8 MaxMSAASamples() noexcept
static U8 s_activeDisplayCount
Definition: Application.h:192
static const OutputDisplayPropertiesContainer & GetDisplayModes(const size_t displayIndex) noexcept
static std::array< OutputDisplayPropertiesContainer, g_maxDisplayOutputs > s_supportedDisplayModes
Definition: Application.h:194
static constexpr U8 g_maxDisplayOutputs
Definition: Application.h:176
static U8 s_maxMSAASAmples
Definition: Application.h:193
static void Reset() noexcept