Mercurial > sdl-ios-xcode
comparison src/timer/macos/SDL_systimer.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 |
---|---|
38 | 38 |
39 #if TARGET_API_MAC_CARBON | 39 #if TARGET_API_MAC_CARBON |
40 #define NewTimerProc NewTimerUPP | 40 #define NewTimerProc NewTimerUPP |
41 #endif | 41 #endif |
42 | 42 |
43 #define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ | 43 #define MS_PER_TICK (1000.0/60.0) /* MacOS tick = 1/60 second */ |
44 | 44 |
45 | 45 |
46 #define kTwoPower32 (4294967296.0) /* 2^32 */ | 46 #define kTwoPower32 (4294967296.0) /* 2^32 */ |
47 | 47 |
48 static double start_tick; | 48 static double start_tick; |
49 static int is_fast_inited = 0; | 49 static int is_fast_inited = 0; |
50 | 50 |
51 void SDL_StartTicks(void) | 51 void |
52 SDL_StartTicks (void) | |
52 { | 53 { |
53 if ( ! is_fast_inited ) // important to check or FastTime may hang machine! | 54 if (!is_fast_inited) // important to check or FastTime may hang machine! |
54 SDL_SYS_TimerInit(); | 55 SDL_SYS_TimerInit (); |
55 | 56 |
56 start_tick = FastMicroseconds(); | 57 start_tick = FastMicroseconds (); |
57 } | 58 } |
58 | 59 |
59 Uint32 SDL_GetTicks(void) | 60 Uint32 |
61 SDL_GetTicks (void) | |
60 { | 62 { |
61 | 63 |
62 if ( ! is_fast_inited ) | 64 if (!is_fast_inited) |
63 SDL_SYS_TimerInit(); | 65 SDL_SYS_TimerInit (); |
64 | 66 |
65 return FastMilliseconds(); | 67 return FastMilliseconds (); |
66 } | 68 } |
67 | 69 |
68 void SDL_Delay(Uint32 ms) | 70 void |
71 SDL_Delay (Uint32 ms) | |
69 { | 72 { |
70 Uint32 stop, now; | 73 Uint32 stop, now; |
71 | 74 |
72 stop = SDL_GetTicks() + ms; | 75 stop = SDL_GetTicks () + ms; |
73 do { | 76 do { |
74 #if TARGET_API_MAC_CARBON | 77 #if TARGET_API_MAC_CARBON |
75 MPYield(); | 78 MPYield (); |
76 #else | 79 #else |
77 SystemTask(); | 80 SystemTask (); |
78 #endif | 81 #endif |
79 | 82 |
80 now = SDL_GetTicks(); | 83 now = SDL_GetTicks (); |
81 | 84 |
82 } while ( stop > now ); | 85 } |
86 while (stop > now); | |
83 } | 87 } |
84 | 88 |
85 /* | 89 /* |
86 void SDL_StartTicks(void) | 90 void SDL_StartTicks(void) |
87 { | 91 { |
113 | 117 |
114 Microseconds (µsecs); | 118 Microseconds (µsecs); |
115 } | 119 } |
116 | 120 |
117 }*/ | 121 }*/ |
118 | 122 |
119 /* Data to handle a single periodic alarm */ | 123 /* Data to handle a single periodic alarm */ |
120 typedef struct _ExtendedTimerRec | 124 typedef struct _ExtendedTimerRec |
121 { | 125 { |
122 TMTask tmTask; | 126 TMTask tmTask; |
123 ProcessSerialNumber taskPSN; | 127 ProcessSerialNumber taskPSN; |
124 } ExtendedTimerRec, *ExtendedTimerPtr; | 128 } ExtendedTimerRec, *ExtendedTimerPtr; |
125 | 129 |
126 static ExtendedTimerRec gExtendedTimerRec; | 130 static ExtendedTimerRec gExtendedTimerRec; |
127 | 131 |
128 | 132 |
129 int SDL_SYS_TimerInit(void) | 133 int |
134 SDL_SYS_TimerInit (void) | |
130 { | 135 { |
131 FastInitialize (); | 136 FastInitialize (); |
132 is_fast_inited = 1; | 137 is_fast_inited = 1; |
133 | 138 |
134 return(0); | 139 return (0); |
135 } | 140 } |
136 | 141 |
137 void SDL_SYS_TimerQuit(void) | 142 void |
143 SDL_SYS_TimerQuit (void) | |
138 { | 144 { |
139 /* We don't need a cleanup? */ | 145 /* We don't need a cleanup? */ |
140 return; | 146 return; |
141 } | 147 } |
142 | 148 |
143 /* Our Stub routine to set up and then call the real routine. */ | 149 /* Our Stub routine to set up and then call the real routine. */ |
144 pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | 150 pascal void |
151 TimerCallbackProc (TMTaskPtr tmTaskPtr) | |
145 { | 152 { |
146 Uint32 ms; | 153 Uint32 ms; |
147 | 154 |
148 WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | 155 WakeUpProcess (&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); |
149 | 156 |
150 ms = SDL_alarm_callback(SDL_alarm_interval); | 157 ms = SDL_alarm_callback (SDL_alarm_interval); |
151 if ( ms ) { | 158 if (ms) { |
152 SDL_alarm_interval = ROUND_RESOLUTION(ms); | 159 SDL_alarm_interval = ROUND_RESOLUTION (ms); |
153 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | 160 PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); |
154 SDL_alarm_interval); | 161 } else { |
155 } else { | 162 SDL_alarm_interval = 0; |
156 SDL_alarm_interval = 0; | 163 } |
157 } | |
158 } | 164 } |
159 | 165 |
160 int SDL_SYS_StartTimer(void) | 166 int |
167 SDL_SYS_StartTimer (void) | |
161 { | 168 { |
162 /* | 169 /* |
163 * Configure the global structure that stores the timing information. | 170 * Configure the global structure that stores the timing information. |
164 */ | 171 */ |
165 gExtendedTimerRec.tmTask.qLink = NULL; | 172 gExtendedTimerRec.tmTask.qLink = NULL; |
166 gExtendedTimerRec.tmTask.qType = 0; | 173 gExtendedTimerRec.tmTask.qType = 0; |
167 gExtendedTimerRec.tmTask.tmAddr = NewTimerProc(TimerCallbackProc); | 174 gExtendedTimerRec.tmTask.tmAddr = NewTimerProc (TimerCallbackProc); |
168 gExtendedTimerRec.tmTask.tmCount = 0; | 175 gExtendedTimerRec.tmTask.tmCount = 0; |
169 gExtendedTimerRec.tmTask.tmWakeUp = 0; | 176 gExtendedTimerRec.tmTask.tmWakeUp = 0; |
170 gExtendedTimerRec.tmTask.tmReserved = 0; | 177 gExtendedTimerRec.tmTask.tmReserved = 0; |
171 GetCurrentProcess(&gExtendedTimerRec.taskPSN); | 178 GetCurrentProcess (&gExtendedTimerRec.taskPSN); |
172 | 179 |
173 /* Install the task record */ | 180 /* Install the task record */ |
174 InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | 181 InsXTime ((QElemPtr) & gExtendedTimerRec.tmTask); |
175 | 182 |
176 /* Go! */ | 183 /* Go! */ |
177 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | 184 PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); |
178 return(0); | 185 return (0); |
179 } | 186 } |
180 | 187 |
181 void SDL_SYS_StopTimer(void) | 188 void |
189 SDL_SYS_StopTimer (void) | |
182 { | 190 { |
183 RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | 191 RmvTime ((QElemPtr) & gExtendedTimerRec.tmTask); |
184 } | 192 } |
185 | 193 |
186 #endif /* SDL_TIMER_MACOS */ | 194 #endif /* SDL_TIMER_MACOS */ |
195 /* vi: set ts=4 sw=4 expandtab: */ |