16 Application::Application(
const char* windowName) : m_WorkerPool(std::thread::hardware_concurrency() == 1 ? 1 : std::thread::hardware_concurrency() - 1) {
19 CORI_CORE_ASSERT(!s_Instance,
"Trying to construct application for the second time. Application already exists!");
22 FileSystem::PathManager::Get();
24 m_Window = Window::Create(windowName,
false);
27 m_Window->SetVSync(
false);
31 m_LayerStack.PushOverlay(m_ImGuiLayer);
34 World::SceneManager::Init();
38 m_GameTimer.SetTickrate(120);
44 m_LayerStack.ClearStack();
45 AssetManager::Shutdown();
46 World::SceneManager::Shutdown();
48 Audio::Mixer::Shutdown();
52 s_Instance->OnEvent(event);
56 return s_Instance->m_WorkerPool.GetWorkerCount();
59 void Application::OnEvent(
Event& event) {
65 m_RenderImGui = !m_RenderImGui;
69 dispatcher.Dispatch<WindowResizeEvent>([](
const WindowResizeEvent& e) ->
bool {
74 for (
auto it = m_LayerStack.end(); it != m_LayerStack.begin();) {
76 (*it)->OnEvent(event);
77 if (event.
m_Handled || (*it)->IsModal()) {
84 return s_Instance->m_LayerStack.PushLayerToQueue(layer);
88 return s_Instance->m_LayerStack.PushOverlayToQueue(overlay);
92 s_Instance->m_LayerStack.PopLayerToQueue();
96 s_Instance->m_LayerStack.PopOverlayToQueue();
100 s_Instance->m_BackgroundColor = color;
108 m_CommandQueue.Execute();
109 m_GameTimer.Update();
119 for (
Layer* layer : m_LayerStack) {
120 layer->ActiveScene.BeginRender();
121 layer->OnUpdate(m_GameTimer);
122 layer->SceneUpdate(m_GameTimer);
123 layer->ActiveScene.EndRender();
130 m_ImGuiLayer->StartFrame();
133 for (
Layer* layer : m_LayerStack) {
134 layer->OnImGuiRender(m_GameTimer);
135 layer->SceneImGuiRender(m_GameTimer);
136 if (layer->IsModal()) {
142 m_ImGuiLayer->EndFrame();
145 m_Window->OnUpdate();
147 m_LayerStack.ProcessQueue();
152 void Application::TickrateUpdate(
GameTimer& gameTimer) {
153 for (
Layer* layer : m_LayerStack) {
154 layer->SceneTickrateUpdate(gameTimer);
155 layer->OnTickUpdate(gameTimer);
156 if (layer->IsModal()) {
162 bool Application::OnWindowClose() {
#define CORI_CORE_ASSERT(x,...)
#define CORI_CORE_INFO_TAGGED(...)
#define CORI_PLACEHOLDERS(x)
#define CORI_BIND_EVENT_FN(x,...)
#define CORI_PROFILER_FRAME_START()
#define CORI_PROFILE_SCOPE(name)
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 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 uint16_t GetWorkerCount()
Returns a number of available worker threads.
Used in OnEvent methods to dispatch and handle Events.
An abstract class that is ment to be used as a template for defining events.
A GameTimer is responsible for managing everything that is connected with time, ticks,...
An abstract class that is ment to be used as a template for defining layers.
static void SetClearColor(const glm::vec4 &color)
static void SetViewport(const int32_t x, const int32_t y, const int32_t width, const int32_t height)
static void ClearFramebuffer()
Core systems of the engine are here.