added docs for face attributes
[sdlgit/SDL-Site.git] / pages / SDL-Time.html-inc
CommitLineData
cf23a5da 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
5<ul><li><a href="#NAME">NAME</a></li>
980e45b1 6<li><a href="#CATEGORY">CATEGORY</a></li>
cf23a5da 7<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8<li><a href="#METHODS">METHODS</a>
9<ul><li><a href="#get_ticks">get_ticks()</a></li>
10<li><a href="#delay_ms">delay(ms)</a></li>
11<li><a href="#add_timer_interval_callback">add_timer(interval,callback)</a>
12<ul>
13<li>
14<ul><li><a href="#Parameters">Parameters</a></li>
15</ul>
16</li>
17</ul>
18</li>
19<li><a href="#remove_timer_id">remove_timer( id )</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
980e45b1 30</div>
31<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
32<div id="CATEGORY_CONTENT">
33<p>Core</p>
cf23a5da 34
35</div>
36<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
37<div id="SYNOPSIS_CONTENT">
38<pre> package foo;
39 use threads;
40 use threads::shared;
41
42 use SDL;
43 use SDL::Time;
44
45 SDL::init(SDL_INIT_TIMER);
46
47 my $tick :shared = 0;
48
49 sub ticker { $tick++; warn $tick; return 100 };
50
51 package main;
52
53 my $id = SDL::Time::add_timer(100, 'foo::ticker');
54
55 sleep(2);
56
57 SDL::Time::remove_timer($id);
58
59 SDL::quit();
60
61</pre>
62
63</div>
64<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
65<div id="METHODS_CONTENT">
66
67
68
69
70
71</div>
72<h2 id="get_ticks">get_ticks()</h2>
73<div id="get_ticks_CONTENT">
74<p>This will be move to SDL::Time.</p>
75
76
77
78
79<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>
80
81
82
83
84
85</div>
86<h2 id="delay_ms">delay(ms)</h2>
87<div id="delay_ms_CONTENT">
88<p>This will be move to SDL::Time.</p>
89<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.
90SDL::delay doesn't returns anything. </p>
91
92</div>
93<h2 id="add_timer_interval_callback">add_timer(interval,callback)</h2>
94<div id="add_timer_interval_callback_CONTENT">
95<p>This runs in a seperate thread and a cloned perl thread.</p>
96<p>Adds a callback function to be run after the specified number of milliseconds has elapsed.
97The 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.
98If the returned value from the callback is the same as the one passed in, the timer continues at the same rate.
99If the returned value from the callback is 0, the timer is cancelled.</p>
100<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>
101<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.
102However, you may always call SDL::push_event.</p>
103<p>SDL::add_timer returns the identifier value of the generated timer or undef on error. </p>
104<p>Note : If you use this function, you need to pass SDL_INIT_TIMER to SDL::init. </p>
105
106</div>
107<h4 id="Parameters">Parameters</h4>
108<div id="Parameters_CONTENT">
109<pre> interval [in] The desired interval of the timer, in milliseconds.
110 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.
111 This means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system.
112 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).
113
114 callback [in] The SDL timer callback function which is called when the specified interval elapses.
115
116
117
118
119</pre>
120
121</div>
122<h2 id="remove_timer_id">remove_timer( id )</h2>
123<div id="remove_timer_id_CONTENT">
124<p>Removes a timer callback previously added with SDL::add_timer.
125It returns 0 on succés or -1 on error.</p>
126
127
128
129
130
131</div>
132</div>