Skip to main content

Module tick

Module tick 

Source
Expand description

Rules that step in time (ADR-0003 §2): a game whose rules run 60 fixed steps a second implements TickSim. Each step takes a TickInput, what each seat’s player pressed, held and released in it, and a run is its seed and its inputs, a TickRecord, which replay plays again, giving the state’s hash after each step.

The rules time things in steps with timer, never with a frame’s seconds, so a run steps the same at any frame rate. shuyi_ui::tick::TickDriver steps a simulation as many times as a frame has steps due, and gives each step what the player did since the last one, so a record of the steps replays the same whatever frame rate made it.

use shuyi_core::tick::{ActionId, SeatInput, TickInput, TickSim};

/// A counter of the steps its one action was held.
#[derive(Default)]
struct Held(u32);

impl TickSim for Held {
    type Event = ();

    fn step(&mut self, input: &TickInput) -> Vec<()> {
        self.0 += u32::from(input.is_held(0, ActionId(0)));
        Vec::new()
    }

    fn hash(&self) -> u64 {
        u64::from(self.0)
    }
}

let mut sim = Held::default();
let held = TickInput::one(SeatInput::new(vec![], vec![ActionId(0)], vec![]));
sim.step(&held);
sim.step(&TickInput::default());
assert_eq!(sim.hash(), 1);

Structs§

ActionId
An action, by its place in the game’s list of actions (ActionSet::ALL in shuyi-assets): 0 is the first. The core names no game’s actions, so a step’s input holds these; shuyi_ui::tick::ActionIds turns a game’s action into its id and back.
Run
One run of a TickRecord: an input and the steps in a row that saw it.
SeatInput
What one seat’s player did in one step: the actions pressed, held and released, each by its ActionId and at most once in each list.
TickInput
What one step of a TickSim is given: one SeatInput per seat, indexed by seat number from 0, at most MAX_SEATS. A game with one player has seat 0 alone.
TickRecord
A run of a TickSim: the stamp of the build that made it (Made), the seed its state was built from, and the input of each step, oldest first. Steps in a row with the same input are written once with their count, so a minute of a dot held right is one line.

Constants§

MAX_SEATS
The most seats a TickInput holds: four players at one machine.

Traits§

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

Functions§

replay
Plays record on sim, the state the caller built from the record’s seed, and gives the state’s hash after each step, one per step of the record, oldest first. sim is left at the record’s end. A record whose stamp isn’t made, this build’s, is refused before anything steps, naming each part that differs (Made::check): another build may step the same inputs differently without a bug in either.