Struct ggrs::SessionBuilder
source · pub struct SessionBuilder<T>where
T: Config,{ /* private fields */ }
Expand description
The SessionBuilder
builds all GGRS Sessions. After setting all appropriate values, use SessionBuilder::start_yxz_session(...)
to consume the builder and create a Session of desired type.
Implementations§
source§impl<T: Config> SessionBuilder<T>
impl<T: Config> SessionBuilder<T>
sourcepub fn add_player(
self,
player_type: PlayerType<T::Address>,
player_handle: PlayerHandle
) -> Result<Self, GGRSError>
pub fn add_player( self, player_type: PlayerType<T::Address>, player_handle: PlayerHandle ) -> Result<Self, GGRSError>
Must be called for each player in the session (e.g. in a 3 player session, must be called 3 times) before starting the session.
Player handles for players should be between 0 and num_players
, spectator handles should be higher than num_players
.
Later, you will need the player handle to add input, change parameters or disconnect the player or spectator.
Errors
- Returns
InvalidRequest
if a player with that handle has been added before - Returns
InvalidRequest
if the handle is invalid for the givenPlayerType
sourcepub fn with_max_prediction_window(self, window: usize) -> Self
pub fn with_max_prediction_window(self, window: usize) -> Self
Change the maximum prediction window. Default is 8.
sourcepub fn with_input_delay(self, delay: usize) -> Self
pub fn with_input_delay(self, delay: usize) -> Self
Change the amount of frames GGRS will delay the inputs for local players.
sourcepub fn with_num_players(self, num_players: usize) -> Self
pub fn with_num_players(self, num_players: usize) -> Self
Change number of total players. Default is 2.
sourcepub fn with_sparse_saving_mode(self, sparse_saving: bool) -> Self
pub fn with_sparse_saving_mode(self, sparse_saving: bool) -> Self
Sets the sparse saving mode. With sparse saving turned on, only the minimum confirmed frame (for which all inputs from all players are confirmed correct) will be saved. This leads to much less save requests at the cost of potentially longer rollbacks and thus more advance frame requests. Recommended, if saving your gamestate takes much more time than advancing the game state.
sourcepub fn with_desync_detection_mode(
self,
desync_detection: DesyncDetection
) -> Self
pub fn with_desync_detection_mode( self, desync_detection: DesyncDetection ) -> Self
Sets the desync detection mode. With desync detection, the session will compare checksums for all peers to detect discrepancies / desyncs between peers If a desync is found the session will send a DesyncDetected event.
sourcepub fn with_disconnect_timeout(self, timeout: Duration) -> Self
pub fn with_disconnect_timeout(self, timeout: Duration) -> Self
Sets the disconnect timeout. The session will automatically disconnect from a remote peer if it has not received a packet in the timeout window.
sourcepub fn with_disconnect_notify_delay(self, notify_delay: Duration) -> Self
pub fn with_disconnect_notify_delay(self, notify_delay: Duration) -> Self
Sets the time before the first notification will be sent in case of a prolonged period of no received packages.
sourcepub fn with_fps(self, fps: usize) -> Result<Self, GGRSError>
pub fn with_fps(self, fps: usize) -> Result<Self, GGRSError>
Sets the FPS this session is used with. This influences estimations for frame synchronization between sessions.
Errors
- Returns
InvalidRequest
if the fps is 0
sourcepub fn with_check_distance(self, check_distance: usize) -> Self
pub fn with_check_distance(self, check_distance: usize) -> Self
Change the check distance. Default is 2.
sourcepub fn with_max_frames_behind(
self,
max_frames_behind: usize
) -> Result<Self, GGRSError>
pub fn with_max_frames_behind( self, max_frames_behind: usize ) -> Result<Self, GGRSError>
Sets the maximum frames behind. If the spectator is more than this amount of frames behind the received inputs,
it will catch up with catchup_speed
amount of frames per step.
sourcepub fn with_catchup_speed(self, catchup_speed: usize) -> Result<Self, GGRSError>
pub fn with_catchup_speed(self, catchup_speed: usize) -> Result<Self, GGRSError>
Sets the catchup speed. Per default, this is set to 1, so the spectator never catches up.
If you want the spectator to catch up to the host if max_frames_behind
is surpassed, set this to a value higher than 1.
sourcepub fn start_p2p_session(
self,
socket: impl NonBlockingSocket<T::Address> + 'static
) -> Result<P2PSession<T>, GGRSError>
pub fn start_p2p_session( self, socket: impl NonBlockingSocket<T::Address> + 'static ) -> Result<P2PSession<T>, GGRSError>
Consumes the builder to construct a P2PSession
and starts synchronization of endpoints.
Errors
- Returns
InvalidRequest
if insufficient players have been registered.
sourcepub fn start_spectator_session(
self,
host_addr: T::Address,
socket: impl NonBlockingSocket<T::Address> + 'static
) -> SpectatorSession<T>
pub fn start_spectator_session( self, host_addr: T::Address, socket: impl NonBlockingSocket<T::Address> + 'static ) -> SpectatorSession<T>
Consumes the builder to create a new SpectatorSession
.
A SpectatorSession
provides all functionality to connect to a remote host in a peer-to-peer fashion.
The host will broadcast all confirmed inputs to this session.
This session can be used to spectate a session without contributing to the game input.
sourcepub fn start_synctest_session(self) -> Result<SyncTestSession<T>, GGRSError>
pub fn start_synctest_session(self) -> Result<SyncTestSession<T>, GGRSError>
Consumes the builder to construct a new SyncTestSession
. During a SyncTestSession
, GGRS will simulate a rollback every frame
and resimulate the last n states, where n is the given check_distance
.
The resimulated checksums will be compared with the original checksums and report if there was a mismatch.
Due to the decentralized nature of saving and loading gamestates, checksum comparisons can only be made if check_distance
is 2 or higher.
This is a great way to test if your system runs deterministically.
After creating the session, add a local player, set input delay for them and then start the session.