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

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().

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().

An Arc<Mutex<GameState>> that you can save()/load() a GameState to/from. These will be handed to the user as part of a GGRSRequest.

The NetworkStats struct contains statistics about the current session.

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

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.

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.

Enums

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

Notifications that you can receive from the session. Handling them is up to the user.

Requests that you can receive from the session. Handling them is mandatory.

Defines the three types of players that GGRS considers:

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

Constants

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.

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

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.

Internally, -1 represents no frame / invalid frame.

Functions

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.

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

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

Type Definitions