Hubris Engine Dev
A Project to learn and get into Game Engine developement.
 
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1#pragma once
2#include <Platform.h>
3#include <Logger.h>
4#include <Core/ThreadPool.h>
7#include <Memory.h>
8#include <Core/EventBus.h>
9
11namespace Hubris {
12
13
14 struct Version {
16 };
17
22 enum class RenderAPI : unsigned short {
24 };
25
26 typedef void(*StartupCallback)();
28 struct EngineConfig {
32 unsigned int ThreadCount = std::thread::hardware_concurrency() - 1;
39 std::string FileRoot = "";
43 std::string ProjectName = "Default";
44
45 Version ProjectVersion = { 0,0,0,0 };
46
48
50 };
51
52 class GraphicsManager final {
53 friend class Engine;
54
55 static void SetAPI(const RenderAPI& api);
56 public:
57 static void CreateWindow();
58 };
59
60 class Engine final {
61 private:
62 static inline bool Started = false;
63 static inline std::string ProjectName;
64 static inline Version ProjectVersion;
65 static inline Graphics::Window* window;
66 static inline std::terminate_handler originalHandler = nullptr;
67 static inline std::vector<const char*> Env = std::vector<const char*>(0);
68 static void InitGraphics(const EngineConfig& config);
69
70
71 static void Terminate() noexcept{
72 Logger::Fatal("Engine Execution has been terminated.");
74
75 if(originalHandler){
76 originalHandler();
77 }
78 }
79
81 Engine() = delete;
82 ~Engine() = delete;
83
84 public:
88 static EngineConfig GetPlatformConfig(std::string ProjectName = "Default", const Version& ProjectVersion = {0,0,0,0}) noexcept {
89 static EngineConfig config;
90 static bool HasInit = false;
91 if (!HasInit) {
92 config.ThreadCount = std::thread::hardware_concurrency() - 1;
95 }
96 }
97 config.ProjectName = ProjectName;
98 config.ProjectVersion = ProjectVersion;
99 config.WindowDimension = {800, 600};
100
101 return config;
102 }
103
106 static void Init(const EngineConfig& config) noexcept {
107 if (Started) {
108 Logger::Log("Engine Already started.");
109 return;
110 }
111 ProjectName = config.ProjectName;
112 //ThreadPool::InitalizePool(config.ThreadCount);
113 InitGraphics(config);
114
115 originalHandler = std::set_terminate(Engine::Terminate);
116
117 // if (config.StartUpCallback) {
118 // config.StartUpCallback();
119 // }
120
122 }
123
131 static void Run() {
132 while (window->IsRunning()) {
133 Loop();
135 }
136 }
137
142 static void Loop() {
143 window->Update();
144// #pragma warning (push)
145// #pragma warning (disable: 4996)
146// _sleep(100);
147// #pragma warning (pop)
148 }
149
150 static void Shutdown(){
151 window->Close();
152 //TODO: Add Grahpics cleanup, this needs some work.
153 // GraphicsManager::Cleanup()
154 }
155
160 static void GetPluginManager() {
161
162 }
163
164 static void CreateWindow() {}
165
167 static inline const std::string& GetProjectName() noexcept { return ProjectName; };
168 static inline const Version& GetProjectVersion() noexcept { return ProjectVersion; };
169 // static const char** GetVkRequiredExtensions() noexcept;
170 };
171 // End of EngineGroup
173}
constinit const Hbr_Platform Platform
Definition Platform.h:48
static void Dispatch(const Event &event)
Definition EventBus.h:15
static void Run()
Yields control to the engine logic. The Engine will run until the program exits.
Definition Engine.h:131
static Graphics::Window * GetWindow()
Definition Engine.h:166
static EngineConfig GetPlatformConfig(std::string ProjectName="Default", const Version &ProjectVersion={0, 0, 0, 0}) noexcept
Returns the default platform's (Windows, Linux, etc...) default engine configuration.
Definition Engine.h:88
static void CreateWindow()
Definition Engine.h:164
static void Shutdown()
Definition Engine.h:150
static void GetPluginManager()
Get the Plugin Manager object. [A planned feature].
Definition Engine.h:160
static const std::string & GetProjectName() noexcept
Definition Engine.h:167
static void Loop()
The Engine Executes the main loop once, then returns control to user.
Definition Engine.h:142
static void Init(const EngineConfig &config) noexcept
Initializes the engine (headless) for the first time called. TODO: Make sure this is a headless initi...
Definition Engine.h:106
static const Version & GetProjectVersion() noexcept
Definition Engine.h:168
friend class Engine
Definition Engine.h:53
static void CreateWindow()
static void Log(const char *message)
Definition Logger.h:104
static void Fatal(fmt::format_string< Args... > message, Args &&... args)
Definition Logger.h:147
static void Close()
Flushes and closes all the files used for logging.
Definition Logger.h:64
RenderAPI
Definition Engine.h:22
void(* StartupCallback)()
Definition Engine.h:26
The Hubris Engine main namespace.
Definition EventBus.h:4
Used to configure the engine on instantiation.
Definition Engine.h:28
unsigned int ThreadCount
Maximum of Thread to be spawned. (default: std::thread::hardware_concurrency() - 1)
Definition Engine.h:32
Graphics::Viewport WindowDimension
Definition Engine.h:47
std::string FileRoot
Set to empty string to make the execution folder the root.
Definition Engine.h:39
std::string ProjectName
The Application/Game Name. Will be set as the Title of the window (used also by vulkan).
Definition Engine.h:43
RenderAPI GraphicsBackend
Definition Engine.h:33
StartupCallback StartUpCallback
Definition Engine.h:49
Version ProjectVersion
Definition Engine.h:45
Screen-space Dimensions. The Depth Values are used by the pipelines.
Definition Window.h:16