flix

0.81.0

Input

eff InputSource

Reading the input devices, as an effect.

Input.poll returns the same value every time it is called within one simulation step: the runtime captures it once, at the top of the frame, and freezes it. That is what makes a run reproducible from a recorded list of snapshots.

Operations

def poll(): Snapshot \ Input§ Source

Definitions

def acrossTicks(n: Int32, s: Snapshot): List[Snapshot]§ Source

One frame's reading of the keyboard, spread over the n ticks it has to drive.

A frame does not map to a tick. The display runs at whatever rate the machine manages and the simulation runs at a fixed one, so a frame may owe several ticks or none.

Only the first tick gets the edges. A press is a transition, and handing the same pressed set to three catch-up ticks fires it three times -- which for anything edge-triggered means the action happens once per stalled frame instead of once per press, and for anything that toggles means it can end up back where it started. The rest of the ticks keep the keys held, because holding is a state and does last.

def diff(previous: { previous = Set[Key] }, current: { current = Set[Key] }): Snapshot§ Source

Builds a snapshot by comparing the keys held now against the keys held last step.

The two sets are named because transposing them inverts every edge, turning presses into releases.

def empty(): Snapshot§ Source

A snapshot with nothing held.

def handleWith(s: Snapshot, f: a -> b \ ef): InputHandler[a, b, ef]§ Source

Interprets Input by answering every poll with the same snapshot.

Like Canvas, this deliberately has no @DefaultHandler: a default of "no keys held" would let a test that forgot to supply input pass while asserting on a world nobody played.

def holding(keys: List[Key]): Snapshot§ Source

A snapshot with keys held, and all of them treated as newly pressed.

Convenience for tests and scripted replays.

def runWith(s: Snapshot, f: Unit -> a \ ef): a \ ef - Input§ Source

Runs f, answering every Input.poll with the same snapshot.

def steady(s: Snapshot): Snapshot§ Source

The same snapshot with its edges removed: still held, but pressed and released nothing.

def ticksDue(accumulated: Int64, perTick: Int64, budget: Int32): Int32§ Source

How many logical ticks are due, given what has accumulated and what may be spent.