From 940c1d706bc5330eead7116d5e006b994f92b707 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Mon, 29 Jan 2024 00:21:14 +0000 Subject: [PATCH] main/debug: Make the frame timing graph a sliding window Use memmove to shift the whole array by one measure to the left, dropping the oldest one and adding a new one at the head. This creates a better visual effect of a graph being produced on the right and scrolling to the left, rather than a looping writing head that overwrites previous data. --- main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 3f91470..0aedcd7 100644 --- a/main.cpp +++ b/main.cpp @@ -115,7 +115,12 @@ int main() ImGui::SetNextWindowBgAlpha(0.2f); ImGui::Begin("FPS", nullptr ,window_flags); if (fpsDataClock.getElapsedTime().asMilliseconds() > 20) { - frameTimings[frameCount%100] = static_cast(deltaT.asMicroseconds()); + if (frameCount >= 100) { + memmove(frameTimings, frameTimings + 1, 99 * sizeof(float)); + frameTimings[99] = static_cast(deltaT.asMicroseconds()); + } else [[unlikely]] { + frameTimings[frameCount] = static_cast(deltaT.asMicroseconds()); + } frameCount++; fpsDataClock.restart(); }