pub struct ClientPrediction { /* private fields */ }Expand description
Client-side prediction with server reconciliation.
Implementations§
Source§impl ClientPrediction
impl ClientPrediction
pub fn new(entity_id: SyncEntityId) -> Self
pub fn entity_id(&self) -> SyncEntityId
pub fn set_correction_threshold(&mut self, threshold: f32)
pub fn set_correction_duration(&mut self, duration: f32)
pub fn misprediction_rate(&self) -> f64
pub fn pending_count(&self) -> usize
Sourcepub fn record_input(
&mut self,
timestamp_ms: u64,
input_data: Vec<u8>,
predicted_position: [f32; 3],
predicted_rotation: [f32; 4],
predicted_velocity: [f32; 3],
) -> u32
pub fn record_input( &mut self, timestamp_ms: u64, input_data: Vec<u8>, predicted_position: [f32; 3], predicted_rotation: [f32; 4], predicted_velocity: [f32; 3], ) -> u32
Record a new predicted input. Returns the sequence number.
Sourcepub fn reconcile(
&mut self,
server_sequence: u32,
server_position: [f32; 3],
server_rotation: [f32; 4],
server_velocity: [f32; 3],
apply_input: &dyn Fn(&[u8], [f32; 3], [f32; 4], [f32; 3]) -> ([f32; 3], [f32; 4], [f32; 3]),
) -> [f32; 3]
pub fn reconcile( &mut self, server_sequence: u32, server_position: [f32; 3], server_rotation: [f32; 4], server_velocity: [f32; 3], apply_input: &dyn Fn(&[u8], [f32; 3], [f32; 4], [f32; 3]) -> ([f32; 3], [f32; 4], [f32; 3]), ) -> [f32; 3]
Process a server authoritative state update. Returns the corrected position after reconciliation.
Sourcepub fn visual_position(&self, predicted_position: [f32; 3], dt: f32) -> [f32; 3]
pub fn visual_position(&self, predicted_position: [f32; 3], dt: f32) -> [f32; 3]
Get the visual position with smoothed correction applied.
Sourcepub fn update_correction(&mut self, dt: f32)
pub fn update_correction(&mut self, dt: f32)
Tick the correction timer.
Sourcepub fn unacknowledged_inputs(&self) -> Vec<&PredictionEntry>
pub fn unacknowledged_inputs(&self) -> Vec<&PredictionEntry>
Get inputs that haven’t been acknowledged yet, for retransmission.
Sourcepub fn acknowledge_up_to(&mut self, sequence: u32)
pub fn acknowledge_up_to(&mut self, sequence: u32)
Mark inputs as acknowledged up to and including the given sequence.
pub fn clear(&mut self)
pub fn server_position(&self) -> [f32; 3]
pub fn server_rotation(&self) -> [f32; 4]
Auto Trait Implementations§
impl Freeze for ClientPrediction
impl RefUnwindSafe for ClientPrediction
impl Send for ClientPrediction
impl Sync for ClientPrediction
impl Unpin for ClientPrediction
impl UnsafeUnpin for ClientPrediction
impl UnwindSafe for ClientPrediction
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.