Skip to main content

SyncTestSession

Struct SyncTestSession 

Source
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:

  1. Save — the current game state is saved.
  2. Advance — your game logic runs for one frame with the inputs you provided.
  3. Roll back — GGRS rewinds check_distance frames and re-simulates forward, requesting a Load followed by check_distance × Advance requests.
  4. 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_distance must be less than max_prediction_window.

Implementations§

Source§

impl<T: Config> SyncTestSession<T>

Source

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 InvalidRequest when the given handle is not valid (i.e. not between 0 and num_players).
Source

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
Source

pub fn current_frame(&self) -> Frame

Returns the current frame of a session.

Source

pub fn num_players(&self) -> usize

Returns the number of players this session was constructed with.

Source

pub fn max_prediction(&self) -> usize

Returns the maximum prediction window of a session.

Source

pub fn check_distance(&self) -> usize

Returns the check distance set on creation, i.e. the length of the simulated rollbacks

Auto Trait Implementations§

§

impl<T> Freeze for SyncTestSession<T>

§

impl<T> !RefUnwindSafe for SyncTestSession<T>

§

impl<T> Send for SyncTestSession<T>
where <T as Config>::Input: Send, <T as Config>::State: Send,

§

impl<T> Sync for SyncTestSession<T>
where <T as Config>::Input: Sync, <T as Config>::State: Send,

§

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

§

impl<T> UnsafeUnpin for SyncTestSession<T>

§

impl<T> !UnwindSafe for SyncTestSession<T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more