Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PlatformContext.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_PLATFORM_CONTEXT_H_
34#define DVD_PLATFORM_CONTEXT_H_
35
36namespace Divide {
37
38class GUI;
39class Kernel;
40class Server;
41class Editor;
42class GFXDevice;
43class SFXDevice;
44class PXDevice;
45class Application;
46class LocalClient;
47class ParamHandler;
48class DisplayWindow;
49
50struct Configuration;
51struct DebugInterface;
52
53namespace Attorney {
54 class PlatformContextKernel;
55};
56
57namespace Input {
58 class InputHandler;
59};
60
61enum class TaskPoolType : U8
62{
63 HIGH_PRIORITY = 0,
67 COUNT
68};
69
70class PlatformContext final : private NonCopyable, private NonMovable
71{
73
74 public:
75 enum class SystemComponentType : U32 {
76 NONE = 0,
77 Application = 1 << 1,
78 GFXDevice = 1 << 2,
79 SFXDevice = 1 << 3,
80 PXDevice = 1 << 4,
81 GUI = 1 << 5,
82 XMLData = 1 << 6,
83 Configuration = 1 << 7,
84 LocalClient = 1 << 8,
85 DebugInterface = 1 << 9,
86 Editor = 1 << 10,
87 InputHandler = 1 << 11,
88 COUNT = 11,
91 };
92
93 public:
96
97 void idle(bool fast = true, U64 deltaTimeUSGame = 0u, U64 deltaTimeUSApp = 0u );
98
99 void init(Kernel& kernel);
100 void terminate();
101
102 [[nodiscard]] Application& app() noexcept { return _app; }
103 [[nodiscard]] const Application& app() const noexcept { return _app; }
104
105 [[nodiscard]] GFXDevice& gfx() noexcept { return *_gfx; }
106 [[nodiscard]] const GFXDevice& gfx() const noexcept { return *_gfx; }
107
108 [[nodiscard]] GUI& gui() noexcept { return *_gui; }
109 [[nodiscard]] const GUI& gui() const noexcept { return *_gui; }
110
111 [[nodiscard]] SFXDevice& sfx() noexcept { return *_sfx; }
112 [[nodiscard]] const SFXDevice& sfx() const noexcept { return *_sfx; }
113
114 [[nodiscard]] PXDevice& pfx() noexcept { return *_pfx; }
115 [[nodiscard]] const PXDevice& pfx() const noexcept { return *_pfx; }
116
117 [[nodiscard]] Configuration& config() noexcept { return *_config; }
118 [[nodiscard]] const Configuration& config() const noexcept { return *_config; }
119
120 [[nodiscard]] LocalClient& client() noexcept { return *_client; }
121 [[nodiscard]] const LocalClient& client() const noexcept { return *_client; }
122
123 [[nodiscard]] Server& server() noexcept { return *_server; }
124 [[nodiscard]] const Server& server() const noexcept { return *_server; }
125
126 [[nodiscard]] DebugInterface& debug() noexcept { return *_debug; }
127 [[nodiscard]] const DebugInterface& debug() const noexcept { return *_debug; }
128
129 [[nodiscard]] Editor& editor() noexcept { return *_editor; }
130 [[nodiscard]] const Editor& editor() const noexcept { return *_editor; }
131
132 [[nodiscard]] TaskPool& taskPool(const TaskPoolType type) noexcept {return *_taskPool[to_base(type)]; }
133 [[nodiscard]] const TaskPool& taskPool(const TaskPoolType type) const noexcept { return *_taskPool[to_base(type)]; }
134
135 [[nodiscard]] Input::InputHandler& input() noexcept { return *_inputHandler; }
136 [[nodiscard]] const Input::InputHandler& input() const noexcept { return *_inputHandler; }
137
138 [[nodiscard]] ParamHandler& paramHandler() noexcept { return *_paramHandler; }
139 [[nodiscard]] const ParamHandler& paramHandler() const noexcept { return *_paramHandler; }
140
141 [[nodiscard]] Kernel& kernel() noexcept;
142 [[nodiscard]] const Kernel& kernel() const noexcept;
143
144 [[nodiscard]] DisplayWindow& mainWindow() noexcept;
145 [[nodiscard]] const DisplayWindow& mainWindow() const noexcept;
146
147 [[nodiscard]] DisplayWindow& activeWindow() noexcept;
148 [[nodiscard]] const DisplayWindow& activeWindow() const noexcept;
149
150 PROPERTY_RW(U32, componentMask, 0u);
151
152 protected:
153 void onThreadCreated(const TaskPoolType type, const std::thread::id& threadID, bool isMainRenderThread) const;
154
155 private:
159 Kernel* _kernel{nullptr};
160
162 std::array<std::unique_ptr<TaskPool>, to_base(TaskPoolType::COUNT)> _taskPool;
164 std::unique_ptr<ParamHandler> _paramHandler;
166 std::unique_ptr<Configuration> _config;
168 std::unique_ptr<DebugInterface> _debug;
170 std::unique_ptr<Input::InputHandler> _inputHandler;
172 std::unique_ptr<GFXDevice> _gfx;
174 std::unique_ptr<GUI> _gui;
176 std::unique_ptr<SFXDevice> _sfx;
178 std::unique_ptr<PXDevice> _pfx;
180 std::unique_ptr<LocalClient> _client;
182 std::unique_ptr<Server> _server;
184 std::unique_ptr<Editor> _editor;
185};
186
187namespace Attorney
188{
190 {
191 static void onThreadCreated(const PlatformContext& context, const TaskPoolType poolType, const std::thread::id& threadID, const bool isMainRenderThread )
192 {
193 context.onThreadCreated(poolType, threadID, isMainRenderThread);
194 }
195
196 friend class Divide::Kernel;
198 };
199}; // namespace Attorney
200
201}; //namespace Divide
202
203#endif //DVD_PLATFORM_CONTEXT_H_
#define PROPERTY_RW(...)
Convenience method to add a class member with public read access and write access.
Class that provides an interface between our framework and the OS (start/stop, display support,...
Definition: Application.h:97
static void onThreadCreated(const PlatformContext &context, const TaskPoolType poolType, const std::thread::id &threadID, const bool isMainRenderThread)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
Graphical User Interface.
Definition: GUI.h:81
The kernel is the main system that connects all of our various systems: windows, gfx,...
Definition: Kernel.h:81
const SFXDevice & sfx() const noexcept
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.
std::unique_ptr< Server > _server
Networking server.
DisplayWindow & activeWindow() noexcept
Application & app() noexcept
Kernel * _kernel
Main app's kernel.
Kernel & kernel() noexcept
const Application & app() const noexcept
const DebugInterface & debug() const noexcept
PXDevice & pfx() noexcept
Editor & editor() noexcept
const LocalClient & client() const noexcept
DebugInterface & debug() noexcept
SFXDevice & sfx() noexcept
const Editor & editor() const noexcept
const Configuration & config() const noexcept
const GFXDevice & gfx() const noexcept
TaskPool & taskPool(const TaskPoolType type) noexcept
Application & _app
Main application instance.
const GUI & gui() const noexcept
const TaskPool & taskPool(const TaskPoolType type) const noexcept
std::unique_ptr< Input::InputHandler > _inputHandler
Input handler.
ParamHandler & paramHandler() noexcept
const ParamHandler & paramHandler() const noexcept
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.
const Input::InputHandler & input() const noexcept
Server & server() noexcept
std::unique_ptr< DebugInterface > _debug
Debugging interface: read only / editable variables.
const Server & server() const noexcept
Input::InputHandler & input() noexcept
void init(Kernel &kernel)
LocalClient & client() noexcept
const PXDevice & pfx() const noexcept
std::unique_ptr< ParamHandler > _paramHandler
Param handler.
std::unique_ptr< Editor > _editor
Game editor.
GFXDevice & gfx() noexcept
void idle(bool fast=true, U64 deltaTimeUSGame=0u, U64 deltaTimeUSApp=0u)
std::unique_ptr< Configuration > _config
User configured settings.
Configuration & config() noexcept
void onThreadCreated(const TaskPoolType type, const std::thread::id &threadID, bool isMainRenderThread) const
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
void PlatformContextIdleCall()
uint8_t U8
uint32_t U32
uint64_t U64
constexpr auto to_base(const Type value) -> Type