ClockObject.getRealTime() drift


I’m about to make a multiplayer game, and I need an accurate clock. I’ve been told globalClock.getRealTime() is the most accurate clock there is, but that about this:

What does that really mean? How does it drift? Is it the same for everyone? Can I reset the clock somehow to minimize the drifting?

It means if you let it run for a couple of days, it won’t necessarily return an accurate count of the total number of seconds that have elapsed over those days. The time is not consistent between machines; on some machines it will have gained several seconds over a couple of days; on other machines it will have lost several seconds over the same period of time. Some machines are particularly inaccurate, by as much as a couple of seconds an hour. Regardless, this is still an excellent timer for measuring things very precisely.

Usually this is not a concern. For a typical game, the kind of precision offered by globalClock.getRealTime() is the right kind of precision. You need the other kind of accuracy for things like wall clocks and wristwatches, not for multiplayer games.

Incidentally, the reason there’s a difference is because of the operating system. globalClock.getRealTime() comes from the QueryPerformanceCounter in windows, which has exactly these properties of being precise on the small scale, but relatively inaccurate in the large scale. Windows offers a different clock for time which is relatively accurate on the large scale but imprecise for small measurements. Other operating systems, for instance Linux and OS X, don’t have this confusing interface; they offer just one clock, and it’s both precise for small time and accurate over large time. On these operating systems, globalClock.getRealTime() is also both precise for small time and accurate over large time.

Finally, you can set:

paranoid-clock 1

in your Config.prc file to keep your globalClock.getRealTime() time in sync with time-of-day time, so that it will be accurate over the long haul if for some crazy reason you really need this.


Thank you!