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 GetEngineBinaryPath() const;
108 virtual std::filesystem::path GetAssetsPath() const;
109 virtual std::filesystem::path GetEngineAssetsPath() const;
110 virtual std::filesystem::path GetAssetPath(std::string subPath) const;
111 virtual entt::registry& GetEntityRegistry();
112 virtual Renderer::RenderingPipeline* GetRenderingPipeline() const;
113
114 virtual bool OnTryQuit(Grindstone::Events::BaseEvent* ev);
115 virtual bool OnForceQuit(Grindstone::Events::BaseEvent* ev);
116 virtual void CalculateDeltaTime();
117 virtual double GetTimeSinceLaunch() const;
118 virtual double GetDeltaTime() const;
119 virtual void PushDeletion(std::function<void()> fn);
120 virtual void ForceDeleteAllDeferred();
121
122 template<typename T, typename... Args>
123 void RegisterServiceEmplaced(Args&&... params) {
124 const size_t hash = typeid(T).hash_code();
125 auto it = services.find(hash);
126 if (it == services.end()) {
127 services[hash] = Grindstone::Memory::AllocatorCore::Allocate<T>(std::forward<Args>(params)...);
128 }
129 }
130
131 template<typename T>
132 void RegisterService(T* instance) {
133 const size_t hash = typeid(T).hash_code();
134 auto it = services.find(hash);
135 if (it == services.end()) {
136 services.emplace(hash, instance);
137 }
138 }
139
140 template<typename T>
141 void UnregisterService() {
142 const size_t hash = typeid(T).hash_code();
143 auto it = services.find(hash);
144 if (it == services.end()) {
145 services.erase(it);
146 }
147 }
148
149 template<typename T>
150 T* TryGetService() {
151 const size_t hash = typeid(T).hash_code();
152 auto it = services.find(hash);
153 return (it != services.end())
154 ? static_cast<T*>(it->second)
155 : nullptr;
156 }
157 public:
158 DisplayManager* displayManager = nullptr;
159 WindowManager* windowManager = nullptr;
160 Assets::AssetManager* assetManager = nullptr;
161 AssetRendererManager* assetRendererManager = nullptr;
162 WorldContextManager* worldContextManager = nullptr;
163 Profiler::Manager* profiler = nullptr;
164 bool isEditor = false;
165 private:
166 Grindstone::DeferredDeletionQueue deferredDeletionQueue;
167 double currentTime = 0.0;
168 double deltaTime = 0.0;
169 std::chrono::steady_clock::time_point firstFrameTime;
170 std::chrono::steady_clock::time_point lastFrameTime;
171 SceneManagement::SceneManager* sceneManager = nullptr;
172 ECS::ComponentRegistrar* componentRegistrar = nullptr;
173 ECS::SystemRegistrar* systemRegistrar = nullptr;
174 RenderPassRegistry* renderpassRegistry = nullptr;
175 Events::Dispatcher* eventDispatcher = nullptr;
176 Plugins::Interface* pluginInterface = nullptr;
177 Plugins::IPluginManager* pluginManager = nullptr;
178 Renderer::RenderingPipeline* renderingPipeline = nullptr;
179 GraphicsAPI::Core* graphicsCore = nullptr;
180 Input::Interface* inputManager = nullptr;
181 std::unordered_map<std::size_t, void*> services;
182 bool shouldClose = false;
183 std::filesystem::path projectPath;
184 std::filesystem::path binaryPath;
185 std::filesystem::path engineBinaryPath;
186 std::filesystem::path engineAssetsPath;
187 std::filesystem::path assetsPath;
188 };
189}
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