1
0
Fork 0

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.
This commit is contained in:
Teo-CD 2024-01-29 00:21:14 +00:00
parent 41437cd259
commit 940c1d706b

View file

@ -115,7 +115,12 @@ int main()
ImGui::SetNextWindowBgAlpha(0.2f); ImGui::SetNextWindowBgAlpha(0.2f);
ImGui::Begin("FPS", nullptr ,window_flags); ImGui::Begin("FPS", nullptr ,window_flags);
if (fpsDataClock.getElapsedTime().asMilliseconds() > 20) { if (fpsDataClock.getElapsedTime().asMilliseconds() > 20) {
frameTimings[frameCount%100] = static_cast<float>(deltaT.asMicroseconds()); if (frameCount >= 100) {
memmove(frameTimings, frameTimings + 1, 99 * sizeof(float));
frameTimings[99] = static_cast<float>(deltaT.asMicroseconds());
} else [[unlikely]] {
frameTimings[frameCount] = static_cast<float>(deltaT.asMicroseconds());
}
frameCount++; frameCount++;
fpsDataClock.restart(); fpsDataClock.restart();
} }