0
\$\begingroup\$

Tutorials wrote Sys.getTimerResolution() for LWJGL time method.

public long getTime() {
   return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}

I thought Sys.getTimerResolution() is just 1000. So the shorter way gives same value.

// shorter way
public long getTime() {
   reutrn Sys.getTime();
}    

Is Sys.getTimerResolution() value always 1000?

\$\endgroup\$
0
\$\begingroup\$

After looking at the source code for LWJGL, the function Sys.getTimerResolution() is potentially different for every operating system. However, currently it is the same on every platform.

This function should not be assumed to be 1000 all the time as not every platform can provide the same time resolution as others (Although currently they do). To support future versions of LWJGL and cross-compatibility, you should use the first example you gave.

You are correct that the two values cancel each other out in the second example but as I said, this is done just in case the game runs on a platform with different time resolution in the future.

Currently, all platform implementations inherit DefaultSysImplementation which is where the value of 1000 is derived.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.