CoriEngine
Loading...
Searching...
No Matches
Application.hpp
Go to the documentation of this file.
1#pragma once
3#include "Window.hpp"
4#include "Layer.hpp"
5#include "LayerStack.hpp"
6#include "ImGuiLayer.hpp"
8#include "Time.hpp"
11
15namespace Cori {
19 namespace Core {
24 public:
25 explicit Application(const char* windowName);
26 virtual ~Application();
27
31 void Run();
32
40 [[nodiscard]] static std::expected<void, CoriError<>> PushLayer(Layer* layer);
41
51 [[nodiscard]] static std::expected<void, CoriError<>> PushOverlay(Layer* overlay);
52
53
59 static void PopLayer();
60
66 static void PopOverlay();
67
72 static void SetBackgroundColor(const glm::vec4& color);
73
78 static Window& GetWindow() { return *s_Instance->m_Window; }
79
84 static GameTimer& GetGameTimer() { return s_Instance->m_GameTimer; }
85
90 static void EmitEvent(Event& event);
91
102 template <class F, class... Args>
103 static std::future<std::invoke_result_t<F, Args...>> SubmitMainTask(F&& f, Args&&... args) {
104 return s_Instance->m_CommandQueue.Submit(std::forward<F>(f), std::forward<Args>(args)...);
105 }
106
116 template <class F, class... Args>
117 static std::future<std::invoke_result_t<F, Args...>> SubmitWorkerTask(F&& f, Args&&... args) {
118 return s_Instance->m_WorkerPool.Submit(std::forward<F>(f), std::forward<Args>(args)...);
119 }
120
125 static uint16_t GetWorkerCount();
126
127 private:
128 void OnEvent(Event& event);
129
130 void TickrateUpdate(GameTimer& gameTimer);
131
132 bool OnWindowClose();
133
134 bool m_RenderImGui{ true };
135
136 std::unique_ptr<Window> m_Window;
137
138 Internal::ImGuiLayer* m_ImGuiLayer;
139
140 LayerStack m_LayerStack;
141
142 Threading::MainThreadQueue m_CommandQueue;
143
144 Threading::ThreadPool m_WorkerPool;
145
146 GameTimer m_GameTimer;
147
148 bool m_Running{ true };
149
150 static Application* s_Instance;
151
152 glm::vec4 m_BackgroundColor{ 0.5f, 0.5f, 0.0f, 1.0f };
153 };
154
156 }
157}
Main Application object, there can only be one Application object. Basically a root of the program.
static void PopOverlay()
Pops the overlay Layer from the LayerStack.
static void EmitEvent(Event &event)
Emits the event and propagates it thought the LayerStack.
Application(const char *windowName)
static std::future< std::invoke_result_t< F, Args... > > SubmitMainTask(F &&f, Args &&... args)
Submits a task to be executed on the main thread.
static GameTimer & GetGameTimer()
Getter for the GameTimer.
static void SetBackgroundColor(const glm::vec4 &color)
Setts the background color of the rendering canvas.
static std::expected< void, CoriError<> > PushLayer(Layer *layer)
Pushes a Layer to the LayerStack.
static void PopLayer()
Pops the Layer from the LayerStack.
void Run()
Run loop, internal.
static std::expected< void, CoriError<> > PushOverlay(Layer *overlay)
Pushes an overlay Layer to the LayerStack.
static Window & GetWindow()
Getter for the main Window.
static std::future< std::invoke_result_t< F, Args... > > SubmitWorkerTask(F &&f, Args &&... args)
Submits a task to be executed on the worker thread.
static uint16_t GetWorkerCount()
Returns a number of available worker threads.
An abstract class that is ment to be used as a template for defining events.
Definition Event.hpp:18
A GameTimer is responsible for managing everything that is connected with time, ticks,...
Definition Time.hpp:8
An abstract class that is ment to be used as a template for defining layers.
Definition Layer.hpp:13
This class manages everything that is connected with physical Window management, i might add multiwin...
Definition Window.hpp:43
Core systems of the engine are here.
Application * CreateApplication()
Global engine namespace.