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>
impl<T: Config> SpectatorSession<T>
Sourcepub fn current_state(&self) -> SessionState
pub fn current_state(&self) -> SessionState
Returns the current SessionState of a session.
Sourcepub fn frames_behind_host(&self) -> usize
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.
Sourcepub fn network_stats(&self) -> Result<NetworkStats, GgrsError>
pub fn network_stats(&self) -> Result<NetworkStats, GgrsError>
Used to fetch some statistics about the quality of the network connection.
§Errors
- Returns
NotSynchronizedif the endpoint has not yet started connecting. - Returns
NotEnoughDataif less than one second has elapsed since the connection was established. The session may already beRunning; retry after a short delay.
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 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
NotSynchronizedif 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)
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.
Sourcepub fn current_frame(&self) -> Frame
pub fn current_frame(&self) -> Frame
Returns the current frame of a session.
Sourcepub fn num_players(&self) -> usize
pub fn num_players(&self) -> usize
Returns the number of players this session was constructed with.