-
Games - timing
How are timing in games usually achieved? By that I mean in more professional games, not the pong thingy everyone makes first. I used to do do a dummy loop and use timing functions to see when it's time for updating. This however eats CPU, though giving a reliable FPS. Lately I started using the WM_TIMER. This has several advantages, however it is incredibly inaccurate and unreliable (lesser priority than other messages I've heard). If you tell it to fire 40 times/second it actually only fires 30 times/second or so. How are timing best made?
-
I don't know very much about programming, but maybe the Allegro library could help?
-
Research hi res timers if your compiler supports it...
Don't have any sites, but look at and for these functions:
bool QueryPerformanceFrequency(LARGE_INTEGER *freq);
bool QueryPerformanceCounter(LARGE_INTEGER *perfCount);
For me they are in winbase.h.
I can give you an example if you want....have to find it.
-
Got it....here's part of it if you want to take a look through it.
-
One way is to find out how much of a second is between frames and then multiply this value with the pixels per second the object is moving.
-
If you cannot gain access to the timers it is possible to do it in assembly code if, and this is a big if, your inline assembler lets you.
-
Thanks, but the high performance timer is merely a better version of timeGetTime(). It still needs a CPU eating dead loop, which I don't want to use.
-
Magos, you could always yield the process a few ms within the game loop if that was an issue. Another way to avoid the dead loop would to try something like this
Code:
// main game loop
while(...) {
timestamp = GetTickCount();
// some sort of sleep function
Sleep(33 - (GetTickCount() - timestamp))
}
This limits the fps of the game, though.
What you probably want to do is use the high res times and then fall back on GetTickCount if they are not supported.