Struct Client

Source
pub struct Client<GameT, StepT>
where GameT: GameCallbacks<StepT> + Debug, StepT: Clone + Deserialize + Serialize + Debug + Display,
{ pub prediction_time_tick: TimeTick, /* private fields */ }
Expand description

The main client structure handling datagram communication, participant management, and input (step) prediction.

The Client does not handle game logic directly but relies on external game logic provided through the GameCallbacks trait.

Fields§

§prediction_time_tick: TimeTick

Implementations§

Source§

impl<StepT, GameT> Client<GameT, StepT>
where StepT: Clone + Deserialize + Serialize + Debug + Display + Eq, GameT: GameCallbacks<StepT> + Debug,

Source

pub fn new(now: Millis) -> Client<GameT, StepT>

Creates a new Client instance with the given current time.

§Arguments
  • now - The current time in milliseconds.
Source

pub const fn with_tick_duration( self, tick_duration: MillisDuration, ) -> Client<GameT, StepT>

Source

pub fn send(&mut self, now: Millis) -> Result<Vec<Vec<u8>>, ClientError>

Creates outgoing messages and returns the serialized datagrams.

This method collects messages prepared by the client logic, serializes them into datagrams, updates network metrics, and returns the datagrams. They are usually sent over some datagram transport.

§Arguments
  • now - The current time in milliseconds.
§Returns

A Result containing a vector of serialized datagrams or a ClientError.

§Errors

Returns ClientError if serialization or sending fails.

Source

pub fn receive( &mut self, now: Millis, datagram: &[u8], ) -> Result<(), ClientError>

Receives and processes an incoming datagram.

This method handles incoming datagrams by updating metrics, deserializing the datagram, and passing the contained commands to the client logic for further processing.

§Arguments
  • millis - The current time in milliseconds.
  • datagram - The received datagram bytes.
§Returns

A Result indicating success or containing a ClientError.

§Errors

Returns ClientError if deserialization or processing fails.

Source

pub const fn debug_rectify( &self, ) -> &Rectify<GameT, SeqMap<ParticipantId, Step<StepT>>>

Source

pub fn update(&mut self, now: Millis) -> Result<(), ClientError>

Updates the client’s phase and handles synchronization tasks based on the current time.

This includes updating the network layer, metrics, tick durations, processing authoritative steps, and managing prediction phases.

§Arguments
  • now - The current time in milliseconds.
§Returns

A Result indicating success or containing a ClientError.

§Errors

Returns ClientError if any internal operations fail.

Source

pub const fn game(&self) -> Option<&GameT>

Retrieves a reference to the current game instance, if available.

Note: The Client does not manage game logic directly. This method provides access to the game state managed externally via callbacks.

§Returns

An Option containing a reference to CallbacksT or None if no game is active.

Source

pub fn required_prediction_count(&self) -> usize

Determines the number of predictions needed based on the current state.

§Returns

The number of predictions needed as a usize.

Source

pub const fn can_join_player(&self) -> bool

Checks if a new player can join the game session.

§Returns

true if a player can join, false otherwise.

Source

pub fn local_players(&self) -> Vec<LocalPlayer>

Retrieves a list of local players currently managed by the client.

§Returns

A vector of LocalPlayer instances.

Source

pub fn push_predicted_step( &mut self, tick_id: TickId, step: &SeqMap<ParticipantId, StepT>, ) -> Result<(), ClientError>

Adds a predicted input (step) to the client’s logic and rectification system.

This method serializes predicted steps into datagrams (in the future) in upcoming send() function calls.

§Arguments
  • tick_id - The tick identifier for the predicted step.
  • step - The predicted step data.
§Returns

A Result indicating success or containing a ClientError.

§Errors

Returns ClientError if the prediction queue is full or if processing fails.

Source

pub fn latency(&self) -> Option<MinMaxAvg<u16>>

Retrieves the current transmission round trip latency metrics.

§Returns

An Option containing MinMaxAvg<u16> representing latency metrics, or None if unavailable.

Source

pub fn metrics(&self) -> CombinedMetrics

Retrieves the combined network metrics.

§Returns

A CombinedMetrics instance containing various network metrics.

Source

pub fn server_buffer_delta_ticks(&self) -> Option<i16>

Retrieves the delta ticks on the host for the incoming predicted steps A negative means that the incoming buffer is too low, a larger positive number means that the buffer is too big, and the prediction should slow down.

§Returns

An Option containing the delta ticks as i16, or None if unavailable.

Source

pub fn request_join_player( &mut self, local_players: Vec<u8>, ) -> Result<(), ClientError>

Requests to join a new player with the specified local indices.

This method sends a request to the host to add new participants to the game session.

§Arguments
  • local_players - A vector of LocalIndex representing the local players to join.
§Returns

A Result indicating success or containing a ClientError.

§Errors

ClientError // TODO:

Auto Trait Implementations§

§

impl<GameT, StepT> Freeze for Client<GameT, StepT>
where GameT: Freeze,

§

impl<GameT, StepT> RefUnwindSafe for Client<GameT, StepT>
where GameT: RefUnwindSafe, StepT: RefUnwindSafe,

§

impl<GameT, StepT> Send for Client<GameT, StepT>
where GameT: Send, StepT: Send,

§

impl<GameT, StepT> Sync for Client<GameT, StepT>
where GameT: Sync, StepT: Sync,

§

impl<GameT, StepT> Unpin for Client<GameT, StepT>
where GameT: Unpin, StepT: Unpin,

§

impl<GameT, StepT> UnwindSafe for Client<GameT, StepT>
where GameT: UnwindSafe, StepT: UnwindSafe,

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.