Clock story in TimeManager

From FlightGear wiki
Revision as of 20:53, 15 January 2021 by Jano (talk | contribs) (→‎before 2021: main text)
Jump to navigation Jump to search
This article is a stub. You can help the wiki by expanding it.

Clock story, an exploration of timeManager.cxx

We'll make a travel in the clock's country, to understand what's happening in TimeManager.cxx. Initially only dedicated to calculate the frame time increment (dt) passed to lot's of subsystems in the update loops, but now having a responsibility in time synchronization between different FG session.

Prior 2018

The simulation time: the simulated time clock was something basic, we started at 0, do some clamping on the delta, (sim/max-simtime-per-frame) then only allow dt to be multiple of 1/modelHz (120 by default) this give a "dtRemainder" difference between the time we mesured, and the time we keep as timestamp; Then is applied time acceleration, giving a sim time unrelated to real time flow, for time accel != 1

we have a clock :

  • having 1/modelHz as basic step (before time accel)
  • able to pause
  • suffering for acceleration if time accel is used

This simulation time was used for the flight simulation as intended, but was the timestamp reference for mp protocol. That's what lead to the 2018 change, the need to a clock for the mp protocol, not based on simulated time, but a "real time" timestamp.

2018 - 2020

The multiplayer achitecture (multi server), and the slow mp packet sending rate made impossible a good synchronization with only a server ping, so we moved to a "real time" way of addressing lag issues, helped by the introduction of 2 clocks in TimeManager.

We still have the same way of providing the simulation time dt, with the same characteristics as before, but we added:

  • a "steady" clock: this clock start synchronized to the wall clock, then follow the "dt" increment, without pausing and accelerating, using a monotonic timer. The goal is to have the wall clock tuned by ntp or ptp, and the different mp pilot are in time with each other by relying on dedicated network time service.

We provide a way to know if the steady clock is still on time with the wall clock, setting "sim/time/compute-clock-drift" to "true" give the current difference in "sim/time/steady-clock-drift-ms"

  • the mpprotocol clock: if the ntp works well, it's the same as the steady clock, but to cope with player not sing ntp, or eg flying with a recorded flight, there's an offset to adjust this mpprotocol clock relative to the steady clock (sim/time/mp-clock-offset_sec). this clock give us the timestamp used in the mp protocol.

This offset is exposed in the lag menu, if you need it :) (more to see here).

This was a bit of a headhache to add in the TimeManager, but the result is quite good (for who know how to set it up, still need improvement for the end user)

Maybe you've noticed that those changes were made only during winter, so the question is, what needed to be changed this winter ?

2021 (hopefully)