Revamped Logger Window
This commit is contained in:
parent
2095152251
commit
6d356f5597
@ -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]
|
||||
Scale: [25, 25, 25]
|
||||
Mesh:
|
||||
MeshPath: assets/models/DefaultMesh.obj
|
||||
submeshes_len: 1
|
||||
submeshes:
|
||||
- vao: 53
|
||||
indexCount: 36
|
||||
textures: ~
|
@ -140,7 +140,7 @@ void MeshComponent::Deserialize(const YAML::Node &node)
|
||||
|
||||
if (submeshes_len != static_cast<int>(model->submeshes.size()))
|
||||
{
|
||||
g_LoggerWindow->AddLog("[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
|
||||
g_LoggerWindow->AddLog(LogLevel::Error, "[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
|
||||
}
|
||||
|
||||
// Assign submeshes
|
||||
@ -182,7 +182,7 @@ void MeshComponent::Deserialize(const YAML::Node &node)
|
||||
}
|
||||
if (submeshes_len != static_cast<int>(submeshes.size()))
|
||||
{
|
||||
g_LoggerWindow->AddLog("[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
|
||||
g_LoggerWindow->AddLog(LogLevel::Error,"[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include <cstdio>
|
||||
#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<ImVec4> 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<ImVec4> 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();
|
||||
}
|
||||
|
@ -6,19 +6,31 @@
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <imgui.h>
|
||||
#include "Icons.h"
|
||||
|
||||
struct LogEntry {
|
||||
// Example: Different severity levels
|
||||
enum class LogLevel
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
struct LogEntry
|
||||
{
|
||||
std::string text ;
|
||||
LogLevel level;
|
||||
std::optional<ImVec4> color;
|
||||
|
||||
LogEntry(const std::string& msg, std::optional<ImVec4> col = std::nullopt)
|
||||
: text(msg), color(col) {}
|
||||
std::string icon ;
|
||||
};
|
||||
|
||||
class LoggerWindow {
|
||||
public:
|
||||
void AddLog(const char* fmt, ...);
|
||||
void AddLog(const char* fmt, std::optional<ImVec4> color, ...);
|
||||
void AddLog(LogLevel level, const char *fmt, ...);
|
||||
void AddLog(LogLevel level, const ImVec4 &color, const char *fmt, ...);
|
||||
|
||||
void Show();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user