C++ and the system clock
High-resolution timing is platform-specific. Under Win32, you can use GetTickCount(), timeGetTime(), QueryPerformanceCounter() and QueryPerformanceFrequency(), _ftime() and _utime() (not all of those are timing functions in the conventional sense). You can look them up online at MSDN Online.
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
|
This is a time class i wrote for my game. It could be better but it does the job. Just call Init, and it will check if you have a hi-resolution windows timer available. If not, it will default to a lo-resolution windows timer. Make sure to call UpdateTime at the beginning of your main message loop to make sure you don't have old values in the class. Call GetTime whenever you need the amount of time since the last frame. If you are running at 50fps, then GetTime on average will return .020 . (50frames * .020 seconds = 1 second). With this class, i have 2-3 unused variables that take up space, but otherwise its a clean way of handling time that i like. Hope that helped
- Kevin "BaShildy" King
Game Programmer: DigiPen
www.mpogd.com
Edited by - BaShildy on January 19, 2002 4:10:08 AM