Hello,
I'm writing a game engine and I need a way to get a precise and accurate "deltatime" value from which to derive the current FPS for debug and also to limit the framerate (this is important for our project).
Doing a bit of research, I found out one of the best ways to do this is to use WinAPI's QueryPerformanceCounter
function. GetTicksCount
has to be used to prevent forward counter leaps, but it in itself is not very accurate.
Now, the problem with QueryPerformanceCounter
is that it apparently may return values that would look like if time warped back (i.e. a call may return a value prior in time relative to another call in the past). This happens only when a value obtained with a given processor core is compared against a value obtained with another processor core, which leads me to the ultimate questions that motivated me to make this post:
- May the OS "reallocate" a thread to another core while the thread is already running, or is a thread is allocated to a given core and that's that until the thread dies?
- If a thread can't be reallocated (and that makes a lot of sense for me, at least), then why is it possible for me to do something like
SetThreadAffinityMask(GetCurrentThread(),mask)
? Ogre3D does that in its Ogre::Timer class (Windows implementation), and I'm assuming that's to avoid time going back. But for that to be true, then I would have to consider the possibility of threads being moved from one core to another arbitrarily by the OS, which seems rather odd to me (not sure why).
I think that was all I wanted to know for now. Thanks.