Updatedd pods
[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>
05c66c33 9<ul><li><a href="#add_timer_interval_callback">add_timer(interval, callback)</a></li>
10<li><a href="#remove_timer_id">remove_timer(id)</a>
cf23a5da 11</li>
12</ul>
13</li>
14</ul><hr />
15<!-- INDEX END -->
16
17<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
18<div id="NAME_CONTENT">
05c66c33 19<p>SDL::Time - An SDL Perl extension for managing timers</p>
cf23a5da 20
980e45b1 21</div>
22<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
23<div id="CATEGORY_CONTENT">
24<p>Core</p>
cf23a5da 25
26</div>
27<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
28<div id="SYNOPSIS_CONTENT">
05c66c33 29<pre> use threads;
30 use threads::shared;
cf23a5da 31
05c66c33 32 use SDL ':all';
33 use SDL::Time;
cf23a5da 34
05c66c33 35 package foo;
cf23a5da 36
05c66c33 37 SDL::init(SDL_INIT_TIMER);
cf23a5da 38
05c66c33 39 my $tick :shared = 0;
40 sub ticker { $tick++; warn $tick; return 100; }
cf23a5da 41
05c66c33 42 package main;
cf23a5da 43
05c66c33 44 my $id = SDL::Time::add_timer(100, 'foo::ticker');
cf23a5da 45
05c66c33 46 sleep(2);
cf23a5da 47
05c66c33 48 SDL::Time::remove_timer($id);
cf23a5da 49
50</pre>
51
52</div>
53<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
54<div id="METHODS_CONTENT">
55
cf23a5da 56</div>
05c66c33 57<h2 id="add_timer_interval_callback">add_timer(interval, callback)</h2>
cf23a5da 58<div id="add_timer_interval_callback_CONTENT">
05c66c33 59<p>This runs in a separate thread and a cloned Perl thread.</p>
60<p>The <code>callback</code> function, specified with a string of the function's name, will be called after the milliseconds of <code>interval</code> have elapsed.
61The actual delay may be longer than specified depending on the underlying OS.
62The callback function is passed the current timer interval as well as the <code>interval</code> parameter and should return the next timer interval.
63If the return value from the callback is 0, the timer is cancelled; otherwise, the timer will continue to run.</p>
64<p>The timer callback function may run in a different thread to your main program, so it shouldn't call any functions from within itself.
65You may call SDL::push_event, however.</p>
66<p><code>SDL::Time::add_timer</code> returns the identifier value of the generated timer or undef on error.</p>
67<p><strong>Note:</strong> You must initialize (<code>SDL::init</code>) the timer subsystem to use this function.</p>
cf23a5da 68
69</div>
05c66c33 70<h2 id="remove_timer_id">remove_timer(id)</h2>
cf23a5da 71<div id="remove_timer_id_CONTENT">
05c66c33 72<p>The other way to cancel a timer is to use <code>SDL::Time::remove_timer</code> on the <code>id</code> of a timer.
73This <code>id</code> is the return value of the <code>SDL::Time::remove_timer</code> function.</p>
74<p><code>SDL::Time::remove_timer</code> returns <code>0</code> on success or <code>-1</code> on error.</p>
cf23a5da 75
76</div>
77</div>