Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PlatformContext.cpp
Go to the documentation of this file.
1
2
5
9
14#include "GUI/Headers/GUI.h"
20
21namespace Divide {
22
24 : _app(app)
25 , _paramHandler(std::make_unique<ParamHandler>())
26 , _config(std::make_unique<Configuration>())
27 , _debug(std::make_unique<DebugInterface>())
28 , _server(std::make_unique<Server>())
29{
30 const char* taskPoolNames[] =
31 {
32 "WORKER_THREAD",
33 "BACKUP_THREAD",
34 "RENDERER",
35 "ASSET_LOADER"
36 };
37
38 static_assert(std::size(taskPoolNames) == to_base(TaskPoolType::COUNT));
39
40 for ( U8 i = 0u; i < to_U8( TaskPoolType::COUNT ); ++i )
41 {
42 _taskPool[i] = std::make_unique<TaskPool>(taskPoolNames[i]);
43 }
44}
45
47{
48 assert(_gfx == nullptr);
49}
50
52{
53 assert(_gfx == nullptr);
54
55 _kernel = &kernel;
56
57 _inputHandler = std::make_unique<Input::InputHandler>( kernel, _app );
58 _gfx = std::make_unique<GFXDevice>(*this);
59 _sfx = std::make_unique<SFXDevice>(*this);
60 _pfx = std::make_unique<PXDevice>(*this);
61 _gui = std::make_unique<GUI>( kernel );
62 _client = std::make_unique<LocalClient>( kernel );
63 _editor = (Config::Build::ENABLE_EDITOR ? std::make_unique<Editor>(*this) : nullptr);
64}
65
67{
68 _editor.reset();
69 _client.reset();
70 _gui.reset();
71 _pfx.reset();
72 _sfx.reset();
73 _gfx.reset();
74 _inputHandler.reset();
75}
76
77void PlatformContext::idle(const bool fast, const U64 deltaTimeUSGame, const U64 deltaTimeUSApp )
78{
80
81 if (componentMask() & to_base(SystemComponentType::GFXDevice))
82 {
83 _gfx->idle(fast, deltaTimeUSGame, deltaTimeUSApp );
84 }
85
86 if (componentMask() & to_base(SystemComponentType::SFXDevice))
87 {
88 _sfx->idle();
89 }
90
91 if (componentMask() & to_base(SystemComponentType::PXDevice))
92 {
93 _pfx->idle();
94 }
95
96 if (componentMask() & to_base(SystemComponentType::DebugInterface))
97 {
98 _debug->idle(*this);
99 }
100
101 if constexpr(Config::Build::ENABLE_EDITOR)
102 {
103 if (componentMask() & to_base(SystemComponentType::Editor))
104 {
105 _editor->idle();
106 }
107 }
108
109 for (U8 i = 0u; i < to_U8( TaskPoolType::COUNT ); ++i)
110 {
111 _taskPool[i]->flushCallbackQueue();
112 }
113}
114
116{
117 return *app().windowManager().mainWindow();
118}
119
121{
122 return *app().windowManager().mainWindow();
123}
124
126{
127 return *app().windowManager().activeWindow();
128}
129
131{
132 return *app().windowManager().activeWindow();
133}
134
136{
137 assert( _kernel != nullptr );
138 return *_kernel;
139}
140
141const Kernel& PlatformContext::kernel() const noexcept
142{
143 assert(_kernel != nullptr);
144 return *_kernel;
145}
146
147void PlatformContext::onThreadCreated(const TaskPoolType poolType, const std::thread::id& threadID, bool isMainRenderThread ) const
148{
149 if ( poolType == TaskPoolType::ASSET_LOADER ||
150 poolType == TaskPoolType::RENDERER )
151 {
152 _gfx->onThreadCreated(threadID, isMainRenderThread);
153
154 if ( poolType == TaskPoolType::ASSET_LOADER )
155 {
156 ShaderProgram::OnThreadCreated(*_gfx, threadID, isMainRenderThread);
157 }
158 }
159}
160
161}; //namespace Divide
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
Class that provides an interface between our framework and the OS (start/stop, display support,...
Definition: Application.h:97
WindowManager & windowManager() noexcept
Definition: Application.inl:77
The kernel is the main system that connects all of our various systems: windows, gfx,...
Definition: Kernel.h:81
std::unique_ptr< GFXDevice > _gfx
Access to the GPU.
std::unique_ptr< SFXDevice > _sfx
Access to the audio device.
DisplayWindow & mainWindow() noexcept
std::unique_ptr< GUI > _gui
The graphical user interface.
DisplayWindow & activeWindow() noexcept
Application & app() noexcept
Kernel * _kernel
Main app's kernel.
Kernel & kernel() noexcept
Application & _app
Main application instance.
std::unique_ptr< Input::InputHandler > _inputHandler
Input handler.
std::unique_ptr< PXDevice > _pfx
Access to the physics system.
std::array< std::unique_ptr< TaskPool >, to_base(TaskPoolType::COUNT)> _taskPool
Task pools.
std::unique_ptr< LocalClient > _client
Networking client.
std::unique_ptr< DebugInterface > _debug
Debugging interface: read only / editable variables.
void init(Kernel &kernel)
std::unique_ptr< Editor > _editor
Game editor.
void idle(bool fast=true, U64 deltaTimeUSGame=0u, U64 deltaTimeUSApp=0u)
PlatformContext(Application &app)
void onThreadCreated(const TaskPoolType type, const std::thread::id &threadID, bool isMainRenderThread) const
static void OnThreadCreated(const GFXDevice &gfx, const std::thread::id &threadID, bool isMainRenderThread)
DisplayWindow * activeWindow() const noexcept
constexpr bool ENABLE_EDITOR
Definition: config.h:66
constexpr Optick::Category::Type IO
Definition: Profiler.h:68
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
constexpr U8 to_U8(const T value)
uint64_t U64
constexpr auto to_base(const Type value) -> Type