RustyNail wrote: Going to have to think about it, but since I currently usually don't keep my computer on for 47calendar days, I don't think I will have a problem for now
Sorry, I was unclear: using gettimeofday() (and milliseconds) will wrap every ~49.7 days,
depending on the date, not on how long your machine has been on for. It could wrap the very first time you do it after booting.
Fortunately, dealing with the wrap is trivial:
Code: Select all
u32 diff = now - last; // All u32 values
// Very high positive values are actually negative values, i.e. it's wrapped.
if(diff > UINT_MAX / 2)
{
// "Unwrap" the negative value back to a small positive value.
diff = UINT_MAX - diff;
}
Now the I've got timing working in Linux...
How would I do timing on Windows?
Have you looked in Irrlicht's os.cpp? (WinCE code elided)
Code: Select all
u32 Timer::getRealTime()
{
if (HighPerformanceTimerSupport)
{
// Avoid potential timing inaccuracies across multiple cores by
// temporarily setting the affinity of this process to one core.
DWORD affinityMask;
if(MultiCore)
affinityMask = SetThreadAffinityMask(GetCurrentThread(), 1);
LARGE_INTEGER nTime;
BOOL queriedOK = QueryPerformanceCounter(&nTime);
// Restore the true affinity.
if(MultiCore)
(void)SetThreadAffinityMask(GetCurrentThread(), affinityMask);
if(queriedOK)
return u32((nTime.QuadPart) * 1000 / HighPerformanceFreq.QuadPart);
}
return GetTickCount();
}
I'm very surprised that you need more than millisecond accuracy. What's that for?