High resolution counter

Started by
11 comments, last by GameDev.net 18 years, 11 months ago
The speed of the code itself doesn't matter.
For example, lets say that on PC1, a frame takes 1 second, and on a PC2 it takes 2 seconds.
Also, lets have a monster that travels 10 pixels per second.

If you have the code
monster.position = monster.position + 10;
then it will move differently on PC1 and PC2 because they run at different speeds

If you have
monster.position = monster.position + (10 * frame_length);
then on PC1, frame_length is 1.0 (for 1 second) so the monster moves 10 pixels in 1 second, but on PC2 frame_length is 2.0 (for 2 seconds) so the monster moves 20 pixels in 2 seconds which is equal to 10 pixesl per second. Because you put the amount of time passed into the equation, both computers end up with the monster in the same place.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Advertisement
"Two things: Don't use QueryPerformance*, because it doesn't work properly on computers that vary their cpu speed. Almost all laptops do this, and most modern pentium 4 processors do as well (and in the future, AMDs will likely do the same)."

Isn't this just an urban legend?

The frequency is the frequency of the timer and not the CPU.
If there was such a problem, would it not be mentioned on msdn?
"If you have monster.position = monster.position + (10 * frame_length);
then on PC1, frame_length is 1.0 (for 1 second) so the monster moves 10 pixels in 1 second, but on PC2 frame_length is 2.0 (for 2 seconds) so the monster moves 20 pixels in 2 seconds which is equal to 10 pixesl per second. Because you put the amount of time passed into the equation, both computers end up with the monster in the same place."

If you are using floats then they will not end up at the same place. Thats why you should run an app at a certain tickrate.

This topic is closed to new replies.

Advertisement