Onyx-Engine/src/core/Core.cpp

89 lines
1.5 KiB
C++
Raw Normal View History

2025-05-18 17:42:48 +00:00
//
// Created by spenc on 5/14/2025.
//
#include "Core.h"
2025-05-18 18:29:55 +00:00
#include "systems/MACROS.h"
2025-05-18 17:42:48 +00:00
namespace OX
{
void Core::AddLayer(std::unique_ptr<Layer> layer) {
Logger::LogDebug("Added Layer: '%s'", layer->GetName().c_str());
m_layers.emplace_back(std::move(layer));
}
void Core::Init() {
Logger::LogInfo("Initializing Core...");
if (!window.Init(m_name, 1280, 720))
return;
2025-05-18 18:29:55 +00:00
OX_ASSERT(!m_layers.empty(), "No Layers Attached");
for (const auto& layer : m_layers) {
2025-05-18 17:42:48 +00:00
Logger::LogDebug("Initializing Layer: '%s'", layer->GetName().c_str());
layer->Init(*this);
}
Logger::LogOk("Core Initialization Complete.");
}
void Core::Run() {
m_running = true;
while (!window.ShouldClose()) {
Profiler::BeginFrame();
{
2025-05-18 18:29:55 +00:00
OX_PROFILE_LABEL("Frame");
2025-05-18 17:42:48 +00:00
Update();
window.BeginFrame();
Draw();
window.EndFrame();
}
Profiler::EndFrame();
}
}
void Core::Update() {
2025-05-18 18:29:55 +00:00
OX_PROFILE_FUNCTION();
2025-05-18 17:42:48 +00:00
for (auto& layer : m_layers) {
layer->Update(*this);
}
}
void Core::Draw() {
2025-05-18 18:29:55 +00:00
OX_PROFILE_FUNCTION();
2025-05-18 17:42:48 +00:00
for (auto& layer : m_layers) {
layer->Draw(*this);
}
}
void Core::Shutdown() {
Logger::LogDebug("Shutting down Core...");
for (auto& layer : m_layers) {
Logger::LogDebug("Shutting down Layer: '%s'", layer->GetName().c_str());
layer->Shutdown(*this);
}
m_layers.clear();
window.Shutdown();
Logger::LogOk("Core Shutdown Complete.");
}
2025-05-18 18:29:55 +00:00
}