pub struct SyncTestSession<T>where
T: Config,{ /* private fields */ }Expand description
A session for verifying that your game logic is deterministic, without any network involvement.
§How it works
Every call to advance_frame() performs the following sequence:
- Save — the current game state is saved.
- Advance — your game logic runs for one frame with the inputs you provided.
- Roll back — GGRS rewinds
check_distanceframes and re-simulates forward, requesting aLoadfollowed bycheck_distance×Advancerequests. - Compare — the checksums produced during re-simulation are compared against those saved during the original run. A mismatch means your game is not deterministic: the same inputs from the same state produced different results on separate runs.
If a checksum mismatch is detected, advance_frame() panics — this is intentional.
SyncTestSession is a development tool; a mismatch is a bug that must be fixed before shipping.
§All players are local
There is no network in a sync test. You must call add_local_input() for every player
handle (0 through num_players - 1) before each advance_frame() call, even in a
multi-player configuration.
§Limitations
- Sparse saving is incompatible with
SyncTestSession: the session must save every frame to have checksums available for the full check window. - The
check_distancemust be less thanmax_prediction_window.
Implementations§
Source§impl<T: Config> SyncTestSession<T>
impl<T: Config> SyncTestSession<T>
Sourcepub fn add_local_input(
&mut self,
player_handle: PlayerHandle,
input: T::Input,
) -> Result<(), GgrsError>
pub fn add_local_input( &mut self, player_handle: PlayerHandle, input: T::Input, ) -> Result<(), GgrsError>
Registers local input for a player for the current frame. This should be successfully called for every local player before calling advance_frame().
If this is called multiple times for the same player before advancing the frame, older given inputs will be overwritten.
In a sync test, all players are considered to be local, so you need to add input for all of them.
§Errors
- Returns
InvalidRequestwhen the given handle is not valid (i.e. not between 0 and num_players).
Sourcepub fn advance_frame(&mut self) -> Result<Vec<GgrsRequest<T>>, GgrsError>
pub fn advance_frame(&mut self) -> Result<Vec<GgrsRequest<T>>, GgrsError>
In a sync test, this will advance the state by a single frame and afterwards rollback check_distance amount of frames,
resimulate and compare checksums with the original states. 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
MismatchedChecksumif checksums don’t match after resimulation.
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.
Sourcepub fn max_prediction(&self) -> usize
pub fn max_prediction(&self) -> usize
Returns the maximum prediction window of a session.
Sourcepub fn check_distance(&self) -> usize
pub fn check_distance(&self) -> usize
Returns the check distance set on creation, i.e. the length of the simulated rollbacks