comparison test/testtimer.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
11 #define DEFAULT_RESOLUTION 1 11 #define DEFAULT_RESOLUTION 1
12 12
13 static int ticks = 0; 13 static int ticks = 0;
14 14
15 static Uint32 SDLCALL 15 static Uint32 SDLCALL
16 ticktock (Uint32 interval) 16 ticktock(Uint32 interval)
17 { 17 {
18 ++ticks; 18 ++ticks;
19 return (interval); 19 return (interval);
20 } 20 }
21 21
22 static Uint32 SDLCALL 22 static Uint32 SDLCALL
23 callback (Uint32 interval, void *param) 23 callback(Uint32 interval, void *param)
24 { 24 {
25 printf ("Timer %d : param = %d\n", interval, (int) (uintptr_t) param); 25 printf("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
26 return interval; 26 return interval;
27 } 27 }
28 28
29 int 29 int
30 main (int argc, char *argv[]) 30 main(int argc, char *argv[])
31 { 31 {
32 int desired; 32 int desired;
33 SDL_TimerID t1, t2, t3; 33 SDL_TimerID t1, t2, t3;
34 34
35 if (SDL_Init (SDL_INIT_TIMER) < 0) { 35 if (SDL_Init(SDL_INIT_TIMER) < 0) {
36 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); 36 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
37 return (1); 37 return (1);
38 } 38 }
39 39
40 /* Start the timer */ 40 /* Start the timer */
41 desired = 0; 41 desired = 0;
42 if (argv[1]) { 42 if (argv[1]) {
43 desired = atoi (argv[1]); 43 desired = atoi(argv[1]);
44 } 44 }
45 if (desired == 0) { 45 if (desired == 0) {
46 desired = DEFAULT_RESOLUTION; 46 desired = DEFAULT_RESOLUTION;
47 } 47 }
48 SDL_SetTimer (desired, ticktock); 48 SDL_SetTimer(desired, ticktock);
49 49
50 /* Wait 10 seconds */ 50 /* Wait 10 seconds */
51 printf ("Waiting 10 seconds\n"); 51 printf("Waiting 10 seconds\n");
52 SDL_Delay (10 * 1000); 52 SDL_Delay(10 * 1000);
53 53
54 /* Stop the timer */ 54 /* Stop the timer */
55 SDL_SetTimer (0, NULL); 55 SDL_SetTimer(0, NULL);
56 56
57 /* Print the results */ 57 /* Print the results */
58 if (ticks) { 58 if (ticks) {
59 fprintf (stderr, 59 fprintf(stderr,
60 "Timer resolution: desired = %d ms, actual = %f ms\n", 60 "Timer resolution: desired = %d ms, actual = %f ms\n",
61 desired, (double) (10 * 1000) / ticks); 61 desired, (double) (10 * 1000) / ticks);
62 } 62 }
63 63
64 /* Test multiple timers */ 64 /* Test multiple timers */
65 printf ("Testing multiple timers...\n"); 65 printf("Testing multiple timers...\n");
66 t1 = SDL_AddTimer (100, callback, (void *) 1); 66 t1 = SDL_AddTimer(100, callback, (void *) 1);
67 if (!t1) 67 if (!t1)
68 fprintf (stderr, "Could not create timer 1: %s\n", SDL_GetError ()); 68 fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError());
69 t2 = SDL_AddTimer (50, callback, (void *) 2); 69 t2 = SDL_AddTimer(50, callback, (void *) 2);
70 if (!t2) 70 if (!t2)
71 fprintf (stderr, "Could not create timer 2: %s\n", SDL_GetError ()); 71 fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError());
72 t3 = SDL_AddTimer (233, callback, (void *) 3); 72 t3 = SDL_AddTimer(233, callback, (void *) 3);
73 if (!t3) 73 if (!t3)
74 fprintf (stderr, "Could not create timer 3: %s\n", SDL_GetError ()); 74 fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError());
75 75
76 /* Wait 10 seconds */ 76 /* Wait 10 seconds */
77 printf ("Waiting 10 seconds\n"); 77 printf("Waiting 10 seconds\n");
78 SDL_Delay (10 * 1000); 78 SDL_Delay(10 * 1000);
79 79
80 printf ("Removing timer 1 and waiting 5 more seconds\n"); 80 printf("Removing timer 1 and waiting 5 more seconds\n");
81 SDL_RemoveTimer (t1); 81 SDL_RemoveTimer(t1);
82 82
83 SDL_Delay (5 * 1000); 83 SDL_Delay(5 * 1000);
84 84
85 SDL_RemoveTimer (t2); 85 SDL_RemoveTimer(t2);
86 SDL_RemoveTimer (t3); 86 SDL_RemoveTimer(t3);
87 87
88 SDL_Quit (); 88 SDL_Quit();
89 return (0); 89 return (0);
90 } 90 }