PDA

View Full Version : Locking a frame rate.



Xorcist
08-11-2002, 10:25 PM
What's the best way of locking a frame rate, supposing I wanted to lock it to a specific rate. And please don't give me "a better solution" or a "why would you want to do that" answer. I'm just looking for a decent method of locking a frame rate and getting more or less the same results on various systems.

Alimonster
08-11-2002, 11:04 PM
Try a loop with a call to sleep in it, which will reduce the CPU usage a bit. Example stuff over here (http://www.geisswerks.com/ryan/FAQS/timing.html) from Ryan Geiss, the bloke behind a famous WinAmp visualization. It's in C, though :(. Remember that you'd use Int64s instead for QueryPerformanceCounter in Delphi, rather than fiddling with LARGE_INTEGER unions/structures as he's doing. Also, he doesn't mention in the section on timeGetTime whether he prefixed/postfixed his code with timeGetDevCaps + timeBeginPeriod and timeEndPeriod. These are necessary for accurate timing under NT - which he's not getting, suggesting that maybe he didn't do this (or maybe he did and timeGetTime just sucks...).

In a similar fashion, here's another article (http://www.mvps.org/directx/articles/writing_the_game_loop.htm) about locking the frame rate (see near the end, "Applying a Throttle". They might give you some ideas.

I've found that averaging a few times gives better results - especially for time-based motion. You might want to keep that in mind.

jdsgames
09-11-2002, 02:46 AM
I have found for controlling the framerate its best to let the game loop run as fast as the target machine can render the graphics, but you control all movement with an elapsed time value. Here is link to an article I wrote on the subject:

http://www.softbeat.com/articles/article1.htm

Stevie56
09-11-2002, 11:51 AM
In DelphiX, there is a framerate runtime value and a DXTimer.

Most games will use the timer with the tick interval set at zero, making it run as fast as the PC will allow.

To bring the program down to a wanted framerate, in the timer tick routine, get the framerate and change the timer tick interval accordingly.