[SDL] FPS Counter?

Sahan Chandrasekara sahanthegamecreator at gmail.com
Thu Sep 21 21:11:35 PDT 2006


On 9/22/06, Sahan Chandrasekara <sahanthegamecreator at gmail.com> wrote:
>
> On 9/15/06, Peter Mulholland <darkmatter at freeuk.com> wrote:
> >
> > Hello DARKGuy,
> >
> > Thursday, September 14, 2006, 6:24:53 PM, you wrote:
> >
> > > Hi again! xD... my game's progressing awesomely thanks to all of you
> > ^_^
> > > hehe... o.o but now I wonder xD I've been through google, lazy foo's
> > > tutorials, Aaron's SDL tutorials, and such, searching for an FPS
> > counter
> > > code and I haven't found any, and in lazy foo's site the code is too
> > old and
> > > it throws errors in SDL (it uses "timers"? which I supposed SDL had =/
> > ).
> > > Going through google all I can find are pseudo-codes and theories, but
> > no
> > > example whatsoever :(. Does anybody here has a simple FPS counter that
> > can
> > > share please? ^^...
> >
> >
> > It's quite easy:
> >
> > while (gamerunning)
> > {
> >       Uint32 start_time, frame_time;
> >       float fps;
> >
> >       start_time = SDL_GetTicks();
> >
> >       // do stuff
> >       SDL_Flip();
> >
> >       frame_time = SDL_GetTicks()-start_time;
> >       fps = (frame time > 0) ? 1000.0f / frame_time : 0.0f;
> > }
> >
> > The extra bit in the fps calculation stops a divide by zero should a
> > frame happen to take less than a millisecond (it's not likely, but it
> > can happen)
> >
> > --
> > Best regards,
> > Peter                            mailto:darkmatter at freeuk.com
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> >
> Cool. I was just about to post this question, and then I find out it has
> already been posted and answered! =D



Wait a min, one extra question:

How would you regulate the frame rate?




-- 
Sahan Chandrasekara

Get a free sony psp at http://psps.freepay.com/?r=30890215 (not a scam)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060922/4ed3663e/attachment-0008.htm>


More information about the SDL mailing list