[SDL] Framerate independence?

Jonathan B. jon at number-none.com
Mon Feb 12 20:14:08 PST 2007


(There's another problem with this code which is that it uses an integer 
divide for the target time... so it will miss for most values of the 
frame time.  For example, if you try to specify 60fps, you will get 
something like 62.5fps.  So I also wouldn't recommend just trying to 
insert a sleep into this code unless you really think about it.)


Jonathan B. wrote:
> Oh wow.  Please *do not* do it like this.  This is a busy wait which 
> will attempt to eat 100% of your CPU doing nothing until the appropriate 
> time.  It is really horrible for any multitasking OS.
>
> It is much better to use SDL_Delay as mentioned on the usingtimers.html 
> page.
>
>
> RCAF wrote:
>   
>> Hi!
>>
>> Look this page:
>>
>> http://www.libsdl.org/intro.en/usingtimers.html
>>
>> but I prefer to do it so:
>>
>> Uint32 t1, t2;
>> int fps = 100;
>> int done=1;
>>
>> while (!done)
>> {
>>     t1 = SDL_GetTicks();  // Initial time
>>
>>     // do something... input, game logic, drawing, ...
>>
>>     do
>>     {
>>         t2 = SDL_GetTicks();  // Current time
>>     } while ((t2 - t1) <= 1000/fps);
>> }
>>
>> Regards!
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>   
>>     
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>   



More information about the SDL mailing list