# HG changeset patch # User Matti Hamalainen # Date 1604160857 -7200 # Node ID ff739727dfec322c0c5bc0e53b6cdc976862f038 # Parent 8b34eab13549448c1d04a9ba7bf66f763ef05b99 Compute and display frametime jitter values. diff -r 8b34eab13549 -r ff739727dfec gldragon.cpp --- 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;