feat(input): #83 Input Manager + auto-commit the device layer in the frame loop
Fixes the papercut: the generated frame loop called rt_poll() (feeding only Input.key) but never input_poll(), so Input.active/key_down/mouse/pad read empty unless the game called Input.poll() by hand. The loop now calls input_poll() when the game uses any Input runtime method — committing the held-key/mouse/gamepad state, and record/replay — and stores its return as the frame key so Input.key still works. A game using no Input runtime keeps the plain rt_poll path, byte-identical. Adds the Input-Manager API: Input.action(name,key) ships a default binding (kept if already bound, so a rebind/loaded map isn't clobbered), Input.bind_pad(name,button) makes an action device-agnostic (keyboard OR pad), and Input.active/just_pressed/just_released read the multi-key device layer with clean on-press/on-release edges (deterministic, dispatch-free — a handler polls the edge; a replay fires identically). Examples input_manager + input_auto, 5 docs pages. Full suite 107/0, goldens byte-identical, fixpoint holds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
6a83c28e05
commit
bccd26fb29
14 changed files with 31773 additions and 31127 deletions
20
examples/library/input_auto.ludic
Normal file
20
examples/library/input_auto.ludic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# input_auto.ludic — proves the frame loop commits the device layer automatically
|
||||
# (#83): a real handler game reads Input.active in its Update phase and NEVER calls
|
||||
# Input.poll by hand, yet the action fires from the live key. Before this fix the
|
||||
# loop only fed Input.key(), so Input.active read empty unless the game polled.
|
||||
#
|
||||
# Driven headless by the keys on stdin — one char per frame. With "llq": frame 1
|
||||
# and 2 read 'l' (the action key), frame 3 reads 'q' (which quits). So the action
|
||||
# is active on exactly two frames.
|
||||
#
|
||||
# Run: printf 'llq' | bin/ludic examples/library/input_auto.ludic -> 2
|
||||
program InputAuto {
|
||||
property Tag { n: int = 0 }
|
||||
model Player { Tag }
|
||||
|
||||
var hits: int = 0
|
||||
|
||||
@OnStart handler Boot { Input.action("go", 'l') } # 'l' == 108
|
||||
handler Sense phase Update { if Input.active("go") { hits = hits + 1 } }
|
||||
@OnQuit handler Report { print(hits) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue