[SDL] How to get constant framerates without busywaits ...

Stephen Anthony stephena at roadrunner.nf.net
Sat Mar 16 10:26:01 PST 2002


On March 15, 2002 09:45 pm, you wrote:
> Hi!
> What about this way:
> when starting the game
> long started = SDL_GetTicks();
> float timethen = (float)(started +
> how_many_milliseconds_until_the_first_frame_display);
>
> while (in_the_main_loop) {
> 	doEventHandling();
> 	doDrawingToBuffer();
> 	do while ((float)SDL_GetTicks()<timethen);
> 	doSwapBuffers();
> 	timethen+= 16.0f + 2/3.0f;	// 60 fps!
> }
>
> Ok, this is not what you asked.  This is a busywait.  But this one
> probably is the most accurate one (I said probably, on my computer I
> normally get a Delay of somewhat at 2ms between two calls of
> SDL_GetTicks(). so everything looks pretty much smoother than with
> delays)
> St0fF.

Thanks for the response.  But this is what I have already.  Actually, in 
the code I use, I have substituted SDL_GetTicks with gettimeofday, which 
leads to no delay.

But my problem is that I'd like to avoid the busy-wait altogether.  But I 
also want to keep smooth framerates too.  I will have to experiment and 
see if delays will make the framerate *noticably* less smooth.  If it 
does, then I'll stick with a busywait.  How it looks onscreen is more 
important than CPU usage.  I just thought I could have the best of both 
worlds :)

Thanks,
Steve




More information about the SDL mailing list