Onyx-Engine/src/core/Core.cpp

107 lines
2.2 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-21 16:34:23 +00:00
#include "systems/AssetManager.h"
2025-05-18 18:29:55 +00:00
2025-05-18 17:42:48 +00:00
namespace OX
{
2025-05-21 02:42:18 +00:00
void Core::AddLayer(std::unique_ptr<Layer> layer)
{
Logger::LogDebug("Added Layer: '%s'", layer->GetName().c_str());
m_layers.emplace_back(std::move(layer));
}
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
void Core::Init()
{
Logger::LogInfo("Initializing Core...");
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
if (!window.Init(m_name, 1280, 720))
return;
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
OX_ASSERT(!m_layers.empty(), "No Layers Attached");
std::string layerTitle;
for (size_t i = 0; i < m_layers.size(); ++i) {
if (i > 0)
layerTitle += " - ";
layerTitle += m_layers[i]->GetName();
}
for (const auto &layer : m_layers) {
2025-05-21 15:16:46 +00:00
2025-05-21 02:42:18 +00:00
Logger::LogDebug("Initializing Layer: '%s'", layer->GetName().c_str());
layer->Init(*this);
}
2025-05-18 17:42:48 +00:00
std::string fullTitle = layerTitle + " - " + m_name;
window.SetWindowTitle(fullTitle);
2025-05-18 17:42:48 +00:00
Logger::LogOk("Core Initialization Complete.");
2025-05-21 16:34:23 +00:00
AssetManager::Init("C:/Users/spenc/OneDrive/Desktop/OnyxProject");
2025-05-21 02:42:18 +00:00
}
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
void Core::Run()
{
m_running = true;
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
while (!window.ShouldClose()) {
Profiler::BeginFrame(); {
OX_PROFILE_LABEL("Frame");
Update();
window.BeginFrame();
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
Draw();
window.EndFrame();
}
Profiler::EndFrame();
2025-05-18 17:42:48 +00:00
}
}
2025-05-21 02:42:18 +00:00
void Core::Update()
{
OX_PROFILE_FUNCTION();
2025-05-21 16:34:23 +00:00
AssetManager::Tick();
2025-05-21 02:42:18 +00:00
for (auto &layer: m_layers) {
layer->Update(*this);
}
2025-05-18 17:42:48 +00:00
}
2025-05-21 02:42:18 +00:00
void Core::Draw()
{
OX_PROFILE_FUNCTION();
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
for (auto &layer: m_layers) {
layer->Draw(*this);
}
2025-05-18 17:42:48 +00:00
}
2025-05-21 02:42:18 +00:00
void Core::Shutdown()
{
Logger::LogDebug("Shutting down Core...");
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
for (auto &layer: m_layers) {
Logger::LogDebug("Shutting down Layer: '%s'", layer->GetName().c_str());
layer->Shutdown(*this);
}
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
m_layers.clear();
2025-05-21 16:34:23 +00:00
AssetManager::Shutdown();
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
window.Shutdown();
2025-05-18 17:42:48 +00:00
2025-05-21 02:42:18 +00:00
Logger::LogOk("Core Shutdown Complete.");
}
2025-05-18 18:29:55 +00:00
}