跳转到内容
查看源码

controls自动生成

分类:包 · 清单:use "kernels/";

读取人的操作:键盘、鼠标、手柄统一映射为游戏动作,以及指针;唯一读取输入的包。

What a person’s hands do, read for a program, and the one package that reads them: a game’s actions from the keyboard, the mouse and a pad alike, from a table of actions (held, pressed and released, the ways to move and look, the stick’s flicks); the pointer (where, its buttons, the wheel); and what was typed.

Layer: Interaction.

use "controls.entpkg";
  • kernels/action.ent — A game’s actions from the keyboard and a pad alike (../package.esn). Kernels: controls.start@1, controls.read@1.
  • kernels/pointer.ent — The pointer: where it is, its buttons held, pressed and released, the wheel, whether it moved. Kernels: controls.pointer_start@1, controls.pointer@1.
  • kernels/typing.ent — What was typed this frame. Kernels: controls.typing@1.

tests/ holds scenes and their replays, run on every backend: actions.replay, pointer.replay. Every Kernel of the package is reached by one of them.

Used by the controls example.

Kernel 执行模式 简述
controls.pointer@1 map The pointer this frame, from the one before.
controls.pointer_start@1 map
controls.read@1 map The controls this frame, from the ones before.
controls.start@1 map
controls.typing@1 map This frame’s typing.
函数 简述
action_dead_zone() -> Float How far a stick goes before it counts, and how its travel past that is spread over 0 to 1.
action_past_dead_zone(v: Vec2) -> Vec2
action_step_delay() -> Float A step held repeats after action_step_delay() seconds, every action_step_every().
action_step_every() -> Float
action_bit(on: Bool, k: Int) -> Int
action_key_down(code: Int) -> Bool
action_held(c: ActionControls, k: Int) -> Bool Whether action k is held, pressed this frame, released this frame.
action_pressed(c: ActionControls, k: Int) -> Bool
action_released(c: ActionControls, k: Int) -> Bool
action_stick_stepped(c: ActionControls, way: Int) -> Bool Whether the left stick (or the arrows) stepped way this frame: 1 up, 2 down, 4 left, 8 right.
pointer_held(p: PointerControls, b: Int) -> Bool Whether button b (0 left, 1 right, 2 middle) is held, pressed this frame, released this frame.
pointer_pressed(p: PointerControls, b: Int) -> Bool
pointer_released(p: PointerControls, b: Int) -> Bool
pointer_points(p: PointerControls) -> Vec2 The pointer at at in the window’s pixels, in its points (scale() pixels a point).
typed_at(t: Typing, k: Int) -> Int Character k typed this frame (0 past the last).
名称 写法
ActionBinding struct ActionBinding { key: Int; key2: Int; pad: Int; }
ActionControls struct ActionControls { held: Int; pressed: Int; released: Int; move: Vec2; look: Vec2; zoom: Float; steps: Int; way: Int;
PointerControls struct PointerControls { at: Vec2; held: Int; pressed: Int; released: Int; wheel: Vec2; moved: Bool; }
Typing struct Typing { codes: [Int; 32]; n: Int; }

The pointer this frame, from the one before.

执行模式 map
需要能力 field.read, field.write, input.read
输入 previous: Rows<PointerControls>
参数 —
输出 result: Rows<PointerControls>
源码 packages/controls.entpkg/kernels/pointer.ent
执行模式 map
需要能力 field.write
输入 —
参数 —
输出 result: Rows<PointerControls>
源码 packages/controls.entpkg/kernels/pointer.ent

The controls this frame, from the ones before.

执行模式 map
需要能力 field.read, field.write, time.read, input.read
输入 previous: Rows<ActionControls>, actions: Rows<ActionBinding>
参数 —
输出 result: Rows<ActionControls>
源码 packages/controls.entpkg/kernels/action.ent
执行模式 map
需要能力 field.write
输入 —
参数 —
输出 result: Rows<ActionControls>
源码 packages/controls.entpkg/kernels/action.ent

This frame’s typing.

执行模式 map
需要能力 field.write, input.read
输入 —
参数 —
输出 result: Rows<Typing>
源码 packages/controls.entpkg/kernels/typing.ent

actions.replay, pointer.replay