test/testtimer.c
changeset 7316 c3052ed2c310
parent 7288 d9fcd19ec866
child 7448 c1f9032d0634
     1.1 --- a/test/testtimer.c	Sun Jun 23 15:00:23 2013 -0700
     1.2 +++ b/test/testtimer.c	Sun Jun 23 22:19:38 2013 -0700
     1.3 @@ -14,16 +14,6 @@
     1.4     platform
     1.5  */
     1.6  
     1.7 -#if 1 /* FIXME: Rework this using the 2.0 API */
     1.8 -#include <stdio.h>
     1.9 -#include "SDL.h"
    1.10 -
    1.11 -int main(int argc, char *argv[])
    1.12 -{
    1.13 -    printf("FIXME\n");
    1.14 -    return 0;
    1.15 -}
    1.16 -#else
    1.17  #include <stdlib.h>
    1.18  #include <stdio.h>
    1.19  
    1.20 @@ -34,7 +24,7 @@
    1.21  static int ticks = 0;
    1.22  
    1.23  static Uint32 SDLCALL
    1.24 -ticktock(Uint32 interval)
    1.25 +ticktock(Uint32 interval, void *param)
    1.26  {
    1.27      ++ticks;
    1.28      return (interval);
    1.29 @@ -52,6 +42,7 @@
    1.30  {
    1.31      int i, desired;
    1.32      SDL_TimerID t1, t2, t3;
    1.33 +    Uint32 start32, now32;
    1.34      Uint64 start, now;
    1.35  
    1.36      if (SDL_Init(SDL_INIT_TIMER) < 0) {
    1.37 @@ -67,14 +58,14 @@
    1.38      if (desired == 0) {
    1.39          desired = DEFAULT_RESOLUTION;
    1.40      }
    1.41 -    SDL_SetTimer(desired, ticktock);
    1.42 +    t1 = SDL_AddTimer(desired, ticktock, NULL);
    1.43  
    1.44      /* Wait 10 seconds */
    1.45      printf("Waiting 10 seconds\n");
    1.46      SDL_Delay(10 * 1000);
    1.47  
    1.48      /* Stop the timer */
    1.49 -    SDL_SetTimer(0, NULL);
    1.50 +    SDL_RemoveTimer(t1);
    1.51  
    1.52      /* Print the results */
    1.53      if (ticks) {
    1.54 @@ -109,14 +100,21 @@
    1.55  
    1.56      start = SDL_GetPerformanceCounter();
    1.57      for (i = 0; i < 1000000; ++i) {
    1.58 -        ticktock(0);
    1.59 +        ticktock(0, NULL);
    1.60      }
    1.61      now = SDL_GetPerformanceCounter();
    1.62      printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
    1.63  
    1.64 +    printf("Performance counter frequency: %lld\n", SDL_GetPerformanceFrequency());
    1.65 +    start32 = SDL_GetTicks();
    1.66 +    start = SDL_GetPerformanceCounter();
    1.67 +    SDL_Delay(1000);
    1.68 +    now = SDL_GetPerformanceCounter();
    1.69 +    now32 = SDL_GetTicks();
    1.70 +    printf("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
    1.71 +
    1.72      SDL_Quit();
    1.73      return (0);
    1.74  }
    1.75 -#endif
    1.76  
    1.77  /* vi: set ts=4 sw=4 expandtab: */