From 40b66ccabf2c2f448504a41909ff2dda80212af4 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 2 Oct 2012 01:10:40 +0200 Subject: [PATCH] Add fallbacks for systems without proper monotonic clocks (e.g. OS X). --- main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 9a9a3ea..93f8c0c 100644 --- a/main.cpp +++ b/main.cpp @@ -227,9 +227,14 @@ int main(int argc, char **argv) make_hsv_wheel_texture(); - struct timespec start, now; int frame = 0, screenshot = 0; +#if _POSIX_C_SOURCE >= 199309L + struct timespec start, now; clock_gettime(CLOCK_MONOTONIC, &start); +#else + struct timeval start, now; + gettimeofday(&start, NULL); +#endif while (!quit) { SDL_Event event; @@ -280,9 +285,15 @@ int main(int argc, char **argv) check_error(); #if 1 +#if _POSIX_C_SOURCE >= 199309L clock_gettime(CLOCK_MONOTONIC, &now); double elapsed = now.tv_sec - start.tv_sec + 1e-9 * (now.tv_nsec - start.tv_nsec); +#else + gettimeofday(&now, NULL); + double elapsed = now.tv_sec - start.tv_sec + + 1e-6 * (now.tv_usec - start.tv_usec); +#endif printf("%d frames in %.3f seconds = %.1f fps (%.1f ms/frame)\n", frame, elapsed, frame / elapsed, 1e3 * elapsed / frame); -- 2.39.2