1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>tick (Timer::Timer)</title>
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body bgcolor="white">
<pre><span class="cmt"># File rbot/timer.rb, line 91</span>
<span class="kw">def</span> tick
<span class="kw">if</span>(@lasttime != 0)
diff = (Time.now - @lasttime).to_f
@lasttime = Time.now
@timers.compact.each { |timer|
timer.in = timer.in - diff
}
@timers.compact.each { |timer|
<span class="kw">if</span> (!timer.blocked)
<span class="kw">if</span>(timer.in <= 0)
<span class="kw">if</span>(timer.run)
<span class="cmt"># run once</span>
@timers.delete(timer)
<span class="kw">end</span>
<span class="kw">end</span>
<span class="kw">end</span>
}
<span class="kw">else</span>
<span class="cmt"># don't do anything on the first tick</span>
@lasttime = Time.now
<span class="kw">end</span>
<span class="kw">end</span></pre>
</body>
</html>
|