From 6cbc3e4ebd9c316672c49e43aa64e25e7ea05445 Mon Sep 17 00:00:00 2001 From: fschildt Date: Sat, 24 Jan 2026 00:55:57 +0100 Subject: main: always draw performance info, add load stats --- src/main.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index ebbaa55..ebf018d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include Game::GameType @@ -46,14 +47,17 @@ DrawGameMenu() void -DrawPerformanceInfo() +DrawPerformanceInfo(float ms_used) { ImGuiIO& io = ImGui::GetIO(); ImGuiWindowFlags flags = ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x - 200, 0)); + float ms_per_frame = 1000.0f / io.Framerate; + float load = (ms_used / ms_per_frame) * 100; + + ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x - 350, 0)); ImGui::Begin("Performance", nullptr, flags); - ImGui::Text("%.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::Text("%.2f ms/frame (%.2f %%) | %.2f ms/frame (%.f FPS)", ms_used, load, ms_per_frame, io.Framerate); ImGui::End(); } @@ -144,6 +148,8 @@ main(int argc, char** argv) ImGui::NewFrame(); + auto start_time = std::chrono::high_resolution_clock::now(); + size_t cur_game_events = 0; size_t max_game_events = game_events.max_size(); @@ -187,13 +193,19 @@ main(int argc, char** argv) game = Game::Select(type); } } + game_events.clear(); + g_renderer.Draw(); + + auto end_time = std::chrono::high_resolution_clock::now(); + float ms_used = float((end_time - start_time) / std::chrono::microseconds(1)) / 1000; + DrawPerformanceInfo(ms_used); - g_renderer.Draw(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + SDL_GL_SwapWindow(window); g_renderer.Reset(); MemoryManager::Clear_Frame(); -- cgit v1.2.3