X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=main.cpp;h=8389cad581768dea43cea63d865797332c5161f0;hp=580989e5f7bdac06198ba162a9b97a16609fbb0a;hb=2e4309fd8af9ca0a3656a584f8ed8b3fc634263f;hpb=994ac0c108d8e0f1d1effcad5ba8b4c2d1dd9d28 diff --git a/main.cpp b/main.cpp index 580989e..8389cad 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -92,7 +93,7 @@ unsigned char *load_image(const char *filename, unsigned *w, unsigned *h) SDL_LockSurface(img); unsigned char *src_pixels = (unsigned char *)img->pixels; unsigned char *dst_pixels = (unsigned char *)malloc(img->w * img->h * 3); - for (unsigned i = 0; i < img->w * img->h; ++i) { + for (int i = 0; i < img->w * img->h; ++i) { unsigned char r, g, b; unsigned int temp; unsigned int pixel = *(unsigned int *)(src_pixels + i * fmt->BytesPerPixel); @@ -227,9 +228,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 +286,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);