Struct crystalorb::clocksync::ClockSyncer [−][src]
pub struct ClockSyncer { /* fields omitted */ }
Expand description
Client-side clock syncing logic. This is responsible for sending out clock synchronization request messages to the server, and handling the server’s responses. This also serves double duty for determining what client identifier has been allocated by the server to this client. For each server response, a sample of the time clock offset between the client and the server is calculated, and a rolling average (ignoring outliers) of these samples is used to update the effective clock offset that is used by the client once the effective clock offset deviates too far from the rolling average.
Implementations
Create a new ClockSyncer
with the given configuration parameters. The ClockSyncer
will start off in a “not ready” state until after multiple
update
calls. During the time when the ClockSyncer
is not
ready, some of the methods may return None
as documented.
Perform the next update, where the ClockSyncer
tries to gather more information about
the client-server clock differences and makes adjustments when needed.
Panics
Panics when the ClockSyncer
receives inconsistent client_id
values from the server.
Whether the ClockSyncer
has enough information to make useful estimates.
It is guaranteed that once the ClockSyncer
becomes “ready”, it stays “ready”.
TODO: Enforce this invariant.
How many measurement samples the ClockSyncer
has collected and currently stored.
Previously collected samples that have since then been discarded are not counted. This
merely counts the number of samples in the current moving window.
How many samples are needed to start making useful estimates.
An identifier issued by the server for us to identify ourselves from other clients. Used, for example, for issuing our player’s commands to the server.
This is None
if no server responses had been received yet.
The difference in seconds between client’s seconds_since_startup
and server’s
seconds_since_startup
, where a positive value refers that an earlier client time value
corresponds to the same instant as a later server time value. Since servers start
earlier than clients, this value should in theory always be positive. The value stored
here is the “effective” offset that is used by the client, and may be up to date with
the latest measurements.
Before initialization, the value is None
.
Convert local client seconds since startup into server seconds since startup using the latest estimated time difference between the client and the server, if available.
Trait Implementations
Performs the conversion.
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for ClockSyncer
impl Send for ClockSyncer
impl Sync for ClockSyncer
impl Unpin for ClockSyncer
impl UnwindSafe for ClockSyncer