Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro timers are laggy?

This thread is locked; no one can reply to it. rss feed Print
Allegro timers are laggy?
xantier
Member #12,521
January 2011

I'm using ALLEGRO_TIMER objects for my Object class. So every object will have a timer in order to control animation frames. But i am suspicious if too many allegro timers lag the game ? Should I use it ?

Thomas Fjellstrom
Member #476
June 2000
avatar

I think they should be fairly efficient. Just make sure that you handle the timer events as soon as you possibly can. Try not to let them pile up.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

xantier
Member #12,521
January 2011

On each timer tick, i set the tick count 0 (so i can check it easily again).

    for (int i=0;i<Objects.size();i++)
    { 
      if (Objects[i]->GetSprite()->IsAnimated())
      {
      if (al_get_timer_count(Objects[i]->GetSprite()->GetTimer()))
      {
      al_set_timer_count(Objects[i]->GetSprite()->GetTimer(),0);
      Objects[i]->GetSprite()->Animate();
      }
      }
    }

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Why do you need a separate timer for each of your objects? A single 60hz timer should be sufficient for most everything. All you have to do is track delta time in your animated object and set the frame number accordingly.

frame_num = (int)(frametime*frames_per_sec);
// check bounds of frame_num here...

Go to: