Added Layer Based Dynamic Window Titles

This commit is contained in:
OusmBlueNinja 2025-05-21 09:21:50 -05:00
parent 623aa4694b
commit f6e80b5ad0
5 changed files with 165 additions and 104 deletions

View File

@ -9,10 +9,12 @@
int main() int main()
{ {
constexpr const char* VERSION = "0.0.7"; // Format: 0.<release><commit_count> constexpr const char* VERSION = "0.1.0"; // Format: 0.<release><commit_count>
constexpr const char* TITLE = "Obsidian Editor - Onyx Engine (2025.1)";
OX::Core core(std::string(TITLE) + " (" + VERSION + ")");
OX::Core core(std::string(OX_ENGINE_VERSION) + " (" + VERSION + ")");
core.AddLayer(std::make_unique<OX::DummyLayer>("Dummy Layer"));
core.AddLayer(std::make_unique<OX::Editor>("Obsidian Editor")); core.AddLayer(std::make_unique<OX::Editor>("Obsidian Editor"));

View File

@ -21,25 +21,31 @@ namespace OX
if (!window.Init(m_name, 1280, 720)) if (!window.Init(m_name, 1280, 720))
return; return;
OX_ASSERT(!m_layers.empty(), "No Layers Attached"); OX_ASSERT(!m_layers.empty(), "No Layers Attached");
for (const auto &layer: m_layers) {
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) {
Logger::LogDebug("Initializing Layer: '%s'", layer->GetName().c_str()); Logger::LogDebug("Initializing Layer: '%s'", layer->GetName().c_str());
layer->Init(*this); layer->Init(*this);
} }
Logger::LogOk("Core Initialization Complete."); std::string fullTitle = layerTitle + " - " + m_name;
window.SetWindowTitle(fullTitle);
Logger::LogInfo("Info: This is an informational message."); Logger::LogOk("Core Initialization Complete.");
Logger::LogWarning("Warning: Something might be wrong.");
Logger::LogError("Error: Something went wrong!");
Logger::LogDebug("Debug: Internal debug information.");
Logger::LogVerbose("Verbose: Extra detailed logs.");
Logger::LogOk("Ok: Everything succeeded!");
} }
void Core::Run() void Core::Run()
{ {
m_running = true; m_running = true;

View File

@ -14,36 +14,69 @@
#include "systems/WindowManager.h" #include "systems/WindowManager.h"
#include "systems/MACROS.h" #include "systems/MACROS.h"
#define OX_ENGINE_VERSION "Onyx Engine (2025.1)"
namespace OX namespace OX
{ {
class Core { class Core
{
public: public:
Core(std::string name) : m_name(std::move(name)) {}; Core(std::string name) : m_name(std::move(name))
{
};
~Core() = default; ~Core() = default;
void Init(); void Init();
void Run(); void Run();
void Shutdown(); void Shutdown();
WindowManager& GetWindow() {return window;} WindowManager &GetWindow() { return window; }
void AddLayer(std::unique_ptr<Layer> layer); void AddLayer(std::unique_ptr<Layer> layer);
private: private:
void Update(); void Update();
void Draw(); void Draw();
std::vector<std::unique_ptr<Layer>> m_layers; std::vector<std::unique_ptr<Layer> > m_layers;
WindowManager window; WindowManager window;
bool m_running = false; bool m_running = false;
std::string m_name = "Application"; std::string m_name = "Application";
}; };
class DummyLayer : public Layer
{
public:
explicit DummyLayer(const std::string &name = "Dummy Layer")
: Layer(name)
{
}
void Init(Core &core) override
{
Logger::LogInfo("DummyLayer '%s' initialized.", m_name.c_str());
}
void Update(Core &core) override
{
}
void Draw(Core &core) override
{
}
void Shutdown(Core &core) override
{
Logger::LogInfo("DummyLayer '%s' shutting down.", m_name.c_str());
}
};
} }
#endif // CORE_H #endif // CORE_H

View File

@ -4,9 +4,11 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "Profiler.h" #include "Profiler.h"
namespace OX namespace OX
{ {
bool WindowManager::Init(const std::string& title, int width, int height) { bool WindowManager::Init(const std::string &title, int width, int height)
{
m_width = width; m_width = width;
m_height = height; m_height = height;
@ -35,7 +37,7 @@ bool WindowManager::Init(const std::string& title, int width, int height) {
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
GLenum err = glewInit(); GLenum err = glewInit();
if (err != GLEW_OK) { if (err != GLEW_OK) {
Logger::LogError("Failed to initialize GLEW: %s", reinterpret_cast<const char*>(glewGetErrorString(err))); Logger::LogError("Failed to initialize GLEW: %s", reinterpret_cast<const char *>(glewGetErrorString(err)));
return false; return false;
} }
@ -45,60 +47,77 @@ bool WindowManager::Init(const std::string& title, int width, int height) {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
return true; return true;
} }
void WindowManager::FramebufferSizeCallback(GLFWwindow* window, int width, int height) { void WindowManager::SetWindowTitle(const std::string &title) const
{
if (m_window) {
glfwSetWindowTitle(m_window, title.c_str());
}
else {
Logger::LogWarning("Failed to set Window Title: 'Not Initialized'");
}
}
void WindowManager::FramebufferSizeCallback(GLFWwindow *window, int width, int height)
{
OX_PROFILE_FUNCTION(); OX_PROFILE_FUNCTION();
auto* wm = static_cast<WindowManager*>(glfwGetWindowUserPointer(window)); auto *wm = static_cast<WindowManager *>(glfwGetWindowUserPointer(window));
if (wm) { if (wm) {
wm->SetSize(width, height); wm->SetSize(width, height);
} }
} }
void WindowManager::SetSize(int width, int height) { void WindowManager::SetSize(int width, int height)
{
OX_PROFILE_FUNCTION(); OX_PROFILE_FUNCTION();
m_width = width; m_width = width;
m_height = height; m_height = height;
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
void WindowManager::PollEvents() const { void WindowManager::PollEvents() const
{
OX_PROFILE_FUNCTION(); OX_PROFILE_FUNCTION();
glfwPollEvents(); glfwPollEvents();
} }
bool WindowManager::ShouldClose() const { bool WindowManager::ShouldClose() const
{
return glfwWindowShouldClose(m_window); return glfwWindowShouldClose(m_window);
} }
void WindowManager::BeginFrame() const { void WindowManager::BeginFrame() const
{
OX_PROFILE_FUNCTION(); OX_PROFILE_FUNCTION();
PollEvents(); PollEvents();
glViewport(0, 0, m_width, m_height); glViewport(0, 0, m_width, m_height);
glClearColor(0.07f, 0.07f, 0.1f, 1.0f); glClearColor(0.07f, 0.07f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} }
void WindowManager::EndFrame() const { void WindowManager::EndFrame() const
{
OX_PROFILE_FUNCTION(); OX_PROFILE_FUNCTION();
glfwSwapBuffers(m_window); glfwSwapBuffers(m_window);
}
} void WindowManager::Shutdown()
{
void WindowManager::Shutdown() {
if (m_window) { if (m_window) {
glfwDestroyWindow(m_window); glfwDestroyWindow(m_window);
m_window = nullptr; m_window = nullptr;
} }
glfwTerminate(); glfwTerminate();
} }
WindowManager::~WindowManager() { WindowManager::~WindowManager()
{
Shutdown(); Shutdown();
} }
} }

View File

@ -15,6 +15,7 @@ namespace OX
void PollEvents() const; void PollEvents() const;
[[nodiscard]] bool ShouldClose() const; [[nodiscard]] bool ShouldClose() const;
void SetWindowTitle(const std::string& title) const;
void BeginFrame() const; void BeginFrame() const;
void EndFrame() const; void EndFrame() const;