QcSnapshotClock Class
Chooses the moment of server time at which the client shows other players and creatures (decision E-271). More...
| Header: | #include <clientcore/session/QcSnapshotClock.h> |
Public Functions
| std::optional<double> | advance(qint64 localMs) |
| std::size_t | arrivalCount() const |
| double | delayMs() const |
| double | intervalMs() const |
| qint64 | latestServerMs() const |
| void | observe(qint64 serverMs, qint64 localMs) |
| void | restart() |
Static Public Members
| const double | baseDelayMs |
| const double | defaultIntervalMs |
| const double | jitterAllowanceMs |
| const std::size_t | maxArrivals |
| const double | maxIntervalMs |
| const double | maxSlew |
| const double | snapIntervalFactor |
| const double | snapMs |
| const double | windowMs |
Detailed Description
Every EntityMoves carries the server's time of its tick; the clock pairs it with the local time it arrived. The fastest arrival of the last two seconds (the smallest lag of local behind server time) is the best estimate of "now" on the server; the client shows delayMs() before that, so snapshots that come late by up to that much minus a tick are already there when they are needed. The shown moment does not jump when the estimate moves with other arrivals: the shown time runs at most 10 % faster or slower until it caught up. A change of more than a second, or of the snapshot interval by a factor of two or more (another tick rate), is taken at once (decision E-277).
Member Function Documentation
std::optional<double> QcSnapshotClock::advance(qint64 localMs)
Moves the shown moment on to local time localMs (once per client tick) and returns the server time to show; std::nullopt before the first snapshot.
std::size_t QcSnapshotClock::arrivalCount() const
Returns the number of arrivals kept.
double QcSnapshotClock::delayMs() const
Returns how far the shown moment lies behind the estimated "now" on the server: the larger of baseDelayMs and intervalMs() plus jitterAllowanceMs.
double QcSnapshotClock::intervalMs() const
Returns the time between two snapshots (the server's tick interval, 50 ms at 20 ticks per second).
qint64 QcSnapshotClock::latestServerMs() const
Returns the newest server time that arrived (-1 before the first).
void QcSnapshotClock::observe(qint64 serverMs, qint64 localMs)
A snapshot of server time serverMs arrived at local time localMs.
void QcSnapshotClock::restart()
The server's time stood still while the local time went on (a pause, decision E-877): the next snapshot starts a new history, so the shown moment neither runs ahead of it nor waits out the old lag.
Member Variable Documentation
const double QcSnapshotClock::baseDelayMs
The shown moment lies at least this far behind the newest snapshot that could have arrived.
const double QcSnapshotClock::defaultIntervalMs
The interval between two snapshots assumed before it is measured.
const double QcSnapshotClock::jitterAllowanceMs
Lateness covered on top of the interval between two snapshots: delay = max(base, interval + this).
const std::size_t QcSnapshotClock::maxArrivals
Arrivals kept at most, whatever the window holds (a server sending many messages per tick).
const double QcSnapshotClock::maxIntervalMs
Largest interval estimate taken.
const double QcSnapshotClock::maxSlew
Share by which the shown time runs at most faster or slower to catch up.
const double QcSnapshotClock::snapIntervalFactor
An interval estimate this many times larger or smaller snaps the shown time.
const double QcSnapshotClock::snapMs
A change of the wanted lag by more than this is taken at once.
const double QcSnapshotClock::windowMs
Arrivals of this many milliseconds back count for the fastest one.