Minor update - Log window in Ui

This commit is contained in:
CatChow0 2025-01-17 17:57:58 +01:00
parent 4ae55e73b2
commit cb3f10b7d5
5 changed files with 154 additions and 25 deletions

View File

@ -40,6 +40,12 @@ public:
Debug
};
struct LogEntry
{
std::string message;
LogLevel level;
};
Logger()
{
char* appdata = nullptr;
@ -134,6 +140,8 @@ public:
<< "[" << fileName << ":" << lineNumber << "] "
<< message;
SendLogToUI(ss.str(), level);
std::ofstream file(m_logFilePath, std::ios::app);
if (file.is_open())
{
@ -142,6 +150,16 @@ public:
}
}
void SendLogToUI(const std::string& message, LogLevel level)
{
m_logs.push_back({ message, level });
}
const std::vector<LogEntry>& GetLogs() const
{
return m_logs;
}
void ManageLogFiles(const std::string& directoryPath)
{
std::vector<std::filesystem::path> logFiles;
@ -189,4 +207,5 @@ private:
std::string m_appdataPath;
std::string m_logFileName;
std::string m_logFilePath;
std::vector<LogEntry> m_logs;
};

View File

@ -1956,10 +1956,10 @@ bool ApplicationClass::RenderPhysics(bool keyLeft, bool keyRight, bool keyUp, bo
float forceX = 0, forceY = 0, forceZ = 0, forceW = 0;
if (keyLeft) {
forceX = -10.0f;
forceX = -40.0f;
}
if (keyRight) {
forceX = 10.0f;
forceX = 40.0f;
}
if (keyUp) {
forceY = 40.0f;

View File

@ -4,22 +4,22 @@ Size=400,400
Collapsed=0
[Window][Khaotic Engine]
Pos=1537,27
Size=375,974
Pos=1180,27
Size=396,489
Collapsed=0
DockId=0x00000005,0
[Window][Objects]
Pos=8,516
Size=330,485
Pos=8,442
Size=395,411
Collapsed=0
DockId=0x00000006,0
DockId=0x0000000A,0
[Window][Terrain]
Pos=8,27
Size=330,487
Size=290,489
Collapsed=0
DockId=0x00000004,0
DockId=0x00000009,0
[Window][Light]
Pos=8,27
@ -34,28 +34,50 @@ Collapsed=0
DockId=0x00000004,2
[Window][Engine Settings]
Pos=1537,27
Size=375,974
Pos=1180,27
Size=396,489
Collapsed=0
DockId=0x00000005,1
[Window][DockSpace Demo]
Pos=0,0
Size=1920,1009
Size=1584,861
Collapsed=0
[Window][Render Window]
Pos=340,27
Size=1195,974
Pos=8,27
Size=1170,489
Collapsed=0
DockId=0x00000002,0
[Docking][Data]
DockSpace ID=0xC0DFADC4 Window=0xD0388BC8 Pos=8,27 Size=1904,974 Split=X
DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Split=Y Selected=0x393905AB
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=330,487 Selected=0x393905AB
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=330,485 Selected=0x031DC75C
DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 Split=X
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1655,1094 CentralNode=1 Selected=0x9204953B
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=375,1094 Selected=0x9F035453
[Window][DockSpace]
Pos=0,0
Size=1584,861
Collapsed=0
[Window][Add Object]
Pos=1188,0
Size=396,430
Collapsed=0
[Window][Log]
Pos=8,518
Size=1568,335
Collapsed=0
DockId=0x0000000C,0
[Docking][Data]
DockSpace ID=0xC0DFADC4 Pos=8,27 Size=1568,826 Split=X
DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Split=Y Selected=0x393905AB
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=330,487 Selected=0x393905AB
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=330,485 Selected=0x031DC75C
DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 CentralNode=1
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=1568,826 Split=Y
DockNode ID=0x0000000B Parent=0xCCBD8CF7 SizeRef=1568,637 Split=X
DockNode ID=0x00000007 Parent=0x0000000B SizeRef=290,826 Split=Y Selected=0x393905AB
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=395,413 Selected=0x393905AB
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=395,411 Selected=0x031DC75C
DockNode ID=0x00000008 Parent=0x0000000B SizeRef=1276,826 Split=X
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=878,826 CentralNode=1 Selected=0x9204953B
DockNode ID=0x00000005 Parent=0x00000008 SizeRef=396,826 Selected=0x9F035453
DockNode ID=0x0000000C Parent=0xCCBD8CF7 SizeRef=1568,335 Selected=0x139FDA3F

View File

@ -66,10 +66,10 @@ void imguiManager::SetupDockspace() {
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
ImGui::Begin("DockSpace Demo", nullptr, window_flags);
ImGui::Begin("DockSpace", nullptr, window_flags);
ImGui::PopStyleVar(2);
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::End();
@ -388,6 +388,11 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
showEngineSettingsWindow = true;
}
if (ImGui::Button("Open Log Window"))
{
showLogWindow = true;
}
ImGui::End();
// Show windows if their corresponding variables are true
@ -416,6 +421,11 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
WidgetEngineSettingsWindow(app);
}
if (showLogWindow)
{
WidgetLogWindow(app);
}
WidgetRenderWindow(app, ImVec2(800, 600));
//render imgui
@ -463,6 +473,9 @@ void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
{
ImGui::Begin("Engine Settings", &showEngineSettingsWindow);
// Begining Of General Setting
ImGui::Text("General");
// Checkbox for toggling vsync globally in the application class by calling the SetVsync function in the application class when the checkbox state changes
bool vsync = app->GetVsync();
if (ImGui::Checkbox("Vsync", &vsync))
@ -470,6 +483,11 @@ void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
app->SetVsync(vsync);
}
// End Of General Setting
ImGui::Separator();
// culling section
ImGui::Text("Culling");
// float input for frustum tolerance
float frustumTolerance = app->GetFrustumTolerance();
if (ImGui::DragFloat("Frustum Tolerance", &frustumTolerance, 0.1f, 0.0f, 100.0f))
@ -477,6 +495,12 @@ void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
app->SetFrustumTolerance(frustumTolerance);
}
// End Of Culling Setting
ImGui::Separator();
// Physics section
ImGui::Text("Physics");
// Input To set the Fixed Update Interval
int physicsInterval = app->GetPhysicsTickRate();
if (ImGui::InputInt("Physics Tick Rate", &physicsInterval))
@ -484,9 +508,71 @@ void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
app->SetPhysicsTickRate(physicsInterval);
}
// Input to change the gravity on same line
XMVECTOR gravity = app->GetPhysics()->GetGravity();
float gravityValues[3] = { XMVectorGetX(gravity), XMVectorGetY(gravity), XMVectorGetZ(gravity) };
if (ImGui::DragFloat3("Gravity", gravityValues))
{
app->GetPhysics()->SetGravity(XMVectorSet(gravityValues[0], gravityValues[1], gravityValues[2], 0.0f));
}
ImGui::End();
}
void imguiManager::WidgetLogWindow(ApplicationClass* app)
{
ImGui::Begin("Log", &showLogWindow);
// Récupérer les logs depuis le Logger
const std::vector<Logger::LogEntry>& logs = Logger::Get().GetLogs();
// Afficher les logs dans ImGui
for (const auto& log : logs)
{
switch (log.level)
{
case Logger::LogLevel::Info:
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 1.0f, 0.0f, 1.0f)); // Vert pour les messages d'info
break;
case Logger::LogLevel::Shutdown:
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 0.0f, 0.0f, 1.0f)); // Rouge sombre pour les messages de shutdown
break;
case Logger::LogLevel::Error:
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); // Rouge pour les messages d'erreur
break;
case Logger::LogLevel::Debug:
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 1.0f, 1.0f)); // Bleu pour les messages de debug
break;
case Logger::LogLevel::Initialize:
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 0.0f, 1.0f)); // Jaune pour les messages d'initialisation
break;
default:
break;
}
ImGui::TextUnformatted(log.message.c_str());
if (log.level == Logger::LogLevel::Info ||
log.level == Logger::LogLevel::Shutdown ||
log.level == Logger::LogLevel::Error ||
log.level == Logger::LogLevel::Debug ||
log.level == Logger::LogLevel::Initialize)
{
ImGui::PopStyleColor();
}
}
// Scroll to the bottom of the log window
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
{
ImGui::SetScrollHereY(1.0f);
}
ImGui::End();
}
void imguiManager::WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize)
{
ImGui::Begin("Render Window");

View File

@ -35,6 +35,7 @@ public:
void WidgetShaderWindow(ApplicationClass* app);
void WidgetEngineSettingsWindow(ApplicationClass* app);
void WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize);
void WidgetLogWindow(ApplicationClass* app);
bool ImGuiWidgetRenderer(ApplicationClass* app);
@ -51,6 +52,7 @@ private :
bool showLightWindow = false;
bool showShaderWindow = false;
bool showEngineSettingsWindow = false;
bool showLogWindow = false;
bool m_isPhyiscsEnabled = false;