Jump to content
  • Advertisement
Sign in to follow this  
NighTiger

How to get fps with the Allegro

This topic is 4918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I would like start to use the Allegro instead the SDL, because the Allegro, I think, working better than the SDL. Anyway, how can I translate this:
void fps(void)
{
  now = SDL_GetTicks() / 1000;

  if (now - old_fps == 1)
  {
    sprintf(string, "Salvatore Di Fazio - fps: %i", count_fps);
    SDL_WM_SetCaption(string, "Salvatore Di Fazio");
    count_fps = 0;
  }
  else
   count_fps++;

  old_fps = now;
}
in Allegro? I don't find something like SDL_GetTicks();. tnx

Share this post


Link to post
Share on other sites
Advertisement
You are right that Allegro does not have an equivalent function, although you probably could roll your own easily enough. (See these threads.)

The common way in Allegro to measure FPS is to set up a timer system. Most games have a "game tick" function that increments a variable so many times per second. You can use that function to count your frames per second.

Go here for a list of threads on the issue.

For a prebuilt C++ class to handle FPS and timing: 266205.

Or, for a common C style Allegro game loop: 238521.

Share this post


Link to post
Share on other sites

Uint32 timeNow;
Uint32 timeLast;
int numFrames;

// In game loop
timeNow = GetTime();
if(timeNow - timeLast > 1000){
m_FPS = numFrames;
timeLast = timeNow;
numFrames = 0;
} else {
numFrames++;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!