Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Kernel.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_KERNEL_H_
34#define DVD_CORE_KERNEL_H_
35
36#include "PlatformContext.h"
37#include "LoopTimingData.h"
41
42namespace Divide {
43
44class Scene;
45class Editor;
46class PXDevice;
47class GFXDevice;
48class SFXDevice;
49class GUISplash;
50class Application;
51class ProjectManager;
52class PlatformContext;
53class SceneRenderState;
54class RenderPassManager;
55
56namespace Input
57{
58 struct MouseState;
59 class InputInterface;
60};
61
62enum class RenderStage : U8;
63
64struct FrameEvent;
65struct DebugInterface;
66
67
68namespace Attorney {
69 class KernelApplication;
70 class KernelWindowManager;
71 class KernelDebugInterface;
72};
73
74namespace Time {
75 class ProfileTimer;
76};
77
81{
85
86 public:
87 Kernel(I32 argc, char** argv, Application& parentApp);
88 ~Kernel() override;
89
91 void onLoop();
94 void idle(bool fast, U64 deltaTimeUSGame, U64 deltaTimeUSApp );
95
97 bool onKeyDown(const Input::KeyEvent& key) override;
99 bool onKeyUp(const Input::KeyEvent& key) override;
101 bool joystickAxisMoved(const Input::JoystickEvent& arg) override;
103 bool joystickPovMoved(const Input::JoystickEvent& arg) override;
105 bool joystickButtonPressed(const Input::JoystickEvent& arg) override;
107 bool joystickButtonReleased(const Input::JoystickEvent& arg) override;
108 bool joystickBallMoved(const Input::JoystickEvent& arg) override;
109 bool joystickAddRemove(const Input::JoystickEvent& arg) override;
110 bool joystickRemap(const Input::JoystickEvent &arg) override;
112 bool mouseMoved(const Input::MouseMoveEvent& arg) override;
114 bool mouseButtonPressed(const Input::MouseButtonEvent& arg) override;
116 bool mouseButtonReleased(const Input::MouseButtonEvent& arg) override;
118 bool onTextEvent(const Input::TextEvent& arg) override;
119
121 PROPERTY_RW(bool, keepAlive, true);
122 PROPERTY_R(std::unique_ptr<ProjectManager>, projectManager);
123 PROPERTY_R(std::unique_ptr<RenderPassManager>, renderPassManager);
124
127
128 FORCE_INLINE FrameListenerManager& frameListenerMgr() noexcept { return _frameListenerMgr; }
129 FORCE_INLINE PlatformContext& platformContext() noexcept { return _platformContext; }
130
131 static size_t TotalThreadCount(TaskPoolType type) noexcept;
132
133 private:
134 ErrorCode initialize(const string& entryPoint);
135 void warmup();
136 void shutdown();
137 void startSplashScreen();
138 void stopSplashScreen();
139 bool mainLoopScene(FrameEvent& evt);
140 bool presentToScreen(FrameEvent& evt);
141
142 void onWindowSizeChange(const SizeChangeParams& params);
143 void onResolutionChange(const SizeChangeParams& params);
144
145 void remapAbsolutePosition(Input::MouseEvent& eventInOut) const noexcept;
146
147 private:
148 enum class InputConsumerType : U8 {
149 Editor,
150 GUI,
151 Scene,
152 COUNT
153 };
154
155 std::array<InputAggregatorInterface*, to_base(InputConsumerType::COUNT)> _inputConsumers{};
156
158
171
172 std::atomic_bool _splashScreenUpdating{};
173 std::unique_ptr<GUISplash> _splashScreen;
174
175 // Command line arguments
177 char** _argv;
178
179 Rect<I32> _prevViewport = { -1, -1, -1, -1 };
181};
182
183namespace Attorney {
185 static ErrorCode initialize(Kernel* kernel, const string& entryPoint) {
186 return kernel->initialize(entryPoint);
187 }
188
189 static void shutdown(Kernel* kernel) {
190 kernel->shutdown();
191 }
192
193 static void onWindowSizeChange(Kernel* kernel, const SizeChangeParams& params) {
194 kernel->onWindowSizeChange(params);
195 }
196
197 static void onResolutionChange(Kernel* kernel, const SizeChangeParams& params) {
198 kernel->onResolutionChange(params);
199 }
200
201 static void warmup(Kernel* kernel) {
202 kernel->warmup();
203 }
204
205 static void onLoop(Kernel* kernel) {
206 kernel->onLoop();
207 }
208
210 };
211
213 static const LoopTimingData& timingData(const Kernel& kernel) noexcept {
214 return kernel._timingData;
215 }
216
218 };
219};
220
221}; // namespace Divide
222
223#endif //DVD_CORE_KERNEL_H_
#define FORCE_INLINE
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
static void onResolutionChange(Kernel *kernel, const SizeChangeParams &params)
Definition: Kernel.h:197
static ErrorCode initialize(Kernel *kernel, const string &entryPoint)
Definition: Kernel.h:185
static void onLoop(Kernel *kernel)
Definition: Kernel.h:205
static void shutdown(Kernel *kernel)
Definition: Kernel.h:189
static void onWindowSizeChange(Kernel *kernel, const SizeChangeParams &params)
Definition: Kernel.h:193
static void warmup(Kernel *kernel)
Definition: Kernel.h:201
static const LoopTimingData & timingData(const Kernel &kernel) noexcept
Definition: Kernel.h:213
The kernel is the main system that connects all of our various systems: windows, gfx,...
Definition: Kernel.h:81
U8 _prevPlayerCount
Definition: Kernel.h:180
bool joystickAddRemove(const Input::JoystickEvent &arg) override
Definition: Kernel.cpp:1156
~Kernel() override
Definition: Kernel.cpp:107
bool joystickAxisMoved(const Input::JoystickEvent &arg) override
Joystick axis change.
Definition: Kernel.cpp:1106
PROPERTY_R(std::unique_ptr< ProjectManager >, projectManager)
void warmup()
Definition: Kernel.cpp:642
void startSplashScreen()
Definition: Kernel.cpp:112
ErrorCode initialize(const string &entryPoint)
Definition: Kernel.cpp:662
char ** _argv
Definition: Kernel.h:177
FORCE_INLINE PlatformContext & platformContext() noexcept
Definition: Kernel.h:129
PROPERTY_R(std::unique_ptr< RenderPassManager >, renderPassManager)
Time::ProfileTimer & _frameTimer
Definition: Kernel.h:161
Time::ProfileTimer & _postRenderTimer
Definition: Kernel.h:169
bool onTextEvent(const Input::TextEvent &arg) override
Generated by text events (e.g. for SDL: SDL_TEXTEDITING and SDL_TEXTINPUT)
Definition: Kernel.cpp:1176
bool mouseButtonReleased(const Input::MouseButtonEvent &arg) override
Mouse button released.
Definition: Kernel.cpp:1064
bool joystickRemap(const Input::JoystickEvent &arg) override
Definition: Kernel.cpp:1166
bool mouseMoved(const Input::MouseMoveEvent &arg) override
Mouse moved.
Definition: Kernel.cpp:1019
Time::ProfileTimer & _sceneUpdateLoopTimer
Definition: Kernel.h:165
bool joystickPovMoved(const Input::JoystickEvent &arg) override
Joystick direction change.
Definition: Kernel.cpp:1116
bool onKeyUp(const Input::KeyEvent &key) override
Key released.
Definition: Kernel.cpp:1096
void onWindowSizeChange(const SizeChangeParams &params)
Definition: Kernel.cpp:969
void shutdown()
Definition: Kernel.cpp:934
Time::ProfileTimer & _sceneUpdateTimer
Definition: Kernel.h:164
bool presentToScreen(FrameEvent &evt)
Definition: Kernel.cpp:572
Time::ProfileTimer & _appScenePass
Definition: Kernel.h:163
static size_t TotalThreadCount(TaskPoolType type) noexcept
Definition: Kernel.cpp:51
bool onKeyDown(const Input::KeyEvent &key) override
Key pressed.
Definition: Kernel.cpp:1086
Time::ProfileTimer & _cameraMgrTimer
Definition: Kernel.h:166
friend class Attorney::KernelWindowManager
Definition: Kernel.h:83
bool joystickButtonPressed(const Input::JoystickEvent &arg) override
Joystick button pressed.
Definition: Kernel.cpp:1126
Time::ProfileTimer & _appIdleTimer
Definition: Kernel.h:162
Time::ProfileTimer & _appLoopTimerInternal
Definition: Kernel.h:160
void onLoop()
Our main application rendering loop: Call input requests, physics calculations, pre-rendering,...
Definition: Kernel.cpp:181
PROPERTY_R(PlatformContext, platformContext)
std::array< InputAggregatorInterface *, to_base(InputConsumerType::COUNT)> _inputConsumers
Definition: Kernel.h:155
PROPERTY_R(FrameListenerManager, frameListenerMgr)
bool mouseButtonPressed(const Input::MouseButtonEvent &arg) override
Mouse button pressed.
Definition: Kernel.cpp:1042
void remapAbsolutePosition(Input::MouseEvent &eventInOut) const noexcept
Definition: Kernel.cpp:992
bool joystickButtonReleased(const Input::JoystickEvent &arg) override
Joystick button released.
Definition: Kernel.cpp:1136
Time::ProfileTimer & _flushToScreenTimer
Definition: Kernel.h:167
Time::ProfileTimer & _preRenderTimer
Definition: Kernel.h:168
std::unique_ptr< GUISplash > _splashScreen
Definition: Kernel.h:173
PROPERTY_RW(LoopTimingData, timingData)
PROPERTY_RW(bool, keepAlive, true)
bool mainLoopScene(FrameEvent &evt)
Definition: Kernel.cpp:344
FORCE_INLINE FrameListenerManager & frameListenerMgr() noexcept
Definition: Kernel.h:128
Time::ProfileTimer & _appLoopTimerMain
Definition: Kernel.h:159
bool joystickBallMoved(const Input::JoystickEvent &arg) override
Definition: Kernel.cpp:1146
void idle(bool fast, U64 deltaTimeUSGame, U64 deltaTimeUSApp)
Definition: Kernel.cpp:154
void stopSplashScreen()
Definition: Kernel.cpp:134
vector< Rect< I32 > > _targetViewports
Definition: Kernel.h:157
void onResolutionChange(const SizeChangeParams &params)
Definition: Kernel.cpp:977
vector< Time::ProfileTimer * > _renderTimer
Definition: Kernel.h:170
std::atomic_bool _splashScreenUpdating
Definition: Kernel.h:172
Rect< I32 > _prevViewport
Definition: Kernel.h:179
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
uint64_t U64
constexpr auto to_base(const Type value) -> Type