Struct ggrs::P2PSession

source ·
pub struct P2PSession<T>
where T: Config,
{ /* private fields */ }
Expand description

A P2PSession provides all functionality to connect to remote clients in a peer-to-peer fashion, exchange inputs and handle the gamestate by saving, loading and advancing.

Implementations§

source§

impl<T: Config> P2PSession<T>

source

pub fn add_local_input( &mut self, player_handle: PlayerHandle, input: T::Input ) -> Result<(), GgrsError>

Registers local input for a player for the current frame. This should be successfully called for every local player before calling advance_frame(). If this is called multiple times for the same player before advancing the frame, older given inputs will be overwritten.

§Errors
  • Returns InvalidRequest when the given handle does not refer to a local player.
source

pub fn advance_frame(&mut self) -> Result<Vec<GgrsRequest<T>>, GgrsError>

You should call this to notify GGRS that you are ready to advance your gamestate by a single frame. Returns an order-sensitive Vec<GgrsRequest>. You should fulfill all requests in the exact order they are provided. Failure to do so will cause panics later.

§Errors
  • Returns InvalidRequest if the provided player handle refers to a remote player.
  • Returns NotSynchronized if the session is not yet ready to accept input. In this case, you either need to start the session or wait for synchronization between clients.
source

pub fn poll_remote_clients(&mut self)

Should be called periodically by your application to give GGRS a chance to do internal work. GGRS will receive packets, distribute them to corresponding endpoints, handle all occurring events and send all outgoing packets.

source

pub fn disconnect_player( &mut self, player_handle: PlayerHandle ) -> Result<(), GgrsError>

Disconnects a remote player and all other remote players with the same address from the session.

§Errors
  • Returns InvalidRequest if you try to disconnect a local player or the provided handle is invalid.
source

pub fn network_stats( &self, player_handle: PlayerHandle ) -> Result<NetworkStats, GgrsError>

Returns a NetworkStats struct that gives information about the quality of the network connection.

§Errors
  • Returns InvalidRequest if the handle not referring to a remote player or spectator.
  • Returns NotSynchronized if the session is not connected to other clients yet.
source

pub fn confirmed_frame(&self) -> Frame

Returns the highest confirmed frame. We have received all input for this frame and it is thus correct.

source

pub fn current_frame(&self) -> Frame

Returns the current frame of a session.

source

pub fn max_prediction(&self) -> usize

Returns the maximum prediction window of a session.

source

pub fn current_state(&self) -> SessionState

Returns the current SessionState of a session.

source

pub fn events(&mut self) -> Drain<'_, GgrsEvent<T>>

Returns all events that happened since last queried for events. If the number of stored events exceeds MAX_EVENT_QUEUE_SIZE, the oldest events will be discarded.

source

pub fn num_players(&self) -> usize

Returns the number of players added to this session

source

pub fn num_spectators(&self) -> usize

Return the number of spectators currently registered

source

pub fn local_player_handles(&self) -> Vec<PlayerHandle>

Returns the handles of local players that have been added

source

pub fn remote_player_handles(&self) -> Vec<PlayerHandle>

Returns the handles of remote players that have been added

source

pub fn spectator_handles(&self) -> Vec<PlayerHandle>

Returns the handles of spectators that have been added

source

pub fn handles_by_address(&self, addr: T::Address) -> Vec<PlayerHandle>

Returns all handles associated to a certain address

source

pub fn frames_ahead(&self) -> i32

Returns the number of frames this session is estimated to be ahead of other sessions

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>
where <T as Config>::Address: Unpin, <T as Config>::Input: Unpin,

§

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> 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>,

§

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>,

§

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