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>

source

pub fn new() -> Self

Construct a new builder with all values set to their defaults.

source

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
source

pub fn with_max_prediction_window(self, window: usize) -> Self

Change the maximum prediction window. Default is 8.

source

pub fn with_input_delay(self, delay: usize) -> Self

Change the amount of frames GGRS will delay the inputs for local players.

source

pub fn with_num_players(self, num_players: usize) -> Self

Change number of total players. Default is 2.

source

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.

source

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.

source

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.

source

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.

source

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
source

pub fn with_check_distance(self, check_distance: usize) -> Self

Change the check distance. Default is 2.

source

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.

source

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.

source

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.
source

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.

source

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.

Trait Implementations§

source§

impl<T> Debug for SessionBuilder<T>where T: Config + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Config> Default for SessionBuilder<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for SessionBuilder<T>where <T as Config>::Address: RefUnwindSafe, <T as Config>::Input: RefUnwindSafe,

§

impl<T> Send for SessionBuilder<T>where <T as Config>::Address: Send, <T as Config>::Input: Send,

§

impl<T> Sync for SessionBuilder<T>where <T as Config>::Address: Sync, <T as Config>::Input: Sync,

§

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

§

impl<T> UnwindSafe for SessionBuilder<T>where <T as Config>::Address: UnwindSafe, <T as Config>::Input: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V