[SDL] Framerate independence?

Andrew Zabolotny zap at cobra.ru
Tue Mar 27 04:34:28 PDT 2007


На Tue, 27 Mar 2007 13:18:45 +0200
"Stefan Hendriks" <stefanhen83 at gmail.com> записано:

> Why does one need a 'fixed' fps anyway? Afaik you want a fixed
> game-flow , independant of the fps.
It's not fixed, it's capped at maximum. You won't have more than some
number of FPS. In particular, it doesn't make any sense to have a
refresh rate higher than monitor's refresh rate (60Hz usually on LCD
monitors) because you won't see anyway more than 60FPS. But if the game
just can't do 60FPS, your game logic still must account for the lower
FPS, thus the amount of time that has passed since last frame is passed
into the update_game() function.

> void handle_logic() {
>  while (timer > 0) {
>    updatelogicbytickonsomeevent/unit. etc.
>    timer--;
> }
This is exactly the kind of overkill I was mentioning. Instead of
calling your updatelogic function N times, call it just once and pass
it the amount of the time between previous frame and this frame. So you
can spend the extra time in a sleep, so that your game behaves nicely
in a multitasking environment.

In particular, on my GeForce 7600GT I can keep a 60FPS rate with just
1-2% CPU usage, so I can run the game and in parallel compile,
download, compute, encode audio or video and in general do any kind of
useful background stuff.

-- 
Greetings,
   Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070327/41af454a/attachment.pgp 


More information about the SDL mailing list