comparison docs/html/sdladdtimer.html @ 0:74212992fb08

Initial revision
author Sam Lantinga <slouken@lokigames.com>
date Thu, 26 Apr 2001 16:45:43 +0000
parents
children 55f1f1b3e27d
comparison
equal deleted inserted replaced
-1:000000000000 0:74212992fb08
1 <HTML
2 ><HEAD
3 ><TITLE
4 >SDL_AddTimer</TITLE
5 ><META
6 NAME="GENERATOR"
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.61
8 "><LINK
9 REL="HOME"
10 TITLE="SDL Library Documentation"
11 HREF="index.html"><LINK
12 REL="UP"
13 TITLE="Time"
14 HREF="time.html"><LINK
15 REL="PREVIOUS"
16 TITLE="SDL_Delay"
17 HREF="sdldelay.html"><LINK
18 REL="NEXT"
19 TITLE="SDL_RemoveTimer"
20 HREF="sdlremovetimer.html"></HEAD
21 ><BODY
22 CLASS="REFENTRY"
23 BGCOLOR="#FFF8DC"
24 TEXT="#000000"
25 LINK="#0000ee"
26 VLINK="#551a8b"
27 ALINK="#ff0000"
28 ><DIV
29 CLASS="NAVHEADER"
30 ><TABLE
31 WIDTH="100%"
32 BORDER="0"
33 CELLPADDING="0"
34 CELLSPACING="0"
35 ><TR
36 ><TH
37 COLSPAN="3"
38 ALIGN="center"
39 >SDL Library Documentation</TH
40 ></TR
41 ><TR
42 ><TD
43 WIDTH="10%"
44 ALIGN="left"
45 VALIGN="bottom"
46 ><A
47 HREF="sdldelay.html"
48 >Prev</A
49 ></TD
50 ><TD
51 WIDTH="80%"
52 ALIGN="center"
53 VALIGN="bottom"
54 ></TD
55 ><TD
56 WIDTH="10%"
57 ALIGN="right"
58 VALIGN="bottom"
59 ><A
60 HREF="sdlremovetimer.html"
61 >Next</A
62 ></TD
63 ></TR
64 ></TABLE
65 ><HR
66 ALIGN="LEFT"
67 WIDTH="100%"></DIV
68 ><H1
69 ><A
70 NAME="SDLADDTIMER"
71 >SDL_AddTimer</A
72 ></H1
73 ><DIV
74 CLASS="REFNAMEDIV"
75 ><A
76 NAME="AEN7854"
77 ></A
78 ><H2
79 >Name</H2
80 >SDL_AddTimer&nbsp;--&nbsp;Add a timer which will call a callback after the specified number of milliseconds has
81 elapsed.</DIV
82 ><DIV
83 CLASS="REFSYNOPSISDIV"
84 ><A
85 NAME="AEN7857"
86 ></A
87 ><H2
88 >Synopsis</H2
89 ><DIV
90 CLASS="FUNCSYNOPSIS"
91 ><A
92 NAME="AEN7858"
93 ></A
94 ><P
95 ></P
96 ><PRE
97 CLASS="FUNCSYNOPSISINFO"
98 >#include "SDL.h"</PRE
99 ><P
100 ><CODE
101 ><CODE
102 CLASS="FUNCDEF"
103 >SDL_TimerID <B
104 CLASS="FSFUNC"
105 >SDL_AddTimer</B
106 ></CODE
107 >(Uint32 interval, SDL_NewTimerCallback callback, void *param);</CODE
108 ></P
109 ><P
110 ></P
111 ></DIV
112 ></DIV
113 ><DIV
114 CLASS="REFSECT1"
115 ><A
116 NAME="SDLNEWTIMERCALLBACK"
117 ></A
118 ><H2
119 >Callback</H2
120 ><PRE
121 CLASS="PROGRAMLISTING"
122 >/* type definition for the "new" timer callback function */
123 typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param);</PRE
124 ></DIV
125 ><DIV
126 CLASS="REFSECT1"
127 ><A
128 NAME="AEN7867"
129 ></A
130 ><H2
131 >Description</H2
132 ><P
133 >Adds a callback function to be run after the specified number of
134 milliseconds has elapsed. The callback function is passed the current
135 timer interval and the user supplied parameter from the
136 <TT
137 CLASS="FUNCTION"
138 >SDL_AddTimer</TT
139 > call and returns the next timer
140 interval. If the returned value from the callback is the same as the one
141 passed in, the periodic alarm continues, otherwise a new alarm is
142 scheduled.</P
143 ><P
144 >To cancel a currently running timer call
145 <A
146 HREF="sdlremovetimer.html"
147 >SDL_RemoveTimer</A
148 > with the
149 timer ID returned from
150 <TT
151 CLASS="FUNCTION"
152 >SDL_AddTimer</TT
153 >.</P
154 ><P
155 >The timer callback function may run in a different thread than your
156 main program, and so shouldn't call any functions from within itself.</P
157 ><P
158 >The maximum resolution of this timer is 10 ms, which means that if
159 you request a 16 ms timer, your callback will run approximately 20 ms
160 later on an unloaded system. If you wanted to set a flag signaling
161 a frame update at 30 frames per second (every 33 ms), you might set a
162 timer for 30 ms (see example below).
163
164 If you use this function, you need to pass <TT
165 CLASS="LITERAL"
166 >SDL_INIT_TIMER</TT
167 >
168 to <A
169 HREF="sdlinit.html"
170 >SDL_Init</A
171 >.</P
172 ></DIV
173 ><DIV
174 CLASS="REFSECT1"
175 ><A
176 NAME="AEN7878"
177 ></A
178 ><H2
179 >Return Value</H2
180 ><P
181 >Returns an ID value for the added timer or
182 <SPAN
183 CLASS="RETURNVALUE"
184 >NULL</SPAN
185 > if there was an error.</P
186 ></DIV
187 ><DIV
188 CLASS="REFSECT1"
189 ><A
190 NAME="AEN7882"
191 ></A
192 ><H2
193 >Examples</H2
194 ><P
195 ><PRE
196 CLASS="PROGRAMLISTING"
197 >my_timer_id = SDL_AddTimer((33/10)*10, my_callbackfunc, my_callback_param);</PRE
198 ></P
199 ></DIV
200 ><DIV
201 CLASS="REFSECT1"
202 ><A
203 NAME="AEN7886"
204 ></A
205 ><H2
206 >See Also</H2
207 ><P
208 ><A
209 HREF="sdlremovetimer.html"
210 ><TT
211 CLASS="FUNCTION"
212 >SDL_RemoveTimer</TT
213 ></A
214 ></P
215 ></DIV
216 ><DIV
217 CLASS="NAVFOOTER"
218 ><HR
219 ALIGN="LEFT"
220 WIDTH="100%"><TABLE
221 WIDTH="100%"
222 BORDER="0"
223 CELLPADDING="0"
224 CELLSPACING="0"
225 ><TR
226 ><TD
227 WIDTH="33%"
228 ALIGN="left"
229 VALIGN="top"
230 ><A
231 HREF="sdldelay.html"
232 >Prev</A
233 ></TD
234 ><TD
235 WIDTH="34%"
236 ALIGN="center"
237 VALIGN="top"
238 ><A
239 HREF="index.html"
240 >Home</A
241 ></TD
242 ><TD
243 WIDTH="33%"
244 ALIGN="right"
245 VALIGN="top"
246 ><A
247 HREF="sdlremovetimer.html"
248 >Next</A
249 ></TD
250 ></TR
251 ><TR
252 ><TD
253 WIDTH="33%"
254 ALIGN="left"
255 VALIGN="top"
256 >SDL_Delay</TD
257 ><TD
258 WIDTH="34%"
259 ALIGN="center"
260 VALIGN="top"
261 ><A
262 HREF="time.html"
263 >Up</A
264 ></TD
265 ><TD
266 WIDTH="33%"
267 ALIGN="right"
268 VALIGN="top"
269 >SDL_RemoveTimer</TD
270 ></TR
271 ></TABLE
272 ></DIV
273 ></BODY
274 ></HTML
275 >