Mercurial > sdl-ios-xcode
comparison src/timer/macos/SDL_MPWtimer.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 | 92947e3a18db |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
32 #include <LowMem.h> | 32 #include <LowMem.h> |
33 | 33 |
34 #include "SDL_timer.h" | 34 #include "SDL_timer.h" |
35 #include "../SDL_timer_c.h" | 35 #include "../SDL_timer_c.h" |
36 | 36 |
37 #define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */ | 37 #define MS_PER_TICK (1000/60) /* MacOS tick = 1/60 second */ |
38 | 38 |
39 /* Note: This is only a step above the original 1/60s implementation. | 39 /* Note: This is only a step above the original 1/60s implementation. |
40 * For a good implementation, see FastTimes.[ch], by Matt Slot. | 40 * For a good implementation, see FastTimes.[ch], by Matt Slot. |
41 */ | 41 */ |
42 #define USE_MICROSECONDS | 42 #define USE_MICROSECONDS |
43 #define WideTo64bit(w) (*(UInt64 *) &(w)) | 43 #define WideTo64bit(w) (*(UInt64 *) &(w)) |
44 | 44 |
45 UInt64 start; | 45 UInt64 start; |
46 | 46 |
47 void SDL_StartTicks(void) | 47 void |
48 SDL_StartTicks (void) | |
48 { | 49 { |
49 #ifdef USE_MICROSECONDS | 50 #ifdef USE_MICROSECONDS |
50 UnsignedWide now; | 51 UnsignedWide now; |
51 | 52 |
52 Microseconds(&now); | 53 Microseconds (&now); |
53 start = WideTo64bit(now); | 54 start = WideTo64bit (now); |
54 #else | 55 #else |
55 /* FIXME: Should we implement a wrapping algorithm, like Win32? */ | 56 /* FIXME: Should we implement a wrapping algorithm, like Win32? */ |
56 #endif | 57 #endif |
57 } | 58 } |
58 | 59 |
59 Uint32 SDL_GetTicks(void) | 60 Uint32 |
61 SDL_GetTicks (void) | |
60 { | 62 { |
61 #ifdef USE_MICROSECONDS | 63 #ifdef USE_MICROSECONDS |
62 UnsignedWide now; | 64 UnsignedWide now; |
63 | 65 |
64 Microseconds(&now); | 66 Microseconds (&now); |
65 return (Uint32)((WideTo64bit(now)-start)/1000); | 67 return (Uint32) ((WideTo64bit (now) - start) / 1000); |
66 #else | 68 #else |
67 return(LMGetTicks()*MS_PER_TICK); | 69 return (LMGetTicks () * MS_PER_TICK); |
68 #endif | 70 #endif |
69 } | 71 } |
70 | 72 |
71 void SDL_Delay(Uint32 ms) | 73 void |
74 SDL_Delay (Uint32 ms) | |
72 { | 75 { |
73 #ifdef USE_MICROSECONDS | 76 #ifdef USE_MICROSECONDS |
74 Uint32 end_ms; | 77 Uint32 end_ms; |
75 | 78 |
76 end_ms = SDL_GetTicks() + ms; | 79 end_ms = SDL_GetTicks () + ms; |
77 do { | 80 do { |
78 /* FIXME: Yield CPU? */ ; | 81 /* FIXME: Yield CPU? */ ; |
79 } while ( SDL_GetTicks() < end_ms ); | 82 } |
83 while (SDL_GetTicks () < end_ms); | |
80 #else | 84 #else |
81 UInt32 unused; /* MJS */ | 85 UInt32 unused; /* MJS */ |
82 Delay(ms/MS_PER_TICK, &unused); | 86 Delay (ms / MS_PER_TICK, &unused); |
83 #endif | 87 #endif |
84 } | 88 } |
85 | 89 |
86 | 90 |
87 /* Data to handle a single periodic alarm */ | 91 /* Data to handle a single periodic alarm */ |
88 typedef struct _ExtendedTimerRec | 92 typedef struct _ExtendedTimerRec |
89 { | 93 { |
90 TMTask tmTask; | 94 TMTask tmTask; |
91 ProcessSerialNumber taskPSN; | 95 ProcessSerialNumber taskPSN; |
92 } ExtendedTimerRec, *ExtendedTimerPtr; | 96 } ExtendedTimerRec, *ExtendedTimerPtr; |
93 | 97 |
94 static ExtendedTimerRec gExtendedTimerRec; | 98 static ExtendedTimerRec gExtendedTimerRec; |
95 | 99 |
96 | 100 |
97 int SDL_SYS_TimerInit(void) | 101 int |
102 SDL_SYS_TimerInit (void) | |
98 { | 103 { |
99 /* We don't need a setup? */ | 104 /* We don't need a setup? */ |
100 return(0); | 105 return (0); |
101 } | 106 } |
102 | 107 |
103 void SDL_SYS_TimerQuit(void) | 108 void |
109 SDL_SYS_TimerQuit (void) | |
104 { | 110 { |
105 /* We don't need a cleanup? */ | 111 /* We don't need a cleanup? */ |
106 return; | 112 return; |
107 } | 113 } |
108 | 114 |
109 /* Our Stub routine to set up and then call the real routine. */ | 115 /* Our Stub routine to set up and then call the real routine. */ |
110 pascal void TimerCallbackProc(TMTaskPtr tmTaskPtr) | 116 pascal void |
117 TimerCallbackProc (TMTaskPtr tmTaskPtr) | |
111 { | 118 { |
112 Uint32 ms; | 119 Uint32 ms; |
113 | 120 |
114 WakeUpProcess(&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); | 121 WakeUpProcess (&((ExtendedTimerPtr) tmTaskPtr)->taskPSN); |
115 | 122 |
116 ms = SDL_alarm_callback(SDL_alarm_interval); | 123 ms = SDL_alarm_callback (SDL_alarm_interval); |
117 if ( ms ) { | 124 if (ms) { |
118 SDL_alarm_interval = ROUND_RESOLUTION(ms); | 125 SDL_alarm_interval = ROUND_RESOLUTION (ms); |
119 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, | 126 PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); |
120 SDL_alarm_interval); | 127 } else { |
121 } else { | 128 SDL_alarm_interval = 0; |
122 SDL_alarm_interval = 0; | 129 } |
123 } | |
124 } | 130 } |
125 | 131 |
126 int SDL_SYS_StartTimer(void) | 132 int |
133 SDL_SYS_StartTimer (void) | |
127 { | 134 { |
128 /* | 135 /* |
129 * Configure the global structure that stores the timing information. | 136 * Configure the global structure that stores the timing information. |
130 */ | 137 */ |
131 gExtendedTimerRec.tmTask.qLink = NULL; | 138 gExtendedTimerRec.tmTask.qLink = NULL; |
132 gExtendedTimerRec.tmTask.qType = 0; | 139 gExtendedTimerRec.tmTask.qType = 0; |
133 gExtendedTimerRec.tmTask.tmAddr = NewTimerUPP(TimerCallbackProc); | 140 gExtendedTimerRec.tmTask.tmAddr = NewTimerUPP (TimerCallbackProc); |
134 gExtendedTimerRec.tmTask.tmCount = 0; | 141 gExtendedTimerRec.tmTask.tmCount = 0; |
135 gExtendedTimerRec.tmTask.tmWakeUp = 0; | 142 gExtendedTimerRec.tmTask.tmWakeUp = 0; |
136 gExtendedTimerRec.tmTask.tmReserved = 0; | 143 gExtendedTimerRec.tmTask.tmReserved = 0; |
137 GetCurrentProcess(&gExtendedTimerRec.taskPSN); | 144 GetCurrentProcess (&gExtendedTimerRec.taskPSN); |
138 | 145 |
139 /* Install the task record */ | 146 /* Install the task record */ |
140 InsXTime((QElemPtr)&gExtendedTimerRec.tmTask); | 147 InsXTime ((QElemPtr) & gExtendedTimerRec.tmTask); |
141 | 148 |
142 /* Go! */ | 149 /* Go! */ |
143 PrimeTime((QElemPtr)&gExtendedTimerRec.tmTask, SDL_alarm_interval); | 150 PrimeTime ((QElemPtr) & gExtendedTimerRec.tmTask, SDL_alarm_interval); |
144 return(0); | 151 return (0); |
145 } | 152 } |
146 | 153 |
147 void SDL_SYS_StopTimer(void) | 154 void |
155 SDL_SYS_StopTimer (void) | |
148 { | 156 { |
149 RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); | 157 RmvTime ((QElemPtr) & gExtendedTimerRec.tmTask); |
150 } | 158 } |
151 | 159 |
152 #endif /* SDL_TIMER_MACOS */ | 160 #endif /* SDL_TIMER_MACOS */ |
161 /* vi: set ts=4 sw=4 expandtab: */ |