P2PSession

Struct P2PSession 

Source
pub struct P2PSession<T>(/* private fields */)
where
    T: Config;
Expand description

The main peer-to-peer Backroll session.

This type internally wraps an Arc<RwLock<…>>, so it is safe to send and access across threads, and is cheap to clone.

Implementations§

Source§

impl<T: Config> P2PSession<T>

Source

pub fn build() -> P2PSessionBuilder<T>

Source

pub fn player_count(&self) -> usize

Gets the number of players in the current session. This includes users that are already disconnected.

Source

pub fn in_rollback(&self) -> bool

Checks if the session currently in the middle of a rollback.

Source

pub fn current_frame(&self) -> i32

Gets the current frame of the game.

Source

pub fn local_players(&self) -> SmallVec<[PlayerHandle; 8]>

Source

pub fn remote_players(&self) -> SmallVec<[PlayerHandle; 8]>

Source

pub fn is_synchronized(&self) -> bool

Checks if all remote players are synchronized. If all players are local, this will always return true.

Source

pub fn add_local_input( &self, player: PlayerHandle, input: T::Input, ) -> BackrollResult<()>

Adds a local input for the current frame. This will register the input in the local input queues, as well as queue the input to be sent to all remote players. If called multiple times for the same player without advancing the session with advance_frame, the previously queued input for the frame will be overwritten.

For a corrrect simulation, this must be called on all local players every frame before calling advance_frame.

§Errors

Returns BackrollError::InRollback if the session is currently in the middle of a rollback.

Returns BackrollError::NotSynchronized if the all of the remote peers have not yet synchornized.

Returns BackrollError::InvalidPlayer if the provided player handle does not point a vali player.

§Panics

This function will panic if the player is not a local player.

Source

pub fn advance_frame(&self) -> Commands<T>

Advances the game simulation by a single frame. This will issue a Command::AdvanceFrame then check if the simulation is consistent with the inputs sent by remote players. If not, a rollback will be triggered, and the game will be resimulated from the point of rollback.

For a corrrect simulation, add_local_input must be called on all local players every frame before calling this. If any call to add_local_input fails, this should not be called.

All of the provided commands must be executed in order, and must not be reordered or skipped.

Source

pub fn poll(&self) -> Commands<T>

Flushes lower level network events. This should always be called before adding local inputs every frame of the game regardless of if the game is advancing it’s state or not.

All of the provided commands must be executed in order, and must not be reordered or skipped.

Source

pub fn disconnect_player( &self, player: PlayerHandle, ) -> BackrollResult<Commands<T>>

Disconnects a player from the game.

If called on a local player, this will disconnect the client from all remote peers.

If called on a remote player, this will disconnect the connection with only that player.

§Errors

Returns BackrollError::InvalidPlayer if the provided player handle does not point a vali player.

Returns BackrollError::PlayerDisconnected if the provided player is already disconnected.

Source

pub fn get_network_stats( &self, player: PlayerHandle, ) -> BackrollResult<NetworkStats>

Gets network statistics with a remote player.

§Errors

Returns BackrollError::InvalidPlayer if the provided player handle does not point a vali player.

Source

pub fn set_frame_delay( &self, player: PlayerHandle, delay: i32, ) -> BackrollResult<()>

Sets the frame delay for a given player.

§Errors

Returns BackrollError::InvalidPlayer if the provided player handle does not point a vali player.

Trait Implementations§

Source§

impl<T: Config> Clone for P2PSession<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for P2PSession<T>

§

impl<T> !RefUnwindSafe for P2PSession<T>

§

impl<T> Send for P2PSession<T>

§

impl<T> Sync for P2PSession<T>

§

impl<T> Unpin for P2PSession<T>

§

impl<T> !UnwindSafe for P2PSession<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more