Skip to main content

TickSim

Trait TickSim 

Source
pub trait TickSim {
    type Event;

    // Required methods
    fn step(&mut self, input: &TickInput) -> Vec<Self::Event>;
    fn hash(&self) -> u64;
}
Expand description

A game’s rules that step in time: 60 fixed steps a second (STEPS_PER_SECOND), each given the players’ input for it.

§Contract

  • Deterministic. The same state and input always give the same events and the same new state, on every platform. Luck comes from a seeded RNG kept in the state (SimRng); there is no clock, no I/O and no float in the state or the step. So a run is rebuilt from its seed and its inputs (TickRecord, replay).
  • Time is steps. One call of step is one step. Timers advance by 1 in it (timer).
  • Events are the only way out. What a screen shows or plays (a sound, say) comes from the events step returns, so a step run again after a rewind plays nothing twice (shuyi_ui::tick::TickDriver hands each step’s events on once).
  • hash changes when the state does and is the same on every platform: most simply state_hash(self)’s (state_hash).

Required Associated Types§

Source

type Event

What happened in a step.

Required Methods§

Source

fn step(&mut self, input: &TickInput) -> Vec<Self::Event>

Runs one step with input, and says what happened.

Source

fn hash(&self) -> u64

The hash of the state, which a replay compares step by step.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§