Image
[sdlgit/SDL-Site.git] / pages / Time.html-inc
CommitLineData
ecabf8b7 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
5<ul><li><a href="#NAME">NAME</a></li>
6<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
7<li><a href="#METHODS">METHODS</a>
8<ul><li><a href="#get_ticks">get_ticks()</a></li>
9<li><a href="#delay_ms">delay(ms)</a></li>
10<li><a href="#add_timer_interval_callback_param">add_timer(interval,callback,param)</a>
11<ul>
12<li>
13<ul><li><a href="#Parameters">Parameters</a></li>
14</ul>
15</li>
16</ul>
17</li>
18<li><a href="#remove_timer_id">remove_timer( id )</a></li>
19<li><a href="#set_timer_interval_callback">set_timer( interval,callback )</a>
20</li>
21</ul>
22</li>
23</ul><hr />
24<!-- INDEX END -->
25
26<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
27<div id="NAME_CONTENT">
28<p>SDL::Time - a SDL perl extension for managing timers.</p>
29
30
31
32
33
34</div>
35<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
36<div id="SYNOPSIS_CONTENT">
37
38
39
40
41
42
43
44
45
46
47
48</div>
49<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
50<div id="METHODS_CONTENT">
51
52
53
54
55
56</div>
57<h2 id="get_ticks">get_ticks()</h2>
58<div id="get_ticks_CONTENT">
59<p>Returns the number of milliseconds since SDL library initialization. This value wraps around if the program runs for more than 49.7 days</p>
60
61
62
63
64
65</div>
66<h2 id="delay_ms">delay(ms)</h2>
67<div id="delay_ms_CONTENT">
68<p>This function waits a specified number of milliseconds before returning. It waits at least the specified time, but possible longer due to OS scheduling. The delay granularity is at least 10 ms. Some platforms have shorter clock ticks but this is the most common.
69SDL::delay doesn't returns anything.</p>
70
71</div>
72<h2 id="add_timer_interval_callback_param">add_timer(interval,callback,param)</h2>
73<div id="add_timer_interval_callback_param_CO">
74<p>Adds a callback function to be run after the specified number of milliseconds has elapsed.
75The callback function is passed the current timer interval and the user supplied parameter from the SDL::add_timer call and returns the next timer interval.
76If the returned value from the callback is the same as the one passed in, the timer continues at the same rate.
77If the returned value from the callback is 0, the timer is cancelled.</p>
78<p>Another way to cancel a currently-running timer is by calling SDL::remove_timer with the timer's ID (which was returned from SDL::add_timer).</p>
79<p>The timer callback function may run in a different thread than your main program, and so shouldn't call any functions from within itself.
80However, you may always call SDL::push_event.</p>
81<p>SDL::add_timer returns the identifier value of the generated timer or undef on error. </p>
82<p>Note : If you use this function, you need to pass SDL_INIT_TIMER to SDL::init. </p>
83
84</div>
85<h4 id="Parameters">Parameters</h4>
86<div id="Parameters_CONTENT">
87<pre> interval [in] The desired interval of the timer, in milliseconds.
88 The granularity of the timer is platform-dependent, but you should count on it being at least 10 ms as this is the most common number.
89 This means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system.
90 If you wanted to set a flag signaling a frame update at 30 frames per second (every 33 ms), you might set a timer for 30 ms (see example below).
91
92 callback [in] The SDL timer callback function which is called when the specified interval elapses.
93
94 param [in] The user parameter which is passed to the callback function
95
96
97
98
99</pre>
100
101</div>
102<h2 id="remove_timer_id">remove_timer( id )</h2>
103<div id="remove_timer_id_CONTENT">
104<p>Removes a timer callback previously added with SDL::add_timer.
cbc85b7f 105It returns 0 on succés or -1 on error.</p>
ecabf8b7 106
107</div>
108<h2 id="set_timer_interval_callback">set_timer( interval,callback )</h2>
109<div id="set_timer_interval_callback_CONTENT">
110<p>Set a callback to run after the specified number of milliseconds has elapsed.
111The callback function is passed the current timer interval and returns the next timer interval.
112If the returned value is the same as the one passed in, the periodic alarm continues, otherwise a new alarm is scheduled.</p>
113<p>To cancel a currently running timer, call SDL::set_timer(0, NULL);</p>
114<p>The timer callback function may run in a different thread than your main constant, and so shouldn't call any functions from within itself.</p>
115<p>The maximum resolution of this timer is 10 ms, which means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system. If you wanted to set a flag signaling a frame update at 30 frames per second (every 33 ms), you might set a timer for 30 ms (see example below).</p>
116<p>If you use this function, you need to pass SDL_INIT_TIMER to SDL::init().
117Note: This function is kept for compatibility but has been superseded by the new timer functions SDL::add_timer and SDL::remove_timer which support multiple timers.</p>
118
119
120
121
122
123</div>
124</div>