Berserk
Engine.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of Berserk Engine project */
3 /* https://github.com/EgorOrachyov/Berserk */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2018 - 2021 Egor Orachyov */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef BERSERK_ENGINE_HPP
29 #define BERSERK_ENGINE_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/EventDispatcher.hpp>
33 #include <core/Scheduler.hpp>
34 #include <core/Thread.hpp>
35 #include <core/io/Config.hpp>
36 #include <platform/FileSystem.hpp>
37 #include <platform/Input.hpp>
38 #include <platform/Output.hpp>
40 #include <render/RenderEngine.hpp>
42 #include <rhi/RHIDevice.hpp>
43 
44 #include <atomic>
45 #include <chrono>
46 #include <memory>
47 #include <thread>
48 
50 
72 class Engine final {
73 public:
74  BRK_API Engine() = default;
75  BRK_API ~Engine();
76 
81  BRK_API void RequestClose();
82 
87  BRK_API bool CloseRequested();
88 
90  BRK_API const Config &GetConfig();
91 
94 
97 
100 
103 
106 
109 
112 
115 
118 
121 
123  BRK_API std::thread::id GetGameThreadId() const;
124 
126  BRK_API float GetDeltaTime() const;
127 
129  BRK_API float GetTime() const;
130 
132  BRK_API static Engine &Instance();
133 
134 private:
135  friend class Application;
136 
137  void InitCore();
138  void InitEngine();
139  void ConfigureWindow();
140  void SetWindowManager(std::shared_ptr<WindowManager> windowManager);
141  void SetInput(std::shared_ptr<Input> input);
142  void SetRHIDevice(std::shared_ptr<RHIDevice> device);
143  void SetRHIThread(std::shared_ptr<Thread> thread);
144  void Update(float t, float dt);
145 
146 private:
147  Config mConfig;
149  std::unique_ptr<Output> mOutput;
150  std::unique_ptr<FileSystem> mFileSystem;
151  std::unique_ptr<Scheduler> mScheduler;
152  std::unique_ptr<EventDispatcher> mEventDispatcher;
154  std::shared_ptr<WindowManager> mWindowManager;
155  std::shared_ptr<Input> mInput;
156  std::shared_ptr<RHIDevice> mRHIDevice;
157  std::shared_ptr<Thread> mRHIThread;
159  std::unique_ptr<RenderEngine> mRenderEngine;
160  std::unique_ptr<ResourceManager> mResourceManager;
162  std::thread::id mGameThreadID;
163  std::atomic_bool mCloseRequested{false};
165  float mDt = 0.0f;
166  float mT = 0.0f;
169  static Engine *gEngine;
170 };
171 
177 
178 #endif//BERSERK_ENGINE_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
Game application main class.
Definition: Application.hpp:63
Key-values based config file in plist style.
Definition: Config.hpp:49
Root manager class.
Definition: Engine.hpp:72
static BRK_API Engine & Instance()
Return engine global instance.
Definition: Engine.cpp:115
BRK_API Output & GetOutput()
Definition: Engine.cpp:63
BRK_API Scheduler & GetScheduler()
Definition: Engine.cpp:71
BRK_API ~Engine()
Definition: Engine.cpp:34
BRK_API FileSystem & GetFileSystem()
Definition: Engine.cpp:67
BRK_API bool CloseRequested()
Check if close of the application is requested.
Definition: Engine.cpp:55
BRK_API Engine()=default
BRK_API float GetTime() const
Definition: Engine.cpp:111
BRK_API float GetDeltaTime() const
Definition: Engine.cpp:107
BRK_API const Config & GetConfig()
Definition: Engine.cpp:59
BRK_API Input & GetInput()
Definition: Engine.cpp:83
BRK_API RHIDevice & GetRHIDevice()
Definition: Engine.cpp:87
BRK_API ResourceManager & GetResourceManager()
Definition: Engine.cpp:99
BRK_API Thread & GetRHIThread()
Definition: Engine.cpp:91
BRK_API RenderEngine & GetRenderEngine()
Definition: Engine.cpp:95
BRK_API std::thread::id GetGameThreadId() const
Definition: Engine.cpp:103
BRK_API EventDispatcher & GetEventDispatcher()
Definition: Engine.cpp:75
BRK_API void RequestClose()
Request close of the application Call this function to request close and application shut-down.
Definition: Engine.cpp:51
BRK_API WindowManager & GetWindowManager()
Definition: Engine.cpp:79
Event dispatcher is responsible for managing engine events.
Definition: EventDispatcher.hpp:58
Target platform file system access and file utils.
Definition: FileSystem.hpp:53
Engine input manager.
Definition: Input.hpp:48
Unified console output for utf-8 text.
Definition: Output.hpp:41
RHI device.
Definition: RHIDevice.hpp:67
Main rendering engine class.
Definition: RenderEngine.hpp:50
Main engine resource management class.
Definition: ResourceManager.hpp:59
Scheduler is responsible for triggering the scheduled callbacks.
Definition: Scheduler.hpp:59
Represents thread wrapper used to enqueue commands to execute.
Definition: Thread.hpp:54
Manager for OS windows.
Definition: WindowManager.hpp:47
Definition: GLDevice.cpp:46