Does anyone have any ideas on how to implement an effective "timer" class. As of now i'm using system calls and sleeping for a second, but it's not very accurate as you can imagine...The class objects basically need to behave like stopwatches...
i'm not looking for code, just an idea or two...Thanks for the input...
You can use GetTickCount(), which returns the number of milliseconds since windows started. It's located in windows.h.
If you want the program to run at a constant speed, you can do this:
<thought>Why is it called GetTickCount() when it actually returns milliseconds, not ticks???</though>
DWORD TickDelay = 20; // 50 Fps --> 1000 / 50 = 20
LastTickCount = GetTickCount();
CurrentTickCount = GetTickCount();
while((CurrentTickCount - LastTickCount) < TickDelay);
You can also use the stuff in ctime like time(), clock(), things like that. I don't think GetTickCount is portable, so your class would probably only work with windows.