Mercurial > sdl-ios-xcode
comparison test/testtimer.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
10 | 10 |
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 ticktock(Uint32 interval) | 15 static Uint32 SDLCALL |
16 ticktock (Uint32 interval) | |
16 { | 17 { |
17 ++ticks; | 18 ++ticks; |
18 return(interval); | 19 return (interval); |
19 } | 20 } |
20 | 21 |
21 static Uint32 SDLCALL callback(Uint32 interval, void *param) | 22 static Uint32 SDLCALL |
23 callback (Uint32 interval, void *param) | |
22 { | 24 { |
23 printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param); | 25 printf ("Timer %d : param = %d\n", interval, (int) (uintptr_t) param); |
24 return interval; | 26 return interval; |
25 } | 27 } |
26 | 28 |
27 int main(int argc, char *argv[]) | 29 int |
30 main (int argc, char *argv[]) | |
28 { | 31 { |
29 int desired; | 32 int desired; |
30 SDL_TimerID t1, t2, t3; | 33 SDL_TimerID t1, t2, t3; |
31 | 34 |
32 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) { | 35 if (SDL_Init (SDL_INIT_TIMER) < 0) { |
33 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); | 36 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
34 return(1); | 37 return (1); |
35 } | 38 } |
36 | 39 |
37 /* Start the timer */ | 40 /* Start the timer */ |
38 desired = 0; | 41 desired = 0; |
39 if ( argv[1] ) { | 42 if (argv[1]) { |
40 desired = atoi(argv[1]); | 43 desired = atoi (argv[1]); |
41 } | 44 } |
42 if ( desired == 0 ) { | 45 if (desired == 0) { |
43 desired = DEFAULT_RESOLUTION; | 46 desired = DEFAULT_RESOLUTION; |
44 } | 47 } |
45 SDL_SetTimer(desired, ticktock); | 48 SDL_SetTimer (desired, ticktock); |
46 | 49 |
47 /* Wait 10 seconds */ | 50 /* Wait 10 seconds */ |
48 printf("Waiting 10 seconds\n"); | 51 printf ("Waiting 10 seconds\n"); |
49 SDL_Delay(10*1000); | 52 SDL_Delay (10 * 1000); |
50 | 53 |
51 /* Stop the timer */ | 54 /* Stop the timer */ |
52 SDL_SetTimer(0, NULL); | 55 SDL_SetTimer (0, NULL); |
53 | 56 |
54 /* Print the results */ | 57 /* Print the results */ |
55 if ( ticks ) { | 58 if (ticks) { |
56 fprintf(stderr, | 59 fprintf (stderr, |
57 "Timer resolution: desired = %d ms, actual = %f ms\n", | 60 "Timer resolution: desired = %d ms, actual = %f ms\n", |
58 desired, (double)(10*1000)/ticks); | 61 desired, (double) (10 * 1000) / ticks); |
59 } | 62 } |
60 | |
61 /* Test multiple timers */ | |
62 printf("Testing multiple timers...\n"); | |
63 t1 = SDL_AddTimer(100, callback, (void*)1); | |
64 if(!t1) | |
65 fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError()); | |
66 t2 = SDL_AddTimer(50, callback, (void*)2); | |
67 if(!t2) | |
68 fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError()); | |
69 t3 = SDL_AddTimer(233, callback, (void*)3); | |
70 if(!t3) | |
71 fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError()); | |
72 | |
73 /* Wait 10 seconds */ | |
74 printf("Waiting 10 seconds\n"); | |
75 SDL_Delay(10*1000); | |
76 | 63 |
77 printf("Removing timer 1 and waiting 5 more seconds\n"); | 64 /* Test multiple timers */ |
78 SDL_RemoveTimer(t1); | 65 printf ("Testing multiple timers...\n"); |
66 t1 = SDL_AddTimer (100, callback, (void *) 1); | |
67 if (!t1) | |
68 fprintf (stderr, "Could not create timer 1: %s\n", SDL_GetError ()); | |
69 t2 = SDL_AddTimer (50, callback, (void *) 2); | |
70 if (!t2) | |
71 fprintf (stderr, "Could not create timer 2: %s\n", SDL_GetError ()); | |
72 t3 = SDL_AddTimer (233, callback, (void *) 3); | |
73 if (!t3) | |
74 fprintf (stderr, "Could not create timer 3: %s\n", SDL_GetError ()); | |
79 | 75 |
80 SDL_Delay(5*1000); | 76 /* Wait 10 seconds */ |
77 printf ("Waiting 10 seconds\n"); | |
78 SDL_Delay (10 * 1000); | |
81 | 79 |
82 SDL_RemoveTimer(t2); | 80 printf ("Removing timer 1 and waiting 5 more seconds\n"); |
83 SDL_RemoveTimer(t3); | 81 SDL_RemoveTimer (t1); |
84 | 82 |
85 SDL_Quit(); | 83 SDL_Delay (5 * 1000); |
86 return(0); | 84 |
85 SDL_RemoveTimer (t2); | |
86 SDL_RemoveTimer (t3); | |
87 | |
88 SDL_Quit (); | |
89 return (0); | |
87 } | 90 } |