yes &quot;get time&quot; comes from GLFW; that is get comes from OpenGL, time from GLFW. <div><br></div><div>I think the time provided by GLFW has a very high resolution but is not very accurate in the long run, which is not a real problem for games I guess</div>
<div><br></div><div><div><div><div><div><div class="gmail_quote">On Tue, Apr 7, 2009 at 6:09 PM, Duane Johnson <span dir="ltr">&lt;<a href="mailto:duane.johnson@gmail.com">duane.johnson@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">The Hipmunk 2D physics engine comes with a &quot;playground&quot; app which includes the following function:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-- | Advances the time.<br>
advanceTime :: IORef State -&gt; Double -&gt; KeyButtonState -&gt; IO Double<br>
advanceTime stateVar oldTime slowKey = do<br>
  newTime &lt;- get time<br>
<br>
  -- Advance simulation<br>
  let slower = if slowKey == Press then slowdown else 1<br>
      mult   = frameSteps / (framePeriod * slower)<br>
      framesPassed   = truncate $ mult * (newTime - oldTime)<br>
      simulNewTime   = oldTime + toEnum framesPassed / mult<br>
  advanceSimulTime stateVar $ min maxSteps framesPassed<br>
<br>
  -- Correlate with reality<br>
  newTime&#39; &lt;- get time<br>
  let diff = newTime&#39; - simulNewTime<br>
      sleepTime = ((framePeriod * slower) - diff) / slower<br>
  when (sleepTime &gt; 0) $ sleep sleepTime<br>
  return simulNewTime<br>
</blockquote>
<br>
<br>
I think the &quot;get time&quot; is provided by GLFW.<br><font color="#888888">
<br>
-- Duane Johnson</font><div><div></div><div class="h5"><br>
<br>
<br>
On Apr 7, 2009, at 9:25 AM, Ulrik Rasmussen wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Apr 07, 2009 at 04:34:22PM +0200, Peter Verswyvelen wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Do you want to cap the rendering framerate at 60FPS or the animation<br>
framerate?<br>
Because when you use OpenGL and GLFW, you can just<br>
<br>
GLFW.swapInterval $= 1<br>
<br>
to cap the rendering framerate at the refresh rate of your monitor or LCD<br>
screen (usually 60Hz)<br>
</blockquote>
<br>
I just want to cap the rendering framerate. The game logic is running in<br>
other threads, and sends rendering information via a Chan to the<br>
renderer.<br>
<br>
I&#39;m using GLUT, and have never heard of GLFW. However, that seems to be<br>
a better tool to get the job done. I&#39;ll check it out, thanks :).<br>
<br>
/Ulrik<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On Tue, Apr 7, 2009 at 1:41 PM, Ulrik Rasmussen &lt;<a href="mailto:haskell@utr.dk" target="_blank">haskell@utr.dk</a>&gt; wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello.<br>
<br>
I am writing a simple game in Haskell as an exercise, and in the<br>
rendering loop I want to cap the framerate to 60fps. I had planned to do<br>
this with GHC.Conc.threadDelay, but looking at it&#39;s documentation, I<br>
discovered that it can only delay the thread in time spans that are<br>
multiples of 20ms:<br>
<br>
<br>
<a href="http://www.haskell.org/ghc/docs/6.4/html/libraries/base/Control.Concurrent.html" target="_blank">http://www.haskell.org/ghc/docs/6.4/html/libraries/base/Control.Concurrent.html</a><br>
<br>
I need a much finer granularity than that, so I wondered if it is<br>
possible to either get a higher resolution for threadDelay, or if there<br>
is an alternative to threadDelay?<br>
<br>
I noticed that the SDL library includes the function &quot;delay&quot;, which<br>
indeed works with a resolution down to one millisecond. However, since<br>
I&#39;m using HOpenGL and GLUT, I think it would be a little overkill to<br>
depend on SDL just for this :).<br>
<br>
<br>
Thanks,<br>
<br>
Ulrik Rasmussen<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
</blockquote></blockquote>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote>
<br>
</div></div></blockquote></div><br></div></div></div></div></div>