I am writing a game engine, and I need a way to get the exact and exact "deltatime" value, from which to derive the current FPS for debugging, and also to limit the frame rate (this is important for our project).
After doing a bit of research, I found out that one of the best ways to do this is to use the WinAPI function QueryPerformanceCounter. GetTicksCountshould be used to prevent forward counter jumps , but this alone is not very accurate.
Now the problem with QueryPerformanceCounteris that it apparently can return values that would look if the time was distorted (i.e., a call can return a value earlier in time relative to another call in the past). This only happens when the value obtained with a particular processor core is compared with the value obtained with another processor core, which leads me to the final questions that motivated me to make this post:
- Can the OS "redistribute" the thread to another kernel while the thread is already running, or is the thread assigned to that kernel and what until the thread dies?
- If the stream cannot be redistributed (and at least it makes a lot of sense to me), then why is it possible for me to do something like this
SetThreadAffinityMask(GetCurrentThread(),mask)? Ogre3D does that in its Ogre :: Timer class (a Windows implementation) , and I assume that it avoids the return of time. But in order for this to be true, I would have to consider the possibility that threads will move from one core to another arbitrarily by the OS, which seems rather strange to me (not entirely clear).
I think that is all I wanted to know now. Thank.
source
share