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
clearfromScreen::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>
impl<A: ActionSet> TickDriver<A>
Sourcepub fn recording(self, record: TickRecord) -> Self
pub fn recording(self, record: TickRecord) -> Self
The same driver recording each step’s input from now on into
record (record).
Sourcepub fn update<S: TickSim>(
&mut self,
sim: &mut S,
input: &FrameInput<A>,
) -> Vec<(u64, S::Event)>
pub fn update<S: TickSim>( &mut self, sim: &mut S, input: &FrameInput<A>, ) -> Vec<(u64, S::Event)>
Sourcepub fn clear(&mut self)
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.
Sourcepub fn rewind_to(&mut self, step: u64)
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.
Sourcepub fn record(&self) -> Option<&TickRecord>
pub fn record(&self) -> Option<&TickRecord>
The record of each step’s input, while recording.
Sourcepub fn take_record(&mut self) -> Option<TickRecord>
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>
impl<A: Clone + ActionSet> Clone for TickDriver<A>
Source§fn clone(&self) -> TickDriver<A>
fn clone(&self) -> TickDriver<A>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more