Mercurial > hg > forks > gldragon
comparison gldragon.cpp @ 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 | 28dd29f3a65f |
comparison
equal
deleted
inserted
replaced
88:8b34eab13549 | 89:ff739727dfec |
---|---|
92 } | 92 } |
93 | 93 |
94 | 94 |
95 int main(int argc, char *argv[]) | 95 int main(int argc, char *argv[]) |
96 { | 96 { |
97 int frameDeltas[SET_FRAMES + 1]; | |
98 | |
97 bool | 99 bool |
98 exitFlag = false, | 100 exitFlag = false, |
99 pauseFlag = false, | 101 pauseFlag = false, |
100 optShowHelp = false, | 102 optShowHelp = false, |
101 optSetInputFilename = false, | 103 optSetInputFilename = false, |
111 DMSimpleScene scene; | 113 DMSimpleScene scene; |
112 int cycleTime = 0, | 114 int cycleTime = 0, |
113 cycleFrames = 0, | 115 cycleFrames = 0, |
114 totalTime = 0, | 116 totalTime = 0, |
115 totalFrames = 0; | 117 totalFrames = 0; |
118 | |
119 memset(&frameDeltas, 0, sizeof(frameDeltas)); | |
116 | 120 |
117 // Check commandline argument for enabling shaders | 121 // Check commandline argument for enabling shaders |
118 for (int narg = 1; narg < argc; narg++) | 122 for (int narg = 1; narg < argc; narg++) |
119 { | 123 { |
120 char *arg = argv[narg]; | 124 char *arg = argv[narg]; |
348 // Check for errors | 352 // Check for errors |
349 renderer.checkErrors(); | 353 renderer.checkErrors(); |
350 | 354 |
351 frameDelta = frameEnd - frameStart; | 355 frameDelta = frameEnd - frameStart; |
352 | 356 |
357 | |
353 // Return true if a full rotation was done | 358 // Return true if a full rotation was done |
354 if (!pauseFlag) | 359 if (!pauseFlag) |
355 { | 360 { |
356 totalFrames++; | 361 totalFrames++; |
357 cycleFrames++; | 362 cycleFrames++; |
358 | 363 |
359 cycleTime += frameDelta; | 364 cycleTime += frameDelta; |
360 totalTime += frameDelta; | 365 totalTime += frameDelta; |
361 | 366 |
367 memmove(&frameDeltas[0], &frameDeltas[1], sizeof(frameDeltas[0]) * (SET_FRAMES - 1)); | |
368 frameDeltas[SET_FRAMES - 1] = frameDelta; | |
369 | |
362 if (cycleFrames >= SET_FRAMES) | 370 if (cycleFrames >= SET_FRAMES) |
363 { | 371 { |
372 float avgCycleFrame = cycleTime / SET_FRAMES; | |
373 float maxJitter = 0, avgJitter = 0; | |
374 | |
375 for (int n = 0; n < SET_FRAMES; n++) | |
376 { | |
377 float mjitter = fabs(avgCycleFrame - frameDeltas[n]); | |
378 if (mjitter > maxJitter) | |
379 maxJitter = mjitter; | |
380 avgJitter += mjitter; | |
381 } | |
382 | |
383 avgJitter /= SET_FRAMES; | |
384 | |
364 // Print the current frames per second | 385 // Print the current frames per second |
365 printf("%d ms for %d frames = %.1lf FPS\n", | 386 printf("%d ms for %d frames = %.1lf FPS [framejitter %.1lf ms avg, %.1lf ms max]\n", |
366 cycleTime, cycleFrames, (cycleFrames * 1000.0f) / cycleTime); | 387 cycleTime, cycleFrames, |
388 (cycleFrames * 1000.0f) / cycleTime, | |
389 avgJitter, maxJitter | |
390 ); | |
367 | 391 |
368 // Reset cycleFrames | 392 // Reset cycleFrames |
369 cycleFrames = 0; | 393 cycleFrames = 0; |
370 cycleTime = 0; | 394 cycleTime = 0; |
371 } | 395 } |