Advertisement

Portable high res timer

Started by February 02, 2005 11:33 AM
2 comments, last by Kylotan 19 years, 7 months ago
Well as I'm considering entering the 72 hour competition talked about elsewhere in this forum, I had another look at Allegro. Now last time I used it I decidied that it was quite good but I came up with a serious problem as there was no way to get the current time (to at least ms resolution) so I could be frame rate independent motion. Now, I know how you are meant to do this in Allegro, by designing the game logic for a fixed update and repeating it until it catches up with real time before rendering a new frame. Unfortunately I really don't like this idea, possibly as I've studied concurrent systems and it is obvious that this is not guarenteed to render any frame at all (in the case that the wanted time between frame updates is lower than the time to do the game logic). I've seen other people with this problem and I'm wondering if somebody has written a crossplatform library (that plays nice with Allegro) for this. I've seen one that handles Windows (QueryPerformanceCounter) and Linux (gettimeofday) but not the other platform that Allegro works on.
If your game logic takes that long to run then you're in trouble anyway...
Advertisement
Quote: Original post by lucky_monkey
If your game logic takes that long to run then you're in trouble anyway...


Not really. If for example I have some really complex AI/game logic that takes 12ms to process, which isn't that silly, and I set my arbitary required framerate to 50fps then everything works. If it set my arbitary required framerate to 100fps then it fails as in the time it takes to do the game logic and increment the actual number of frames the target number of frames is also increased. If the update is based on the delta time then it would manage about 80fps perfectly well.

Now I can see that it would be possible to have some sort of heuristist system to change the required frame rate to match the time it takes to do the logic but it's much easier to do the game logic correctly.
I never heard of anyone expecting 100fps for animation. Besides which, most monitors will not update that often anyway.

I hear figures more like 12, 24, or 30fps for animation. That's at least 33ms for each frame which is generally enough, and skipping the occasional frame is not usually a tragedy.

The problem here is not necessarily just about the accuracy of the timer, as you will have fluctuations in frame times anyway, meaning you're gonna have some slow frames no matter what you do. You might get a smoother and more accurate time if you average it across several frames.

This topic is closed to new replies.

Advertisement