Skip to main content

TickDriver

Struct TickDriver 

Source
pub struct TickDriver<A: ActionSet> { /* private fields */ }
Expand description

Runs a stage’s TickSim in fixed steps: as many a frame as FrameInput::ticks says are due (counted by the platform’s App, 60 a second, at most 4 a frame). It keeps no clock of its own.

§Input reaches the steps

It keeps what each frame read until a step takes it, so the frame rate never changes which presses a simulation sees:

  • A press is pressed in one step: the first run in or after the frame that read it, the first of a frame’s steps when it has several. A frame that runs no step (less than a step’s time passed, an action handed in by Game::act, a slowed or stopped game) keeps it for the next.
  • A release is released in one step, after its press’s: a tap between two steps is pressed in one and released in the next, so it is never lost.
  • Held is the frame’s: every step a frame runs sees the actions held at its end. A tap is pressed without being held.
  • Key repeats never reach a step (FrameInput::presses).
  • An action pressed twice before a step isn’t merged: the second press waits. The next step has the first press, the one after the release and the press again, and so on, so every press and release reaches a step, in order. An action is pressed when it goes down: a second key on an action already held presses nothing.
  • Covered or resumed, it forgets. A stage calls clear from Screen::covered, and a frame after a suspend (FrameInput::resumed) clears it, so a press made before a pause screen or a suspend never fires after it. A press a step had stays down, and its release still comes.

Each step’s input is one seat, seat 0, from the game’s input. With a recording it is kept in a TickRecord: what each step saw, so the record replays the same whatever frame rate made it.

§Events are handed on once

update hands on each step’s events with the step’s number (counted from 1), in order, a frame catching up included. It keeps the highest step it has handed on: after a rewind (rewind_to), the steps that run again are stepped for their state, but their events aren’t handed on a second time. A simulation asks for sound only through its events, so no sound plays twice.

Implementations§

Source§

impl<A: ActionSet> TickDriver<A>

Source

pub fn new() -> Self

A driver that has run no step, and records nothing.

Source

pub fn recording(self, record: TickRecord) -> Self

The same driver recording each step’s input from now on into record (record).

Source

pub fn update<S: TickSim>( &mut self, sim: &mut S, input: &FrameInput<A>, ) -> Vec<(u64, S::Event)>

Reads input’s presses and releases and runs input.ticks() steps of sim, each with its seat’s TickInput (type docs). Gives back the events of the steps not handed on before, each with its step’s number, in order.

Source

pub fn clear(&mut self)

Forgets every press and release no step has had yet: from Screen::covered, so a press made just before a pause screen never fires after it.

Source

pub fn rewind_to(&mut self, step: u64)

Sets the steps run back to step, when the game has loaded its state at that step (a rollback): the steps after it run again for their state, and their events, handed on before, aren’t handed on again. The record forgets the steps after it. A step at or past the steps run changes nothing.

Source

pub fn steps(&self) -> u64

The steps run: the number of the last one.

Source

pub fn handed(&self) -> u64

The highest step whose events were handed on.

Source

pub fn record(&self) -> Option<&TickRecord>

The record of each step’s input, while recording.

Source

pub fn take_record(&mut self) -> Option<TickRecord>

Stops recording, handing back the record.

Trait Implementations§

Source§

impl<A: Clone + ActionSet> Clone for TickDriver<A>

Source§

fn clone(&self) -> TickDriver<A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug + ActionSet> Debug for TickDriver<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: ActionSet> Default for TickDriver<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A> Freeze for TickDriver<A>

§

impl<A> RefUnwindSafe for TickDriver<A>
where A: RefUnwindSafe,

§

impl<A> Send for TickDriver<A>
where A: Send,

§

impl<A> Sync for TickDriver<A>
where A: Sync,

§

impl<A> Unpin for TickDriver<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for TickDriver<A>

§

impl<A> UnwindSafe for TickDriver<A>
where A: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.