Skip to main content

SpectatorSession

Struct SpectatorSession 

Source
pub struct SpectatorSession<T>
where T: Config,
{ /* private fields */ }
Expand description

Connects to a remote host in a peer-to-peer fashion without contributing input.

The host will broadcast all confirmed inputs to this session, allowing it to replay the game as a spectator.

Implementations§

Source§

impl<T: Config> SpectatorSession<T>

Source

pub fn current_state(&self) -> SessionState

Returns the current SessionState of a session.

Source

pub fn frames_behind_host(&self) -> usize

Returns how many confirmed frames the spectator has yet to process.

Both last_recv_frame and current_frame are initialised to NULL_FRAME (-1), so this returns 0 before any input has arrived from the host, which is correct: neither side has advanced yet. Once the session is running, the invariant last_recv_frame >= current_frame is maintained by the session, so the result is always non-negative.

Source

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

Used to fetch some statistics about the quality of the network connection.

§Errors
  • Returns NotSynchronized if the endpoint has not yet started connecting.
  • Returns NotEnoughData if less than one second has elapsed since the connection was established. The session may already be Running; retry after a short delay.
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 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 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)

Receive UDP packages, distribute them to corresponding UDP endpoints, handle all occurring events and send all outgoing UDP packages. Should be called periodically by your application to give GGRS a chance to do internal work like packet transmissions.

Source

pub fn current_frame(&self) -> Frame

Returns the current frame of a session.

Source

pub fn num_players(&self) -> usize

Returns the number of players this session was constructed with.

Auto Trait Implementations§

§

impl<T> Freeze for SpectatorSession<T>
where <T as Config>::Address: Freeze,

§

impl<T> !RefUnwindSafe for SpectatorSession<T>

§

impl<T> !Send for SpectatorSession<T>

§

impl<T> !Sync for SpectatorSession<T>

§

impl<T> Unpin for SpectatorSession<T>
where <T as Config>::Address: Unpin, <T as Config>::Input: Unpin,

§

impl<T> UnsafeUnpin for SpectatorSession<T>
where <T as Config>::Address: UnsafeUnpin,

§

impl<T> !UnwindSafe for SpectatorSession<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> 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, 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