GetTickCount???

Started by
4 comments, last by Alex5 22 years, 10 months ago
What is the best way to find elapsed time between frames in a game? Is GetTickCount() good, or is there a better way?
Advertisement
In Windows I presume. The best universal method is timeGetTime(), and even better one is QueryPerformanceCounter, but not everyone has a performance counter.

[Resist Windows XP''s Invasive Production Activation Technology!]
ya, first test whether QueryPerformanceCounter() works, then if it doesn''t use timeGetTime(), like this:
timeBeginPeriod(1);
time=timeGetTime();
timeEndPeriod(1);
that is more accurate that GetTickCount by far, but it''s not as high res as QPC.

HHSDrum@yahoo.com
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
GetTickCount is for the most part usually okay, but it doesn''t have a very high resolution and you would be way better off using a multimedia timer or a performance timer. What I do is test the system by calling QueryPerformanceFrequency(). If the system has a performance timer, QueryPerformanceFrequency will return 1, and if it doesn''t, it will return 0. Then if there is no performance counter, you can just use timeGetTime(). Of course, using the performance timer requires some extra work since you have to figure out the resolution and adjust your time accordingly, so it may be easier to just always use timeGetTime().


It would require very high frame rates to really see a difference between the two timers.

If the framerate is 1.000 fps then a timer with a resolution of 1 ms is clearly not enough...

If it takes you 1 ms or less time to render your frame then you should deffinately use a high performance timer...

If you want to be able to run your game in 10 years when CPUs are 10.000 Mhz and monitors run at 1000hz then use the high performance timer.

It´s very nice to use timeGetTime() because one tick is one ms on all systems. It´s easy for your brain to work with a number like 1.000.

Maybe I am wrong about this...I have used both timers and this is my conclusion....




-------------Ban KalvinB !
I just use a timer class which looks for the performance timer, and if it isn''t present, uses timegettime. This class converts both to seconds per frame, so my brain has no problems ;-)

This topic is closed to new replies.

Advertisement