pub struct ClientPrediction {
pub input_buffer: InputBuffer,
pub predicted_pos: Vec3,
pub predicted_vel: Vec3,
pub last_acked_tick: u64,
pub correction_blend: f32,
/* private fields */
}Expand description
Client-side movement prediction with server reconciliation.
The client applies inputs locally before the server confirms them. When the server snapshot arrives, if our predicted position differs from the authoritative one, we roll back and replay unacked inputs.
Fields§
§input_buffer: InputBuffer§predicted_pos: Vec3Predicted entity position (local player).
predicted_vel: Vec3Predicted entity velocity.
last_acked_tick: u64Last tick acknowledged by the server.
correction_blend: f32Correction blend factor per frame (0.1 = smooth over ~10 frames).
Implementations§
Source§impl ClientPrediction
impl ClientPrediction
pub fn new() -> Self
Sourcepub fn apply_input<F>(&mut self, input: PlayerInput, dt: f32, simulate: F)
pub fn apply_input<F>(&mut self, input: PlayerInput, dt: f32, simulate: F)
Apply input locally using the provided simulate function.
simulate(pos, vel, input, dt) -> (new_pos, new_vel).
Sourcepub fn reconcile<F>(
&mut self,
server_pos: Vec3,
server_vel: Vec3,
server_tick: u64,
dt: f32,
simulate: F,
)
pub fn reconcile<F>( &mut self, server_pos: Vec3, server_vel: Vec3, server_tick: u64, dt: f32, simulate: F, )
Called when an authoritative server state arrives. Rolls back to the server position and replays unacked inputs.
Sourcepub fn tick_correction(&mut self) -> Vec3
pub fn tick_correction(&mut self) -> Vec3
Advance correction blend each frame. Returns the visually rendered position.
pub fn is_correcting(&self) -> bool
Trait Implementations§
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.