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