Crate ggrs[][src]

Expand description

GGRS

GGRS (good game rollback system) is a reimagination of the GGPO network SDK written in 100% safe Rust 🦀. It replaces the C-style callback API with a clearer control flow.

Structs

GameInput

Represents a serialized input for a single player in a single frame. This struct holds a buffer where the first size bytes represent the encoded input of a single player. The associated frame is denoted with frame. You do not need to create this struct, but the sessions will provide a Vec<GameInput> for you during advance_frame().

GameState

Represents a serialized game state of your game for a single frame. The buffer buffer holds your state, frame indicates the associated frame number and checksum can additionally be provided for use during a SyncTestSession. You are expected to return this during save_game_state() and use them during load_game_state().

NetworkStats

The NetworkStats struct contains statistics about the current session.

P2PSession

A P2PSession provides a UDP protocol to connect to remote clients in a peer-to-peer fashion.

P2PSpectatorSession

A P2PSpectatorSession provides a UDP protocol 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.

SyncTestSession

During a SyncTestSession, GGRS will simulate a rollback every frame and resimulate the last n states, where n is the given check distance. If you provide checksums in your save_game_state() function, the SyncTestSession will compare the resimulated checksums with the original checksums and report if there was a mismatch.

Enums

GGRSError

This enum contains all error messages this library can return. Most API functions will generally return a Result<(),GGRSError>.

GGRSEvent

These are the notifications that you can receive from the session.

PlayerType

Defines the three types of players that GGRS considers:

SessionState

A session is always in one of these states. You can query the current state of a session via current_state().

Constants

MAX_INPUT_BYTES

The maximum number of bytes the input of a single player can consist of. This corresponds to the size of usize. Higher values should be possible, but are not tested.

MAX_PLAYERS

The maximum number of players allowed. Theoretically, higher player numbers should work, but are not well-tested.

MAX_PREDICTION_FRAMES

The maximum number of frames GGRS will roll back. Every gamestate older than this is guaranteed to be correct if the players did not desync.

NULL_FRAME

Internally, -1 represents no frame / invalid frame.

Traits

GGRSInterface

The GGRSInterface trait describes the functions that your application interface must provide. GGRS might call multiple of these functions after you called advance_frame() of a session.

Functions

start_p2p_session

Used to create a new P2PSession for players who participate on the game input. After creating the session, add local and remote players, set input delay for local players and then start the session.

start_p2p_spectator_session

Used to create a new P2PSpectatorSession for a spectator. The session will receive inputs from all players from the given host directly.

start_synctest_session

Used to create a new SyncTestSession. During a sync test, GGRS will simulate a rollback every frame and resimulate the last n states, where n is the given check_distance. If checksums are provided with the saved states, the SyncTestSession will compare the checksums from resimulated states to the original states. This is a great way to test if your system runs deterministically. After creating the session, add local players, set input delay for them and then start the session. Currently, 6 is the maximum allowed check_distance.

Type Definitions

FrameNumber
PlayerHandle