Revamped Logger Window
This commit is contained in:
parent
2095152251
commit
6d356f5597
@ -2,10 +2,6 @@ Entities:
|
|||||||
- ID: 0
|
- ID: 0
|
||||||
Name: Bacround
|
Name: Bacround
|
||||||
Components:
|
Components:
|
||||||
Transform:
|
|
||||||
Position: [0, 300, 0]
|
|
||||||
Rotation: [0, 0, 0]
|
|
||||||
Scale: [1, 1, 1]
|
|
||||||
Mesh:
|
Mesh:
|
||||||
MeshPath: assets/models/sponza.obj
|
MeshPath: assets/models/sponza.obj
|
||||||
submeshes_len: 26
|
submeshes_len: 26
|
||||||
@ -160,15 +156,13 @@ Entities:
|
|||||||
- id: 26
|
- id: 26
|
||||||
type: texture_diffuse
|
type: texture_diffuse
|
||||||
path: textures/vase_hanging.tga
|
path: textures/vase_hanging.tga
|
||||||
|
Transform:
|
||||||
|
Position: [0, 300, 0]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
- ID: 1
|
- ID: 1
|
||||||
Name: Camera
|
Name: Camera
|
||||||
Components:
|
Components:
|
||||||
ScriptComponent:
|
|
||||||
ScriptPath: assets/scripts/camera.lua
|
|
||||||
Transform:
|
|
||||||
Position: [578.542908, 200, -169.946655]
|
|
||||||
Rotation: [0, 160.221146, 0]
|
|
||||||
Scale: [1, 1, 1]
|
|
||||||
CameraComponent:
|
CameraComponent:
|
||||||
IsPerspective: true
|
IsPerspective: true
|
||||||
DefaultRuntimeCamera: true
|
DefaultRuntimeCamera: true
|
||||||
@ -176,14 +170,23 @@ Entities:
|
|||||||
AspectRatio: 1.75
|
AspectRatio: 1.75
|
||||||
NearPlane: 0.100000001
|
NearPlane: 0.100000001
|
||||||
FarPlane: 7000
|
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
|
- ID: 2
|
||||||
Name: New GameObject 2
|
Name: Grey Cube
|
||||||
Components:
|
Components:
|
||||||
Mesh:
|
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
|
||||||
submeshes_len: 0
|
|
||||||
submeshes: ~
|
|
||||||
Transform:
|
Transform:
|
||||||
Position: [0, 0, 0]
|
Position: [0, 0, 0]
|
||||||
Rotation: [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()))
|
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
|
// Assign submeshes
|
||||||
@ -182,7 +182,7 @@ void MeshComponent::Deserialize(const YAML::Node &node)
|
|||||||
}
|
}
|
||||||
if (submeshes_len != static_cast<int>(submeshes.size()))
|
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
|
#ifdef DEBUG
|
||||||
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable;
|
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Path to your font files
|
// 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
|
// Optionally, call 'onInit' Lua function
|
||||||
|
|
||||||
// Some initial logs
|
// Some initial logs
|
||||||
m_LoggerWindow->AddLog("Engine initialized.");
|
|
||||||
m_LoggerWindow->AddLog("Welcome to Tesseract Engine!");
|
m_LoggerWindow->AddLog("Welcome to Tesseract Engine!");
|
||||||
|
|
||||||
m_Running = true;
|
m_Running = true;
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
DEBUG_PRINT("[OK] Engine Init ");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,9 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "Icons.h"
|
#include "Icons.h"
|
||||||
#include "Engine/ScopedTimer.h"
|
#include "Engine/ScopedTimer.h"
|
||||||
|
#include "Icons.h"
|
||||||
|
|
||||||
|
|
||||||
// Helper function to format strings
|
|
||||||
static std::string FormatString(const char *fmt, va_list args)
|
static std::string FormatString(const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
@ -15,6 +16,48 @@ static std::string FormatString(const char *fmt, va_list args)
|
|||||||
return std::string(buffer);
|
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, ...)
|
void LoggerWindow::AddLog(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -22,21 +65,54 @@ void LoggerWindow::AddLog(const char *fmt, ...)
|
|||||||
std::string formatted = FormatString(fmt, args);
|
std::string formatted = FormatString(fmt, args);
|
||||||
va_end(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;
|
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_list args;
|
||||||
va_start(args, color);
|
va_start(args, fmt);
|
||||||
std::string formatted = FormatString(fmt, args);
|
std::string formatted = FormatString(fmt, args);
|
||||||
va_end(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;
|
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()
|
void LoggerWindow::Show()
|
||||||
{
|
{
|
||||||
SCOPE_TIMER("LoggerWindow::Show");
|
SCOPE_TIMER("LoggerWindow::Show");
|
||||||
@ -50,21 +126,18 @@ void LoggerWindow::Show()
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
// Begin a child region to enable scrolling
|
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false,
|
||||||
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
|
|
||||||
for (const auto &logEntry : m_Logs)
|
for (const auto &logEntry : m_Logs)
|
||||||
{
|
{
|
||||||
if (logEntry.color.has_value())
|
// 1) Decide what color to use
|
||||||
{
|
ImVec4 color = logEntry.color.value_or(
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, logEntry.color.value());
|
GetDefaultColorForLevel(logEntry.level)
|
||||||
ImGui::TextUnformatted(logEntry.text.c_str());
|
);
|
||||||
ImGui::PopStyleColor();
|
|
||||||
}
|
// 2) Show "[icon] the text"
|
||||||
else
|
ImGui::TextColored(color, "%s %s", logEntry.icon.c_str(), logEntry.text.c_str());
|
||||||
{
|
|
||||||
ImGui::TextUnformatted(logEntry.text.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-scroll to bottom if new logs are added
|
// Auto-scroll to bottom if new logs are added
|
||||||
@ -75,6 +148,5 @@ void LoggerWindow::Show()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,31 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
#include "Icons.h"
|
||||||
|
|
||||||
struct LogEntry {
|
// Example: Different severity levels
|
||||||
std::string text;
|
enum class LogLevel
|
||||||
std::optional<ImVec4> color;
|
{
|
||||||
|
Info,
|
||||||
|
Warning,
|
||||||
|
Error
|
||||||
|
};
|
||||||
|
|
||||||
LogEntry(const std::string& msg, std::optional<ImVec4> col = std::nullopt)
|
struct LogEntry
|
||||||
: text(msg), color(col) {}
|
{
|
||||||
|
std::string text ;
|
||||||
|
LogLevel level;
|
||||||
|
std::optional<ImVec4> color;
|
||||||
|
std::string icon ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoggerWindow {
|
class LoggerWindow {
|
||||||
public:
|
public:
|
||||||
void AddLog(const char* fmt, ...);
|
void AddLog(const char* fmt, ...);
|
||||||
void AddLog(const char* fmt, std::optional<ImVec4> color, ...);
|
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();
|
void Show();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user