Updated look of logger and fixed Crash on shutdown
This commit is contained in:
parent
59f5d3ee6e
commit
45914933c0
18
imgui.ini
18
imgui.ini
@ -162,6 +162,24 @@ RefScale=13
|
||||
Column 0 Weight=1.0000
|
||||
Column 1 Width=120
|
||||
|
||||
[Table][0xE47E6B5D,3]
|
||||
RefScale=13
|
||||
Column 0 Width=70
|
||||
Column 1 Width=90
|
||||
Column 2 Weight=1.0000
|
||||
|
||||
[Table][0x88683AD9,3]
|
||||
RefScale=13
|
||||
Column 0 Width=120
|
||||
Column 1 Width=90
|
||||
Column 2 Weight=1.0000
|
||||
|
||||
[Table][0x43152D8E,3]
|
||||
RefScale=13
|
||||
Column 0 Width=120
|
||||
Column 1 Width=90
|
||||
Column 2 Weight=1.0000
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X
|
||||
|
@ -1,4 +1,2 @@
|
||||
[COMPILE] g++ -std=c++20 -Wall -g -DGLM_ENABLE_EXPERIMENTAL -O2 -static -static-libstdc++ -static-libgcc -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -Isrc\vendor\imgui -IC:\msys64\mingw64\lib\libyaml-cpp.a -MMD -MP -c src\src\core\utils\Logging.cpp -o src\build\core\utils\Logging.o
|
||||
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\AudioPlayerComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PathFollowerComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\audio\AudioEngine.o src\build\core\functions\Prefab.o src\build\core\functions\ScenePacker.o src\build\core\scripts\LuaGlobalBridge.o src\build\core\scripts\ScriptCore.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Popup.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\utils\Themes.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\AudioInfo.o src\build\editor\windows\Inspector.o src\build\editor\windows\LuaGlobals.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o src\build\xxhash.o src\build\miniaudio.o src\build\ImGuizmo.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto -ldbghelp -lz -lfreetype
|
||||
[ERROR] Runtime crash
|
||||
Command 'src\build\app.exe' returned non-zero exit status 3221225477.
|
||||
|
@ -684,7 +684,7 @@ void Engine::Run()
|
||||
{
|
||||
Logger::LogOk("Engine Start");
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
while (!glfwWindowShouldClose(window) && running)
|
||||
{
|
||||
if (g_engineConfig.settings.profile_editor)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
std::shared_ptr<Object> GetObjectByTag(const std::string &tag);
|
||||
|
||||
void Shutdown();
|
||||
void Stop() {running = false;}
|
||||
|
||||
|
||||
private:
|
||||
@ -49,6 +50,8 @@ private:
|
||||
std::vector<ParticleComponent*> m_particleUpdates;
|
||||
std::vector<PathFollowerComponent*> m_PathUpdates;
|
||||
|
||||
bool running = true;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -65,7 +65,9 @@ void SignalHandler::HandleSignal(int signal) {
|
||||
if (signal == SIGINT) {
|
||||
std::cout << "\n[Engine] Shutting down." << std::endl;
|
||||
if (engine)
|
||||
engine->Stop();
|
||||
engine->Shutdown();
|
||||
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include "utils.h"
|
||||
// Logger.cpp or a logger helper header
|
||||
#include <ctime> // for std::time, std::localtime
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <windows.h>
|
||||
@ -101,30 +101,42 @@ void Logger::Log(Level level, const char *fmt, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Logger::LogVA(Level level, const char *fmt, va_list args)
|
||||
|
||||
void Logger::LogVA(Level level, const char* fmt, va_list args)
|
||||
{
|
||||
char buffer[1024];
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
s_Messages.push_back({buffer, level});
|
||||
|
||||
const char *levelStr = ToString(level);
|
||||
const char *ansiColor = GetAnsiColor(level);
|
||||
std::string formatted = std::string("[Logger][") + levelStr + "] " + buffer;
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm localTime = *std::localtime(&t);
|
||||
char timeBuf[16];
|
||||
std::snprintf(timeBuf, sizeof(timeBuf), "%02d:%02d:%02d", localTime.tm_hour, localTime.tm_min, localTime.tm_sec);
|
||||
|
||||
s_Messages.push_back({
|
||||
buffer,
|
||||
level,
|
||||
{ localTime.tm_hour, localTime.tm_min, localTime.tm_sec }
|
||||
});
|
||||
|
||||
const char* levelStr = ToString(level);
|
||||
const char* ansiColor = GetAnsiColor(level);
|
||||
|
||||
std::string formatted = "[" + std::string(timeBuf) + "][" + levelStr + "] " + buffer;
|
||||
|
||||
if (s_PrintToTerminal && HasTerminal())
|
||||
{
|
||||
std::cout << ansiColor << formatted << "\033[0m\n";
|
||||
}
|
||||
|
||||
// Always write to file
|
||||
ScopedLogFileWriter logFile;
|
||||
auto &out = logFile.Get();
|
||||
auto& out = logFile.Get();
|
||||
if (out.is_open())
|
||||
{
|
||||
out << formatted << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Logger::LogOk(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
@ -255,92 +267,103 @@ void Logger::Clear()
|
||||
s_Messages.clear();
|
||||
}
|
||||
|
||||
void Logger::Draw(const char *title)
|
||||
|
||||
void Logger::Draw(const char* title)
|
||||
{
|
||||
ImGui::Begin(title);
|
||||
|
||||
if (ImGui::Button("Clear"))
|
||||
Clear();
|
||||
// Top Controls
|
||||
if (ImGui::Button("Clear")) Clear();
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Auto-scroll", &s_AutoScroll);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("PrintLogs", &s_PrintToTerminal);
|
||||
ImGui::Separator();
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(200);
|
||||
static char filterBuf[128] = "";
|
||||
ImGui::InputTextWithHint("##Filter", "Filter logs...", filterBuf, IM_ARRAYSIZE(filterBuf));
|
||||
|
||||
// New Ok checkbox
|
||||
ImGui::Checkbox("Ok", &s_ShowOk);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Info", &s_ShowInfo);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Warning", &s_ShowWarning);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Error", &s_ShowError);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Debug", &s_ShowDebug);
|
||||
// Filter toggles
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Show:");
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Ok", &s_ShowOk); ImGui::SameLine();
|
||||
ImGui::Checkbox("Info", &s_ShowInfo); ImGui::SameLine();
|
||||
ImGui::Checkbox("Warning", &s_ShowWarning); ImGui::SameLine();
|
||||
ImGui::Checkbox("Error", &s_ShowError); ImGui::SameLine();
|
||||
ImGui::Checkbox("Debug", &s_ShowDebug); ImGui::SameLine();
|
||||
ImGui::Checkbox("Verbose", &s_ShowVerbose);
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::BeginChild("LogMessages");
|
||||
|
||||
// Filter
|
||||
std::vector<const LogMessage *> filtered;
|
||||
for (auto &m : s_Messages)
|
||||
{
|
||||
if ((m.level == Ok && !s_ShowOk) ||
|
||||
(m.level == Info && !s_ShowInfo) ||
|
||||
(m.level == Warning && !s_ShowWarning) ||
|
||||
(m.level == Error && !s_ShowError) ||
|
||||
(m.level == Debug && !s_ShowDebug) ||
|
||||
(m.level == Verbose && !s_ShowVerbose))
|
||||
continue;
|
||||
filtered.push_back(&m);
|
||||
}
|
||||
const ImGuiTableFlags tableFlags = ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg |
|
||||
ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersInnerV |
|
||||
ImGuiTableFlags_BordersOuterH;
|
||||
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin((int)filtered.size());
|
||||
while (clipper.Step())
|
||||
if (ImGui::BeginTable("LogMessages", 3, tableFlags))
|
||||
{
|
||||
for (int idx = clipper.DisplayStart; idx < clipper.DisplayEnd; idx++)
|
||||
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed, 120.0f);
|
||||
ImGui::TableSetupColumn("Timestamp", ImGuiTableColumnFlags_WidthFixed, 90.0f);
|
||||
ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
for (const auto& msg : s_Messages)
|
||||
{
|
||||
auto msg = filtered[idx];
|
||||
if ((msg.level == Ok && !s_ShowOk) ||
|
||||
(msg.level == Info && !s_ShowInfo) ||
|
||||
(msg.level == Warning && !s_ShowWarning) ||
|
||||
(msg.level == Error && !s_ShowError) ||
|
||||
(msg.level == Debug && !s_ShowDebug) ||
|
||||
(msg.level == Verbose && !s_ShowVerbose))
|
||||
continue;
|
||||
|
||||
if (filterBuf[0] != '\0' && std::string(msg.text).find(filterBuf) == std::string::npos)
|
||||
continue;
|
||||
|
||||
ImVec4 col;
|
||||
switch (msg->level)
|
||||
switch (msg.level)
|
||||
{
|
||||
case Ok:
|
||||
col = ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
|
||||
break;
|
||||
case Info:
|
||||
col = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
break;
|
||||
case Warning:
|
||||
col = ImVec4(1.0f, 0.85f, 0.3f, 1.0f);
|
||||
break;
|
||||
case Error:
|
||||
col = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
|
||||
break;
|
||||
case Debug:
|
||||
col = ImVec4(0.3f, 0.9f, 1.0f, 1.0f);
|
||||
break;
|
||||
case Verbose:
|
||||
col = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
break;
|
||||
default:
|
||||
col = ImVec4(1, 1, 1, 1);
|
||||
break;
|
||||
case Ok: col = ImVec4(0.6f, 1.0f, 0.6f, 1.0f); break;
|
||||
case Info: col = ImVec4(0.3f, 0.6f, 1.0f, 1.0f); break;
|
||||
case Warning: col = ImVec4(1.0f, 0.8f, 0.2f, 1.0f); break;
|
||||
case Error: col = ImVec4(1.0f, 0.2f, 0.2f, 1.0f); break;
|
||||
case Debug: col = ImVec4(0.2f, 1.0f, 1.0f, 1.0f); break;
|
||||
case Verbose: col = ImVec4(0.5f, 0.5f, 0.5f, 1.0f); break;
|
||||
default: col = ImVec4(1, 1, 1, 1); break;
|
||||
}
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, col);
|
||||
ImGui::Text("[%s] %s", ToString(msg->level), msg->text.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
clipper.End();
|
||||
ImGui::TableNextRow();
|
||||
|
||||
if (s_AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
|
||||
// --- Column 0: Type with vertical color bar ---
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImVec2 cursor = ImGui::GetCursorScreenPos();
|
||||
float barWidth = 4.0f;
|
||||
float textHeight = ImGui::GetTextLineHeight();
|
||||
ImVec2 barStart = cursor;
|
||||
ImVec2 barEnd = ImVec2(cursor.x + barWidth, cursor.y + textHeight);
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(barStart, barEnd, ImGui::ColorConvertFloat4ToU32(col), 1.0f);
|
||||
|
||||
ImGui::Dummy(ImVec2(barWidth + 6.0f, 0));
|
||||
ImGui::SameLine();
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, col);
|
||||
ImGui::TextUnformatted(ToString(msg.level));
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
// --- Column 1: Timestamp ---
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("%02d:%02d:%02d", msg.timestamp.hour, msg.timestamp.min, msg.timestamp.sec);
|
||||
|
||||
// --- Column 2: Message ---
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
ImGui::TextWrapped("%s", msg.text.c_str());
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
if (s_AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY() - 5.0f)
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,9 @@ private:
|
||||
{
|
||||
std::string text;
|
||||
Level level;
|
||||
struct {
|
||||
int hour, min, sec;
|
||||
} timestamp;
|
||||
};
|
||||
|
||||
static std::vector<LogMessage> s_Messages;
|
||||
|
Loading…
Reference in New Issue
Block a user