Struct bones_framework::external::ggrs::P2PSession
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§
§impl<T> P2PSession<T>where
T: Config,
impl<T> P2PSession<T>where
T: Config,
pub fn add_local_input(
&mut self,
player_handle: usize,
input: <T as Config>::Input,
) -> Result<(), GgrsError>
pub fn add_local_input( &mut self, player_handle: usize, input: <T as Config>::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.
pub 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.
pub 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.
pub fn disconnect_player(
&mut self,
player_handle: usize,
) -> Result<(), GgrsError>
pub fn disconnect_player( &mut self, player_handle: usize, ) -> 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.
pub fn network_stats(
&self,
player_handle: usize,
) -> Result<NetworkStats, GgrsError>
pub fn network_stats( &self, player_handle: usize, ) -> 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.
pub fn confirmed_frame(&self) -> i32
pub fn confirmed_frame(&self) -> i32
Returns the highest confirmed frame. We have received all input for this frame and it is thus correct.
pub fn current_frame(&self) -> i32
pub fn current_frame(&self) -> i32
Returns the current frame of a session.
pub fn max_prediction(&self) -> usize
pub fn max_prediction(&self) -> usize
Returns the maximum prediction window of a session.
pub fn current_state(&self) -> SessionState
pub fn current_state(&self) -> SessionState
Returns the current SessionState
of a session.
pub 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.
pub fn num_players(&self) -> usize
pub fn num_players(&self) -> usize
Returns the number of players added to this session
pub fn num_spectators(&self) -> usize
pub fn num_spectators(&self) -> usize
Return the number of spectators currently registered
pub fn local_player_handles(&self) -> Vec<usize>
pub fn local_player_handles(&self) -> Vec<usize>
Returns the handles of local players that have been added
pub fn remote_player_handles(&self) -> Vec<usize>
pub fn remote_player_handles(&self) -> Vec<usize>
Returns the handles of remote players that have been added
pub fn spectator_handles(&self) -> Vec<usize>
pub fn spectator_handles(&self) -> Vec<usize>
Returns the handles of spectators that have been added
pub fn handles_by_address(&self, addr: <T as Config>::Address) -> Vec<usize>
pub fn handles_by_address(&self, addr: <T as Config>::Address) -> Vec<usize>
Returns all handles associated to a certain address
pub 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
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoArcAny for T
impl<T> IntoArcAny for T
§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.