InputState class final

What the player is asking for, as one object that every input device writes into and the simulation alone reads.

Latching, and why it is not optional

Devices produce events whenever they feel like it; the simulation consumes them on a fixed step. At 30 frames per second with a 60 Hz step those two rates are far enough apart that a key can go down and come back up entirely between two steps. Comparing "held now" against "held last step" would see nothing happened and swallow the shot — and it would do so more often the worse the frame rate, which is exactly when the player is least forgiving.

So presses and releases are latched: they record that an edge happened at all, survive until a step consumes them, and are cleared by endStep. A tap too short to be held during any step still reads as pressed for exactly one step.

Reading

Only the simulation calls beginStep/endStep, and only between them are pressed and released meaningful.

Every input device, a test and a server write one made with InputState().

Constructors

InputState()

Properties

axisValues → Map<AxisAction, double>
Every axis with a value, for a recorder that cannot ask by name.
no setter
dualAxisValues → Map<DualAxisAction, Vector2>
Every dual axis with a value other than DualAxisAction.move and DualAxisAction.look, which moveAxis and lookDelta already answer.
no setter
externalThisStep → List<ExternalStateInput>
What was fed from outside for this step, in order — see feedExternal.
no setter
hashCode → int
The hash code for this object.
no setterinherited
heldNow → Iterable<GameAction>
Everything held right now, for a recorder that starts mid-run.
no setter
lookDelta → Vector2
Accumulated view movement since the last step, in whatever units the device reports. Sensitivity is applied by the camera, not here. A copy the caller owns.
no setter
magnitudes → Map<GameAction, double>
Every action with an analogue reading, and the reading.
no setter
moveAxis → Vector2
Movement intent: x strafes right, y moves forward. Never longer than 1.
no setter
muted ↔ bool
Whether the devices are ignored.
getter/setter pair
pressedThisStep → Iterable<GameAction>
What became held and what let go this step, for something that has to write it all down rather than ask about one action.
no setter
releasedThisStep → Iterable<GameAction>
What let go this step, as an unmodifiable list: the release side of pressedThisStep.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
slotRequest → int?
The numbered slot asked for since the last step, if any.
no setter
tunesThisStep → Map<String, double>
The tunables set for this step, by name — see tune.
no setter

Methods

addLook(double dx, double dy) → void
Adds view movement. Called once per mouse event or once per drag update; the values pile up until a step takes them.
axis(AxisAction action) → double
Where action stands, from minus one to one; nought when nothing has said.
beginStep() → void
Marks the start of a simulation step. Currently nothing to do, and it exists anyway so that call sites are already correct when it does.
clear() → void
Drops everything, held state included.
clearAxis(AxisAction action) → void
Stops saying anything about action, which then reads nought.
clearDualAxis(DualAxisAction action) → void
Stops saying anything about action; for DualAxisAction.move that is the stick at rest.
clearMagnitude(GameAction action) → void
Stops saying anything about how hard action is asked for.
dualAxis(DualAxisAction action) → Vector2
Where action stands: moveAxis for DualAxisAction.move, lookDelta for DualAxisAction.look, and the value a device gave for any other.
endStep() → void
Marks the end of a simulation step and clears everything one-shot.
feedExternal(ExternalStateInput input) → void
Feeds input, state that arrived from outside the simulation, to the next step: a plant's sensor, a log's line, a headset's pose.
held(GameAction action) → bool
Is action down? The bool of a button: some press has not been released yet, or a toggled action is latched on.
isToggled(GameAction action) → bool
Whether action latches rather than being held.
magnitude(GameAction action) → double
How far is action pulled? A number from nought to one, the analogue side of held.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
press(GameAction action) → void
Adds one hold on action and latches it as pressed for the next step.
pressed(GameAction action) → bool
True for the one step that consumes a press, even if the button was already released again by then.
release(GameAction action) → void
Lets go of one hold on action, which releases it only if it was the last.
released(GameAction action) → bool
True for the one step that consumes a release of action, even if it was pressed again by then.
replayMoveAxis(double x, double y) → void
Puts moveAxis at exactly (x, y) for this step, whatever the stick and the held directions would add up to.
requestSlot(int slot) → void
Asks for the numbered slot; read by the next step as slotRequest. A later request before that step replaces it. Ignored while muted.
setAxis(AxisAction action, double value) → void
Sets action to value, clamped to [-1, 1].
setDualAxis(DualAxisAction action, double x, double y) → void
Writes a two-number action.
setMagnitude(GameAction action, double magnitude) → void
Says how hard an action is being asked for.
setStickAxis(double x, double y) → void
Sets the analogue movement axis, for a stick or a d-pad.
setToggled(GameAction action, {required bool toggled}) → void
Makes action latch: a press turns it on and the next press turns it off.
toggle(GameAction action) → void
Turns action on if it is off and off if it is on.
toString() → String
A string representation of this object.
inherited
tune(String name, double value) → void
Sets the tunable called name to value from the next step on.
valueOf<T extends Object>(InputAction<T> action) → T
What does action read as, typed by its kind? held for a button, an axis's number, a dual axis's vector, as every valueOf reads a key.

Operators

operator ==(Object other) → bool
The equality operator.
inherited