diff options
| author | fschildt <florian.schildt@protonmail.com> | 2026-01-24 00:55:57 +0100 |
|---|---|---|
| committer | fschildt <florian.schildt@protonmail.com> | 2026-01-24 01:11:31 +0100 |
| commit | 6cbc3e4ebd9c316672c49e43aa64e25e7ea05445 (patch) | |
| tree | d36203c1409fe4d64f849351fffea42c30bb07f5 /src/main.cpp | |
| parent | 58b09c254cb30ee47f30574aff5a489bf9f681a5 (diff) | |
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
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 <memory> #include <cstdlib> #include <assert.h> +#include <chrono> 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(); |
