pub fn record_server_tick(
        &mut self,
        server_tick: u16,
        ping_average: f32,
        jitter_deviation: f32,
    ) {
        self.server_tick_running_diff += wrapping_diff(self.server_tick, server_tick);

        // Decay the diff so that small fluctuations are acceptable
        if self.server_tick_running_diff > 0 {
            self.server_tick_running_diff = self.server_tick_running_diff.wrapping_sub(1);
        }
        if self.server_tick_running_diff < 0 {
            self.server_tick_running_diff = self.server_tick_running_diff.wrapping_add(1);
        }

        // If the server tick is far off enough, reset to the received server tick
        if self.server_tick_running_diff.abs() > 8 {
            self.server_tick = server_tick;
            self.server_tick_running_diff = 0;
        }

        // Calculate incoming & outgoing jitter buffer tick offsets
        let jitter_based_offset = jitter_deviation * 3.0;
        self.server_tick_adjust = (jitter_based_offset / self.tick_interval_millis).ceil() as u16;

        // NOTE: I've struggled multiple times with why (ping_average * 2.0) exists in
        // this calculation, figured it out, then returned to struggle later.
        // This is not a bug!
        // Keep in mind that self.server_tick here is the tick we have RECEIVED from the
        // Server which means that the real current server_tick is likely
        // self.server_tick + ping_average / tick_interval By multiplying the
        // ping average here, we are correcting for our late self.server_tick value
        let target_client_adjust_millis = self
            .minimum_latency
            .max((ping_average * 2.0) + jitter_based_offset);
        self.client_tick_adjust =
            ((target_client_adjust_millis / self.tick_interval_millis) + 1.0).ceil() as u16;
    }
/// Using information from the Server and RTT/Jitter measurements, determine
/// the appropriate future intended tick
Using information from the Server and RTT/Jitter measurements, determine
the appropriate future intended tick
Using information from the Server and RTT / Jitter measurements determine the appropriate future intended tick
pub fn record_server_tick(
        &mut self,
        server_tick: u16,
        ping_average: f32,
        jitter_deviation: f32,
    ) {
        self.server_tick_running_diff += wrapping_diff(self.server_tick, server_tick);
        // Decay the diff so that small fluctuations are acceptable
        if self.server_tick_running_diff > 0 {
            self.server_tick_running_diff = self.server_tick_running_diff.wrapping_sub(1);
        }
        if self.server_tick_running_diff < 0 {
            self.server_tick_running_diff = self.server_tick_running_diff.wrapping_add(1);
        }
        // If the server tick is far off enough, reset to the received server tick
        if self.server_tick_running_diff.abs() > 8 {
            self.server_tick = server_tick;
            self.server_tick_running_diff = 0;
        }
        // Calculate incoming & outgoing jitter buffer tick offsets
        let jitter_based_offset = jitter_deviation * 3.0;
        self.server_tick_adjust = (jitter_based_offset / self.tick_interval_millis).ceil() as u16;
        // NOTE: I've struggled multiple times with why (ping_average * 2.0) exists in
        // this calculation, figured it out, then returned to struggle later.
        // This is not a bug!
        // Keep in mind that self.server_tick here is the tick we have RECEIVED from the
        // Server which means that the real current server_tick is likely
        // self.server_tick + ping_average / tick_interval By multiplying the
        // ping average here, we are correcting for our late self.server_tick value
        let target_client_adjust_millis = self
            .minimum_latency
            .max((ping_average * 2.0) + jitter_based_offset);
        self.client_tick_adjust =
            ((target_client_adjust_millis / self.tick_interval_millis) + 1.0).ceil() as u16;
    }
pub fn record_server_tick ( & mut self , server_tick : u16 , ping_average : f32 , jitter_deviation : f32 , ) { self . server_tick_running_diff += wrapping_diff ( self . server_tick , server_tick ) ; // Decay the diff so that small fluctuations are acceptable if self . server_tick_running_diff > 0 { self . server_tick_running_diff = self . server_tick_running_diff . wrapping_sub ( 1 ) ; } if self . server_tick_running_diff < 0 { self . server_tick_running_diff = self . server_tick_running_diff . wrapping_add ( 1 ) ; } // If the server tick is far off enough, reset to the received server tick if self . server_tick_running_diff . abs ( ) > 8 { self . server_tick = server_tick ; self . server_tick_running_diff = 0 ; } // Calculate incoming & outgoing jitter buffer tick offsets let jitter_based_offset = jitter_deviation * 3.0 ; self . server_tick_adjust = ( jitter_based_offset / self . tick_interval_millis ) . ceil ( ) as u16 ; // NOTE: I've struggled multiple times with why (ping_average * 2.0) exists in // this calculation, figured it out, then returned to struggle later. // This is not a bug! // Keep in mind that self.server_tick here is the tick we have RECEIVED from the // Server which means that the real current server_tick is likely // self.server_tick + ping_average / tick_interval By multiplying the // ping average here, we are correcting for our late self.server_tick value let target_client_adjust_millis = self . minimum_latency . max ( ( ping_average * 2.0 ) + jitter_based_offset ) ; self . client_tick_adjust = ( ( target_client_adjust_millis / self . tick_interval_millis ) + 1.0 ) . ceil ( ) as u16 ; }
Using information from the Server and RTT/Jitter measurements, determine
the appropriate future intended tick
Using information from the Server and RTT / Jitter measurements determine the appropriate future intended tick
&mut self
server_tick
u16
ping_average
f32
jitter_deviation
f32
&mut self
server_tick
u16
ping_average
f32
jitter_deviation
f32