Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL FPS counter


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 DyDx   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 March 2003 - 09:34 AM

I''ve looked around but alas, no websites pertaining to creating an FPS counter in SDL. (Well their must be some out there, but I just couldn''t pull them up with Google...) All I did find was SDL_GetTicks(), which is supposed to count the number of milliseconds since the SDL library was called. The only problem with this is that it has a resolution of only 10ms under windows - and I don''t know what that means. So what should I do? I don''t need the FPS counter really, although I''d like to put one in this and any other SDL app I make just as a performance tester. What I really need is a way of limiting how fast the main loop loops so that my apps don''t run really fast on really fast machines and really slow on really slow machines. An idea I have is to limit the number of times the loop goes through in one second to under 60 - but I still do not know how to implement that. How would I "slow" down the loop? Help me out! Thanks!

Sponsor:

#2 Dobbs   Members   -  Reputation: 164

Like
Likes
Like

Posted 03 March 2003 - 09:57 AM

A much better approach to making the game run at consistent speeds is to make movement in your game time-dependent. Rather than updating something''s position/velocity by a fixed amount each frame, update position by velocity*timeElapsedSinceLastFrame and update velocity by acceleration*timeElapsedSinceLastFrame. You calculate timeElapsedSinceLastFrame using SDL_GetTicks.

#3 keethrus   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 March 2003 - 09:21 AM


    
// setup code

Uint32 startclock = 0;
Uint32 deltaclock = 0;
Uint32 currentFPS = 0;


// at beginning of loop

startclock = SDL_GetTicks();


// actual fps calculation inside loop

deltaclock = SDL_GetTicks() - startclock;
startclock = SDL_GetTicks();

if ( deltaclock != 0 )
currentFPS = 1000 / deltaclock;


- jeremiah

inlovewithGod.com


[edited by - keethrus on March 4, 2003 4:23:27 PM]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS