Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
EngineCore.hpp
1#pragma once
2
3#include <filesystem>
4#include <functional>
5#include <chrono>
6
7#include <entt/entity/registry.hpp>
8
9#include <EngineCore/Utils/DeferredDeletionQueue.hpp>
10#include <EngineCore/Utils/MemoryAllocator.hpp>
11#include <Common/Logging.hpp>
12
13namespace Grindstone {
14 namespace GraphicsAPI {
15 class Core;
16 class RenderPass;
17 }
18
19 namespace Input {
20 class Interface;
21 }
22
23 namespace Plugins {
24 class IPluginManager;
25 class Interface;
26 }
27
28 namespace ECS {
30 class SystemRegistrar;
31 }
32
33 namespace SceneManagement {
34 class SceneManager;
35 }
36
37 namespace Events {
38 struct BaseEvent;
39 class Dispatcher;
40 }
41
42 namespace Assets {
43 class AssetManager;
44 class AssetLoader;
45 }
46
47 namespace Profiler {
48 class Manager;
49 }
50
51 namespace Renderer {
52 class RenderingPipeline;
53 }
54
55 class Window;
56 class DisplayManager;
57 class WindowManager;
58
59 class AssetRendererManager;
60 class RenderPassRegistry;
61 class WorldContextManager;
62
63 class EngineCore {
64 public:
65 static EngineCore& GetInstance();
66 static void SetInstance(EngineCore& engineCore);
67
69 bool isEditor = false;
70 const char* applicationModuleName = nullptr;
71 const char* applicationTitle = nullptr;
72 const char* projectPath = nullptr;
73 const char* engineBinaryPath = nullptr;
74 Assets::AssetLoader* assetLoader = nullptr;
75 };
76
78 Grindstone::Assets::AssetLoader* assetLoader = nullptr;
79 Grindstone::Plugins::IPluginManager* pluginManagerOverride = nullptr;
80 };
81
82 virtual bool EarlyInitialize(EarlyCreateInfo& ci);
83 virtual bool Initialize(LateCreateInfo& createInfo);
84 virtual void InitializeScene(bool shouldLoadSceneFromDefaults, const char* scenePath = nullptr);
85 virtual void ShowMainWindow();
86
87 virtual ~EngineCore();
88 virtual void Run();
89 virtual void RunEditorLoopIteration();
90 virtual void RunLoopIteration();
91 virtual void UpdateWindows();
92 void RegisterGraphicsCore(GraphicsAPI::Core*);
93 virtual void RegisterInputManager(Input::Interface*);
94 virtual Input::Interface* GetInputManager() const;
95 virtual SceneManagement::SceneManager* GetSceneManager() const;
96 virtual Plugins::IPluginManager* GetPluginManager() const;
97 virtual Plugins::Interface* GetPluginInterface() const;
98 virtual ECS::SystemRegistrar* GetSystemRegistrar() const;
99 virtual Events::Dispatcher* GetEventDispatcher() const;
100 virtual ECS::ComponentRegistrar* GetComponentRegistrar() const;
101 virtual GraphicsAPI::Core* GetGraphicsCore() const;
102 virtual Profiler::Manager* GetProfiler() const;
103 virtual RenderPassRegistry* GetRenderPassRegistry() const;
104 virtual WorldContextManager* GetWorldContextManager() const;
105 virtual std::filesystem::path GetProjectPath() const;
106 virtual std::filesystem::path GetBinaryPath() const;
107 virtual std::filesystem::path GetEngineBasePath() const;
108 virtual std::filesystem::path GetEngineBinaryPath() const;
109 virtual entt::registry& GetEntityRegistry();
110 virtual Renderer::RenderingPipeline* GetRenderingPipeline() const;
111
112 virtual bool OnTryQuit(Grindstone::Events::BaseEvent* ev);
113 virtual bool OnForceQuit(Grindstone::Events::BaseEvent* ev);
114 virtual void CalculateDeltaTime();
115 virtual double GetTimeSinceLaunch() const;
116 virtual double GetDeltaTime() const;
117 virtual void PushDeletion(std::function<void()> fn);
118 virtual void ForceDeleteAllDeferred();
119
120 template<typename T, typename... Args>
121 void RegisterServiceEmplaced(Args&&... params) {
122 const size_t hash = typeid(T).hash_code();
123 auto it = services.find(hash);
124 if (it == services.end()) {
125 services[hash] = Grindstone::Memory::AllocatorCore::Allocate<T>(std::forward<Args>(params)...);
126 }
127 }
128
129 template<typename T>
130 void RegisterService(T* instance) {
131 const size_t hash = typeid(T).hash_code();
132 auto it = services.find(hash);
133 if (it == services.end()) {
134 services.emplace(hash, instance);
135 }
136 }
137
138 template<typename T>
139 void UnregisterService() {
140 const size_t hash = typeid(T).hash_code();
141 auto it = services.find(hash);
142 if (it == services.end()) {
143 services.erase(it);
144 }
145 }
146
147 template<typename T>
148 T* TryGetService() {
149 const size_t hash = typeid(T).hash_code();
150 auto it = services.find(hash);
151 return (it != services.end())
152 ? static_cast<T*>(it->second)
153 : nullptr;
154 }
155 public:
156 DisplayManager* displayManager = nullptr;
157 WindowManager* windowManager = nullptr;
158 Assets::AssetManager* assetManager = nullptr;
159 AssetRendererManager* assetRendererManager = nullptr;
160 WorldContextManager* worldContextManager = nullptr;
161 Profiler::Manager* profiler = nullptr;
162 bool isEditor = false;
163 private:
164 Grindstone::DeferredDeletionQueue deferredDeletionQueue;
165 double currentTime = 0.0;
166 double deltaTime = 0.0;
167 std::chrono::steady_clock::time_point firstFrameTime;
168 std::chrono::steady_clock::time_point lastFrameTime;
169 SceneManagement::SceneManager* sceneManager = nullptr;
170 ECS::ComponentRegistrar* componentRegistrar = nullptr;
171 ECS::SystemRegistrar* systemRegistrar = nullptr;
172 RenderPassRegistry* renderpassRegistry = nullptr;
173 Events::Dispatcher* eventDispatcher = nullptr;
174 Plugins::Interface* pluginInterface = nullptr;
175 Plugins::IPluginManager* pluginManager = nullptr;
176 Renderer::RenderingPipeline* renderingPipeline = nullptr;
177 GraphicsAPI::Core* graphicsCore = nullptr;
178 Input::Interface* inputManager = nullptr;
179 std::unordered_map<std::size_t, void*> services;
180 bool shouldClose = false;
181 std::filesystem::path projectPath;
182 std::filesystem::path binaryPath;
183 std::filesystem::path engineBasePath;
184 std::filesystem::path engineBinaryPath;
185 };
186}
Definition AssetLoader.hpp:32
Definition AssetManager.hpp:15
Definition ComponentRegistrar.hpp:18
Definition SystemRegistrar.hpp:12
Definition EngineCore.hpp:63
Definition Dispatcher.hpp:14
Definition Core.hpp:41
Definition RenderPass.hpp:10
Definition InputInterface.hpp:11
Definition IPluginManager.hpp:9
Definition Interface.hpp:56
Definition Profiling.hpp:24
Definition RenderPassRegistry.hpp:12
Definition RenderingPipeline.hpp:22
Definition WorldContextManager.hpp:12
Definition ArchiveContentFile.hpp:8
Definition ComponentInspector.hpp:11
Definition BaseEvent.hpp:6
Definition Buffer.hpp:9
Definition CursorMode.hpp:6
Definition EditorPluginInterface.hpp:17
Definition EngineCore.hpp:47
Definition AttachmentInfo.hpp:17
Definition CommandList.hpp:8
Definition Assert.hpp:16
Definition EngineCore.hpp:68
Definition EngineCore.hpp:77
Definition BaseEvent.hpp:7