pub struct LagCompensation { /* private fields */ }Expand description
Server-side lag compensation: rewinds game state to a client’s perceived point in time for accurate hit registration.
Implementations§
Source§impl LagCompensation
impl LagCompensation
Sourcepub fn new(max_history_ms: f64, tick_rate_hz: f64) -> Self
pub fn new(max_history_ms: f64, tick_rate_hz: f64) -> Self
max_history_ms should be at least the maximum expected client RTT.
pub fn default_one_second() -> Self
Sourcepub fn record(&mut self, snap: GameStateSnapshot)
pub fn record(&mut self, snap: GameStateSnapshot)
Record the authoritative server state each tick.
Sourcepub fn rewind_to_tick(&self, target_tick: u64) -> Option<&GameStateSnapshot>
pub fn rewind_to_tick(&self, target_tick: u64) -> Option<&GameStateSnapshot>
Rewind to the state at target_tick.
Returns None if the tick is outside the history window.
Sourcepub fn rewind_for_client(
&self,
client_tick: u64,
rtt_ms: f64,
) -> Option<&GameStateSnapshot>
pub fn rewind_for_client( &self, client_tick: u64, rtt_ms: f64, ) -> Option<&GameStateSnapshot>
Rewind to approximate server tick that a client with rtt_ms round-trip
and client_tick would have been seeing.
Sourcepub fn entity_at_tick(
&self,
entity_id: u64,
tick: u64,
) -> Option<&EntitySnapshot>
pub fn entity_at_tick( &self, entity_id: u64, tick: u64, ) -> Option<&EntitySnapshot>
Get the entity state at a particular tick (for hit detection).
pub fn oldest_tick(&self) -> Option<u64>
pub fn latest_tick(&self) -> Option<u64>
pub fn history_len(&self) -> usize
Auto Trait Implementations§
impl Freeze for LagCompensation
impl RefUnwindSafe for LagCompensation
impl Send for LagCompensation
impl Sync for LagCompensation
impl Unpin for LagCompensation
impl UnsafeUnpin for LagCompensation
impl UnwindSafe for LagCompensation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.