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 class Window;
52 class DisplayManager;
53 class WindowManager;
54
59
60 class EngineCore {
61 public:
62 static EngineCore& GetInstance();
63 static void SetInstance(EngineCore& engineCore);
64
66 bool isEditor = false;
67 const char* applicationModuleName = nullptr;
68 const char* applicationTitle = nullptr;
69 const char* projectPath = nullptr;
70 const char* engineBinaryPath = nullptr;
71 Assets::AssetLoader* assetLoader = nullptr;
72 };
73
75 Grindstone::Assets::AssetLoader* assetLoader = nullptr;
76 Grindstone::Plugins::IPluginManager* pluginManagerOverride = nullptr;
77 };
78
79 virtual bool EarlyInitialize(EarlyCreateInfo& ci);
80 virtual bool Initialize(LateCreateInfo& createInfo);
81 virtual void InitializeScene(bool shouldLoadSceneFromDefaults, const char* scenePath = nullptr);
82 virtual void ShowMainWindow();
83
84 virtual ~EngineCore();
85 virtual void Run();
86 virtual void RunEditorLoopIteration();
87 virtual void RunLoopIteration();
88 virtual void UpdateWindows();
89 void RegisterGraphicsCore(GraphicsAPI::Core*);
90 virtual void RegisterInputManager(Input::Interface*);
91 virtual void SetRendererFactory(BaseRendererFactory* factory);
92 virtual Input::Interface* GetInputManager() const;
93 virtual SceneManagement::SceneManager* GetSceneManager() const;
94 virtual Plugins::IPluginManager* GetPluginManager() const;
95 virtual Plugins::Interface* GetPluginInterface() const;
96 virtual ECS::SystemRegistrar* GetSystemRegistrar() const;
97 virtual Events::Dispatcher* GetEventDispatcher() const;
98 virtual ECS::ComponentRegistrar* GetComponentRegistrar() const;
99 virtual GraphicsAPI::Core* GetGraphicsCore() const;
100 virtual Profiler::Manager* GetProfiler() const;
101 virtual BaseRendererFactory* GetRendererFactory() const;
102 virtual RenderPassRegistry* GetRenderPassRegistry() const;
103 virtual WorldContextManager* GetWorldContextManager() const;
104 virtual std::filesystem::path GetProjectPath() const;
105 virtual std::filesystem::path GetBinaryPath() const;
106 virtual std::filesystem::path GetEngineBinaryPath() const;
107 virtual std::filesystem::path GetAssetsPath() const;
108 virtual std::filesystem::path GetEngineAssetsPath() const;
109 virtual std::filesystem::path GetAssetPath(std::string subPath) const;
110 virtual entt::registry& GetEntityRegistry();
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 BaseRendererFactory* rendererFactory = nullptr;
173 RenderPassRegistry* renderpassRegistry = nullptr;
174 Events::Dispatcher* eventDispatcher = nullptr;
175 Plugins::Interface* pluginInterface = nullptr;
176 Plugins::IPluginManager* pluginManager = 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 engineBinaryPath;
184 std::filesystem::path engineAssetsPath;
185 std::filesystem::path assetsPath;
186 };
187}
Definition AssetRendererManager.hpp:18
Definition AssetLoader.hpp:32
Definition AssetManager.hpp:15
Definition BaseRenderer.hpp:47
Definition DisplayManager.hpp:8
Definition ComponentRegistrar.hpp:18
Definition SystemRegistrar.hpp:12
Definition EngineCore.hpp:60
Definition Dispatcher.hpp:14
Definition Core.hpp:41
Definition RenderPass.hpp:10
Definition InputInterface.hpp:11
Definition IPluginManager.hpp:9
Definition Interface.hpp:48
Definition Profiling.hpp:24
Definition RenderPassRegistry.hpp:12
Definition WindowManager.hpp:7
Definition Window.hpp:12
Definition WorldContextManager.hpp:12
Definition EngineCore.hpp:65
Definition EngineCore.hpp:74
Definition BaseEvent.hpp:7