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>
impl<T: Config> P2PSession<T>
Sourcepub fn add_local_input(
&mut self,
player_handle: PlayerHandle,
input: T::Input,
) -> Result<(), GgrsError>
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.
Sourcepub fn advance_frame(&mut self) -> Result<Vec<GgrsRequest<T>>, GgrsError>
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.
Sourcepub fn poll_remote_clients(&mut self)
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.
Sourcepub fn disconnect_player(
&mut self,
player_handle: PlayerHandle,
) -> Result<(), GgrsError>
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.
Sourcepub fn network_stats(
&self,
player_handle: PlayerHandle,
) -> Result<NetworkStats, GgrsError>
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.
Sourcepub fn confirmed_frame(&self) -> Frame
pub fn confirmed_frame(&self) -> Frame
Returns the highest confirmed frame. We have received all input for this frame and it is thus correct.
Sourcepub fn current_frame(&self) -> Frame
pub fn current_frame(&self) -> Frame
Returns the current frame of a session.
Sourcepub fn max_prediction(&self) -> usize
pub fn max_prediction(&self) -> usize
Returns the maximum prediction window of a session.
Sourcepub fn in_lockstep_mode(&mut self) -> bool
pub fn in_lockstep_mode(&mut self) -> bool
Returns true if the session is running in lockstep mode.
In lockstep mode, a session will only advance if the current frame has inputs confirmed from all other players.
Sourcepub fn current_state(&self) -> SessionState
pub fn current_state(&self) -> SessionState
Returns the current SessionState
of a session.
Sourcepub fn events(&mut self) -> Drain<'_, GgrsEvent<T>>
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.
Sourcepub fn num_players(&self) -> usize
pub fn num_players(&self) -> usize
Returns the number of players added to this session
Sourcepub fn num_spectators(&self) -> usize
pub fn num_spectators(&self) -> usize
Return the number of spectators currently registered
Sourcepub fn local_player_handles(&self) -> Vec<PlayerHandle> ⓘ
pub fn local_player_handles(&self) -> Vec<PlayerHandle> ⓘ
Returns the handles of local players that have been added
Sourcepub fn remote_player_handles(&self) -> Vec<PlayerHandle> ⓘ
pub fn remote_player_handles(&self) -> Vec<PlayerHandle> ⓘ
Returns the handles of remote players that have been added
Sourcepub fn spectator_handles(&self) -> Vec<PlayerHandle> ⓘ
pub fn spectator_handles(&self) -> Vec<PlayerHandle> ⓘ
Returns the handles of spectators that have been added
Sourcepub fn handles_by_address(&self, addr: T::Address) -> Vec<PlayerHandle> ⓘ
pub fn handles_by_address(&self, addr: T::Address) -> Vec<PlayerHandle> ⓘ
Returns all handles associated to a certain address
Sourcepub fn frames_ahead(&self) -> i32
pub fn frames_ahead(&self) -> i32
Returns the number of frames this session is estimated to be ahead of other sessions
Sourcepub fn desync_detection(&self) -> DesyncDetection
pub fn desync_detection(&self) -> DesyncDetection
Returns the DesyncDetection
mode set for this session at creation time.