Mercurial > hg > forks > gldragon
changeset 89:ff739727dfec
Compute and display frametime jitter values.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 31 Oct 2020 18:14:17 +0200 |
parents | 8b34eab13549 |
children | 3863ad92f8d8 |
files | gldragon.cpp |
diffstat | 1 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/gldragon.cpp Sun Oct 18 14:15:07 2020 +0300 +++ b/gldragon.cpp Sat Oct 31 18:14:17 2020 +0200 @@ -94,6 +94,8 @@ int main(int argc, char *argv[]) { + int frameDeltas[SET_FRAMES + 1]; + bool exitFlag = false, pauseFlag = false, @@ -114,6 +116,8 @@ totalTime = 0, totalFrames = 0; + memset(&frameDeltas, 0, sizeof(frameDeltas)); + // Check commandline argument for enabling shaders for (int narg = 1; narg < argc; narg++) { @@ -350,6 +354,7 @@ frameDelta = frameEnd - frameStart; + // Return true if a full rotation was done if (!pauseFlag) { @@ -359,11 +364,30 @@ cycleTime += frameDelta; totalTime += frameDelta; + memmove(&frameDeltas[0], &frameDeltas[1], sizeof(frameDeltas[0]) * (SET_FRAMES - 1)); + frameDeltas[SET_FRAMES - 1] = frameDelta; + if (cycleFrames >= SET_FRAMES) { + float avgCycleFrame = cycleTime / SET_FRAMES; + float maxJitter = 0, avgJitter = 0; + + for (int n = 0; n < SET_FRAMES; n++) + { + float mjitter = fabs(avgCycleFrame - frameDeltas[n]); + if (mjitter > maxJitter) + maxJitter = mjitter; + avgJitter += mjitter; + } + + avgJitter /= SET_FRAMES; + // Print the current frames per second - printf("%d ms for %d frames = %.1lf FPS\n", - cycleTime, cycleFrames, (cycleFrames * 1000.0f) / cycleTime); + printf("%d ms for %d frames = %.1lf FPS [framejitter %.1lf ms avg, %.1lf ms max]\n", + cycleTime, cycleFrames, + (cycleFrames * 1000.0f) / cycleTime, + avgJitter, maxJitter + ); // Reset cycleFrames cycleFrames = 0;