Input->movement ergonomics: avoid bool->int boilerplate (directional int / axis returning int) #79

Closed
opened 2026-09-02 04:52:40 +02:00 by orkun · 1 comment
Owner

Turning WASD into a -1/0/1 movement intent currently needs glue like function ki(b: bool) -> int { if b {return 1}; return 0 } then dx = ki(key_down('d')) - ki(key_down('a')). Input.axis/Input.vector exist but return fixed, while movers like TopDown.move take int, so games write conversion boilerplate.

Proposal: an ergonomic path — e.g. Input.axis_i(neg,pos) -> int, movers accepting the fixed vector directly, or a clean bool->int coercion — so directional input reads without helper functions.

Turning WASD into a -1/0/1 movement intent currently needs glue like `function ki(b: bool) -> int { if b {return 1}; return 0 }` then `dx = ki(key_down('d')) - ki(key_down('a'))`. `Input.axis`/`Input.vector` exist but return `fixed`, while movers like `TopDown.move` take `int`, so games write conversion boilerplate. Proposal: an ergonomic path — e.g. `Input.axis_i(neg,pos) -> int`, movers accepting the fixed vector directly, or a clean bool->int coercion — so directional input reads without helper functions.
Author
Owner

Shipped in ad3be0c (full suite 112/0, goldens byte-identical, fixpoint intact).

Input.axis_i(neg, pos) -> int returns a directional intent as a plain int: +1 when the positive key is held, -1 the negative, 0 for neither or both. It reads the multi-key device set, so it replaces the ki(key_down('d')) - ki(key_down('a')) bool->int boilerplate and feeds an int mover directly:

dx = Input.axis_i('a', 'd')
dy = Input.axis_i('w', 's')
TopDown.move(e, dx, dy)

Complements Input.axis (fixed) / Input.vector (normalized) for the analog path. Verified by examples/library/input_movement.ludic (prints 1 0 -1 -1 0 — right, none, left, up, and opposing keys cancelling). Docs page added.

Shipped in ad3be0c (full suite 112/0, goldens byte-identical, fixpoint intact). **`Input.axis_i(neg, pos) -> int`** returns a directional intent as a plain int: `+1` when the positive key is held, `-1` the negative, `0` for neither or both. It reads the multi-key device set, so it replaces the `ki(key_down('d')) - ki(key_down('a'))` bool->int boilerplate and feeds an int mover directly: dx = Input.axis_i('a', 'd') dy = Input.axis_i('w', 's') TopDown.move(e, dx, dy) Complements `Input.axis` (fixed) / `Input.vector` (normalized) for the analog path. Verified by `examples/library/input_movement.ludic` (prints `1 0 -1 -1 0` — right, none, left, up, and opposing keys cancelling). Docs page added.
orkun closed this issue 2026-09-02 06:45:02 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: workshopsoft/ludic#79
No description provided.