Struct InputQueue

Source
pub struct InputQueue { /* private fields */ }
Expand description

Deduplicates input redundancy and bounds per-client simulation backlog.

Checked admission preserves the legacy bool methods’ ordering and bounds. All TimedInput::shot_tick values (including a tick without a fire bit) remain accepted when the embedded frame is valid; authority rewind policy belongs to the consumer, not this queue. No protocol bytes are changed.

Receive controls independently of rendering or local menus. Pop only for an actual authoritative tick; a local overlay must not suspend network/replay progression. Queue metrics describe removal, not executed simulation work.

This supplied-input recipe recovers an older fire press while using newest movement. Hand the returned command and shot time to the authority’s fixed tick, then derive feedback from its accepted game events.

use ferravex_net::{
    BUTTON_FIRE, InputAdmissionError, InputFrame, InputQueue,
    InputQueueMetrics, TimedInput,
};

let mut queue = InputQueue::default();
queue.push_timed_checked(TimedInput {
    input: InputFrame {
        sequence: 40, yaw: 1.0, pitch: 0.25, buttons: BUTTON_FIRE,
        ..InputFrame::default()
    },
    shot_tick: Some(120),
}).unwrap();
let movement = InputFrame { sequence: 41, move_x: 1.0, ..InputFrame::default() };
queue.push_checked(movement).unwrap();
assert_eq!(queue.push_checked(movement), Err(InputAdmissionError::DuplicateNewest));
// At the next actual authority tick:
let command = queue.pop_latest_timed().unwrap();
assert_eq!(command.input.sequence, 41);
assert_eq!(command.input.move_x, 1.0);
assert_eq!((command.input.yaw, command.input.pitch), (1.0, 0.25));
assert_eq!(command.input.buttons, BUTTON_FIRE);
assert_eq!(command.shot_tick, Some(120));
let metrics = queue.metrics(); // Read-only copy for host diagnostics.
assert_eq!(metrics.returned_inputs, 1);
assert_eq!(metrics.coalesced_inputs, 1);
assert_eq!(metrics.rejected_duplicate_newest, 1);

// A round reset discards pending controls but keeps replay protection.
assert!(queue.push(InputFrame { sequence: 42, ..movement }));
queue.clear_pending();
assert_eq!(queue.metrics().discarded_inputs, 1);
assert_eq!(queue.push_checked(movement), Err(InputAdmissionError::OutOfOrder));
let previous_window = queue.reset_metrics();
assert_eq!(previous_window.accepted_inputs, 3);
assert_eq!(queue.metrics(), InputQueueMetrics::default());
assert!(!queue.push(InputFrame { sequence: 42, ..movement }));
// Only after the host establishes a new authenticated session:
queue.reset_session(); // Clears pending and watermark; retains metrics/storage.
assert!(queue.push(InputFrame::default()));

Implementations§

Source§

impl InputQueue

Source

pub fn push(&mut self, input: InputFrame) -> bool

Legacy admission; true exactly when Self::push_checked succeeds.

Source

pub fn push_timed(&mut self, timed: TimedInput) -> bool

Legacy timed admission; counts once through Self::push_timed_checked.

Source

pub fn push_checked( &mut self, input: InputFrame, ) -> Result<(), InputAdmissionError>

Append untimed controls or report the first rejection reason.

Equivalent to Self::push_timed_checked with no shot tick. See the InputQueue recipe for admission, coalescing and reset scopes.

Source

pub fn push_timed_checked( &mut self, timed: TimedInput, ) -> Result<(), InputAdmissionError>

Append timed controls, validating input, capacity, then sequence ordering.

Failure preserves all pending values and the watermark, and increments exactly one saturating rejection counter. Only the embedded frame is validated: shot_tick is opaque, as in the existing wire protocol. Success appends without eviction and advances the accepted watermark.

Source

pub fn metrics(&self) -> InputQueueMetrics

Read a copy of queue-local counters without changing any state.

Source

pub fn reset_metrics(&mut self) -> InputQueueMetrics

Begin a new metrics window and return the previous counters.

Pending inputs, allocated storage and the accepted sequence watermark are retained. Later removals can count inputs admitted before this reset.

Source

pub fn clear_pending(&mut self)

Discard queued controls while retaining the sequence watermark and metrics.

Increments discarded_inputs by the number removed; retains storage. Suitable for an authority round reset, never a local menu pause.

Source

pub fn reset_session(&mut self)

Discard pending controls and forget the accepted sequence watermark.

Retains allocated storage and metrics (including these discards). Call reset_metrics separately if a new reporting window is wanted. Use only when the host establishes a new session; using this for a round/menu would allow delayed controls from the same session to re-enter.

Source

pub fn pop(&mut self) -> Option<InputFrame>

Return the oldest input without its shot time, counting one returned entry.

Source

pub fn pop_latest(&mut self) -> Option<InputFrame>

Coalesce a burst to its newest movement/look sample without losing a queued action press. The authority still simulates exactly one fixed step. This prevents redundant commands recovered after loss from adding permanent control latency. Previously consumed commands cannot re-enter the queue.

Source

pub fn pop_latest_timed(&mut self) -> Option<TimedInput>

A recovered older quick-fire press retains its original aim and shot time.

Returns one entry and counts all older entries as coalesced. The newest fire sample wins if present; otherwise the oldest queued fire sample wins. Empty pops change no counters. Removal never resets the watermark.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Debug for InputQueue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for InputQueue

Source§

fn default() -> InputQueue

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.