Logo Mibo

InputMapper Module

Functions and values

Function or value Description

subscribe getMap toMsg ctx

Full Usage: subscribe getMap toMsg ctx

Parameters:
Returns: Sub<'Msg>
Type parameters: 'Action, 'Msg (requires comparison)

Elmish subscription that builds an ActionState from the registered IInput observables and the supplied map. Backend-neutral apart from the "is key down" poller, which reads MonoGame state.

getMap : unit -> InputMap<'Action>
toMsg : ActionState<'Action> -> 'Msg
ctx : GameContext
Returns: Sub<'Msg>

subscribeAdaptive getMap actions ctx

Full Usage: subscribeAdaptive getMap actions ctx

Parameters:
Returns: AdaptiveSub
Type parameters: 'Action (requires comparison)

Adaptive subscription that builds an ActionState from the registered IInput observables and the supplied map, and writes it into the actions root. This is the adaptive counterpart of InputMapper.subscribe with the root as the sink (no 'Msg, no dispatch). The state is built at event time (owner thread, during the host's input poll); the writes are deferred to framework-owned moments: each build is merged into the root at the step boundary, before Update, and the consumed edges are cleared after Update, before the frame is forced. Edge handling is shared with the raylib backend (see AdaptiveInput.subscribe).

CONSUMING: Held is current truth — derive projections from it freely (actions |> AVal.map (fun s -> s.Held.Contains Jump), or read it in the frame builder). Started/Released are EDGE EVENTS: read them in Update exactly once. The subscription clears them after Update (after each fixed sub-step's Update, before the frame is forced), so the next step reads fresh edges:

   let s = actions |> AVal.getValue
   for a in s.Started do handleStarted a
val s: obj
val a: obj
A manual actions.Set(ActionState.nextFrame s) write stays legal but is redundant; the root's equality gate makes it free. The clear runs before the frame force and before work posted from Update, so a projection over Started forced in the frame builder and an intent that reads Started both see the cleared state: read the edges (or materialize the derived value) in Update instead. One exception: a fixed-step frame with no sub-step runs no Update and no drain, so the clear waits and the edges stay in the root for the next sub-step's Update.

EDGES ACCUMULATE between consumptions: every delta (keyboard, mouse, gamepad) builds a full state and the write MERGES its edges into the root's unread edges (ActionState.mergeEdges) — a mouse-move build between a key press and its release must not drop the key's edges. Held/Values stay last-wins (current truth).

COST: the write is cheap (merging with empty edges reuses the existing sets; the changeable's equality gate skips no-op writes), but the BUILD is real per-event work — the same cost the Msg-dispatching subscribe pays, one build per delta. The edge clear costs one closure per state that has edges, and nothing on frames without input events. Do not skip empty-delta builds: the rebuild re-derives Held from live polling at event time, which is how a missed release heals for Held-based consumers.

FRAME ONE: subscriptions attach at the first Step's diff, which runs after the host's first input poll — input from that first poll is dropped. One startup frame; not observable in practice.

getMap : unit -> InputMap<'Action>
actions : cval<ActionState<'Action>>
ctx : GameContext
Returns: AdaptiveSub

subscribeStatic map toMsg ctx

Full Usage: subscribeStatic map toMsg ctx

Parameters:
Returns: Sub<'Msg>
Type parameters: 'Action, 'Msg (requires comparison)

Elmish subscription variant for a fixed (non-changing) InputMap.

map : InputMap<'Action>
toMsg : ActionState<'Action> -> 'Msg
ctx : GameContext
Returns: Sub<'Msg>

subscribeStaticAdaptive map actions ctx

Full Usage: subscribeStaticAdaptive map actions ctx

Parameters:
Returns: AdaptiveSub
Type parameters: 'Action (requires comparison)

Adaptive subscription variant for a fixed (non-changing) InputMap.

map : InputMap<'Action>
actions : cval<ActionState<'Action>>
ctx : GameContext
Returns: AdaptiveSub

Type something to start searching.