From 6d356f55976740f93fe3fc088b3da356cb3748d5 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:06:38 -0600 Subject: [PATCH] Revamped Logger Window --- scenes/Default.scene | 35 ++++++------ src/Components/Mesh.cpp | 4 +- src/Engine.cpp | 6 +- src/Windows/LoggerWindow.cpp | 108 +++++++++++++++++++++++++++++------ src/Windows/LoggerWindow.h | 22 +++++-- 5 files changed, 133 insertions(+), 42 deletions(-) diff --git a/scenes/Default.scene b/scenes/Default.scene index bf16638..f65c1e0 100644 --- a/scenes/Default.scene +++ b/scenes/Default.scene @@ -2,10 +2,6 @@ Entities: - ID: 0 Name: Bacround Components: - Transform: - Position: [0, 300, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] Mesh: MeshPath: assets/models/sponza.obj submeshes_len: 26 @@ -160,15 +156,13 @@ Entities: - id: 26 type: texture_diffuse path: textures/vase_hanging.tga + Transform: + Position: [0, 300, 0] + Rotation: [0, 0, 0] + Scale: [1, 1, 1] - ID: 1 Name: Camera Components: - ScriptComponent: - ScriptPath: assets/scripts/camera.lua - Transform: - Position: [578.542908, 200, -169.946655] - Rotation: [0, 160.221146, 0] - Scale: [1, 1, 1] CameraComponent: IsPerspective: true DefaultRuntimeCamera: true @@ -176,14 +170,23 @@ Entities: AspectRatio: 1.75 NearPlane: 0.100000001 FarPlane: 7000 + Transform: + Position: [654.808716, 200, -123.745712] + Rotation: [0, 170.205078, 0] + Scale: [1, 1, 1] + ScriptComponent: + ScriptPath: assets/scripts/camera.lua - ID: 2 - Name: New GameObject 2 + Name: Grey Cube Components: - Mesh: - MeshPath: assets/models/DefaultMesh.obj - submeshes_len: 0 - submeshes: ~ Transform: Position: [0, 0, 0] Rotation: [0, 0, 0] - Scale: [1, 1, 1] \ No newline at end of file + Scale: [25, 25, 25] + Mesh: + MeshPath: assets/models/DefaultMesh.obj + submeshes_len: 1 + submeshes: + - vao: 53 + indexCount: 36 + textures: ~ \ No newline at end of file diff --git a/src/Components/Mesh.cpp b/src/Components/Mesh.cpp index 10c32c2..e3b4b4f 100644 --- a/src/Components/Mesh.cpp +++ b/src/Components/Mesh.cpp @@ -140,7 +140,7 @@ void MeshComponent::Deserialize(const YAML::Node &node) if (submeshes_len != static_cast(model->submeshes.size())) { - g_LoggerWindow->AddLog("[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast(submeshes.size())); + g_LoggerWindow->AddLog(LogLevel::Error, "[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast(submeshes.size())); } // Assign submeshes @@ -182,7 +182,7 @@ void MeshComponent::Deserialize(const YAML::Node &node) } if (submeshes_len != static_cast(submeshes.size())) { - g_LoggerWindow->AddLog("[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast(submeshes.size())); + g_LoggerWindow->AddLog(LogLevel::Error,"[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast(submeshes.size())); } } } diff --git a/src/Engine.cpp b/src/Engine.cpp index 39b77a1..586c763 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -118,6 +118,7 @@ bool MyEngine::Init(int width, int height, const std::string &title) #ifdef DEBUG ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable; + #endif // Path to your font files @@ -184,13 +185,16 @@ bool MyEngine::Init(int width, int height, const std::string &title) // Optionally, call 'onInit' Lua function // Some initial logs - m_LoggerWindow->AddLog("Engine initialized."); m_LoggerWindow->AddLog("Welcome to Tesseract Engine!"); m_Running = true; m_LastTime = glfwGetTime(); DEBUG_PRINT("[OK] Engine Init "); + #ifdef DEBUG + g_LoggerWindow->AddLog(LogLevel::Warning, "Warning: You are in Debug Mode. Switch to Releace for more performance"); + #endif + return true; } diff --git a/src/Windows/LoggerWindow.cpp b/src/Windows/LoggerWindow.cpp index 556207f..6d3bf5d 100644 --- a/src/Windows/LoggerWindow.cpp +++ b/src/Windows/LoggerWindow.cpp @@ -6,8 +6,9 @@ #include #include "Icons.h" #include "Engine/ScopedTimer.h" +#include "Icons.h" + -// Helper function to format strings static std::string FormatString(const char *fmt, va_list args) { char buffer[1024]; @@ -15,6 +16,48 @@ static std::string FormatString(const char *fmt, va_list args) return std::string(buffer); } +// Choose a default icon for each LogLevel +static const char* GetIconForLevel(LogLevel level) +{ + switch (level) + { + case LogLevel::Warning: return ICON_FA_TRIANGLE_EXCLAMATION; + case LogLevel::Error: return ICON_FA_CIRCLE_EXCLAMATION; + case LogLevel::Info: + default: return ICON_FA_INFO; + } +} + +// Choose a default color for each LogLevel if none is specified. +static ImVec4 GetDefaultColorForLevel(LogLevel level) +{ + switch (level) + { + case LogLevel::Warning: return ImVec4(1.0f, 0.8f, 0.0f, 1.0f); // Yellow-ish + case LogLevel::Error: return ImVec4(1.0f, 0.2f, 0.2f, 1.0f); // Reddish + case LogLevel::Info: + default: return ImVec4(0.8f, 0.8f, 0.8f, 1.0f); // Light gray + } +} + +void LoggerWindow::AddLog(const char *fmt, std::optional color, ...) +{ + va_list args; + va_start(args, fmt); + std::string formatted = FormatString(fmt, args); + va_end(args); + + LogEntry entry; + entry.text = formatted; + entry.level = LogLevel::Info; + entry.color = color; + entry.icon = GetIconForLevel(entry.level); + + m_Logs.emplace_back(entry); + m_ScrollToBottom = true; +} + +// 1) Existing method (no LogLevel) — default to Info void LoggerWindow::AddLog(const char *fmt, ...) { va_list args; @@ -22,21 +65,54 @@ void LoggerWindow::AddLog(const char *fmt, ...) std::string formatted = FormatString(fmt, args); va_end(args); - m_Logs.emplace_back(formatted); + LogEntry entry; + entry.text = formatted; + entry.level = LogLevel::Info; + entry.color = std::nullopt; // We'll use the default color + entry.icon = GetIconForLevel(entry.level); + + m_Logs.emplace_back(entry); m_ScrollToBottom = true; } -void LoggerWindow::AddLog(const char *fmt, std::optional color, ...) +// 2) New method for specifying LogLevel +void LoggerWindow::AddLog(LogLevel level, const char *fmt, ...) { va_list args; - va_start(args, color); + va_start(args, fmt); std::string formatted = FormatString(fmt, args); va_end(args); - m_Logs.emplace_back(formatted, color); + LogEntry entry; + entry.text = formatted; + entry.level = level; + entry.color = std::nullopt; // Use default color for this level + entry.icon = GetIconForLevel(level); + + m_Logs.emplace_back(entry); m_ScrollToBottom = true; } +// 3) New method for specifying LogLevel + an explicit color override +void LoggerWindow::AddLog(LogLevel level, const ImVec4 &color, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + std::string formatted = FormatString(fmt, args); + va_end(args); + + LogEntry entry; + entry.text = formatted; + entry.level = level; + entry.color = color; // Explicit color override + entry.icon = GetIconForLevel(level); + + m_Logs.emplace_back(entry); + m_ScrollToBottom = true; +} + + + void LoggerWindow::Show() { SCOPE_TIMER("LoggerWindow::Show"); @@ -50,21 +126,18 @@ void LoggerWindow::Show() ImGui::Separator(); - // Begin a child region to enable scrolling - ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); + ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false, + ImGuiWindowFlags_HorizontalScrollbar); for (const auto &logEntry : m_Logs) { - if (logEntry.color.has_value()) - { - ImGui::PushStyleColor(ImGuiCol_Text, logEntry.color.value()); - ImGui::TextUnformatted(logEntry.text.c_str()); - ImGui::PopStyleColor(); - } - else - { - ImGui::TextUnformatted(logEntry.text.c_str()); - } + // 1) Decide what color to use + ImVec4 color = logEntry.color.value_or( + GetDefaultColorForLevel(logEntry.level) + ); + + // 2) Show "[icon] the text" + ImGui::TextColored(color, "%s %s", logEntry.icon.c_str(), logEntry.text.c_str()); } // Auto-scroll to bottom if new logs are added @@ -75,6 +148,5 @@ void LoggerWindow::Show() } ImGui::EndChild(); - ImGui::End(); } diff --git a/src/Windows/LoggerWindow.h b/src/Windows/LoggerWindow.h index 8d4ac3f..ef06d87 100644 --- a/src/Windows/LoggerWindow.h +++ b/src/Windows/LoggerWindow.h @@ -6,19 +6,31 @@ #include #include #include +#include "Icons.h" -struct LogEntry { - std::string text; - std::optional color; +// Example: Different severity levels +enum class LogLevel +{ + Info, + Warning, + Error +}; - LogEntry(const std::string& msg, std::optional col = std::nullopt) - : text(msg), color(col) {} +struct LogEntry +{ + std::string text ; + LogLevel level; + std::optional color; + std::string icon ; }; class LoggerWindow { public: void AddLog(const char* fmt, ...); void AddLog(const char* fmt, std::optional color, ...); + void AddLog(LogLevel level, const char *fmt, ...); + void AddLog(LogLevel level, const ImVec4 &color, const char *fmt, ...); + void Show(); private: