[SDL] Setting FPS to 60?

Leo M. Cabrera leo28c at gmail.com
Mon Mar 19 17:37:55 PDT 2007


That would work, in fact C#'s SDL has something very similar... However 
I can't use that due to the nature of my program.

I must do it manually.

Can anyone help me with that?

Thanks!

Andreas Schiffler wrote:
> SDL_gfx has a framerate manager that does stuff like that ...
> http://www.ferzkopp.net/joomla/content/view/19/14/
>
> ---snip---
> The framerate functions are used to insert delays into the graphics loop 
> to maintain a constant framerate.
>
> The implementation is more sophisticated that the usual
>     SDL_Delay(1000/FPS);
> call since these functions keep track of the desired game time per frame 
> for a linearly interpolated sequence of future timing points of each 
> frame. This is done to avoid rounding errors from the inherent 
> instability in the delay generation and application - i.e. the 100th 
> frame of a game running at 50Hz will be accurately 2.00sec after the 1st 
> frame (if the machine can keep up with the drawing). See also the 
> diagram for more details on this.
>  
> [[[ Interface ]]]
>
> The functions return 0 or value for sucess and -1 for error. All functions
>  use a pointer to a framerate-manager variable to operate.
>  
>  void SDL_initFramerate(FPSmanager * manager); 
>   Initialize the framerate manager, set default framerate of 30Hz and
>   reset delay interpolation.
>   
>  int SDL_setFramerate(FPSmanager * manager, int rate); 
>   Set a new framerate for the manager and reset delay interpolation.
>   
>  int SDL_getFramerate(FPSmanager * manager); 
>   Get the currently set framerate of the manager.
>   
>  void SDL_framerateDelay(FPSmanager * manager); 
>   Generate a delay to accommodate currently set framerate. Call once in the
>   graphics/rendering loop. If the computer cannot keep up with the rate 
> (i.e.
>   drawing too slow), the delay is zero and the delay interpolation is reset.
>
>
> L-28C wrote:
>   
>> Hello everyone!
>>
>> I'm translating a piece of code into C#.  However it has some variables 
>> and functions that who-knows-where they are declared, so if anyone could 
>> analyze my framerate function I would appreciate it: (translated back to 
>> C++ and regular SDL 'cause I know most of you guys don't speak C#)
>>
>> void waitVblankStart()
>> {
>> 	float t = ((float) SDL_GetTicks()) / ((float) 60);
>> 	if (t - lastTime < 1.0/60.0)
>> 	{
>> 		SDL_Delay(int)(1000000000.0 * (1.0 / 60.0 - (t - lastTime))));
>> 	}
>> 	// lastTime is a global, and 2,000,000 stands for 2.0GHz How do I get 
>> the actual processor cycles-per-second in SDL?
>> 	lastTime = ((float) SdlDotNet.Core.Timer.TicksElapsed) / ((float) 2000000);
>>
>> 	printf(lastTime); // assume printf() can print floats
>> }
>>
>> Thanks in advance!
>>
>> _______________________________________________
>> 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