euv_core/game/input/struct.rs
1use super::*;
2
3/// Fixed-size 256-bit zero-allocation keyboard state bitset supporting `Copy` snapshots without heap sets.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
5pub struct KeyBitset {
6 /// Four 64-bit words storing bits `0..256` mapped from `KeyCode`.
7 #[get(type(copy))]
8 pub(crate) words: [u64; 4],
9}
10
11/// Fixed-size 16-bit zero-allocation pointer button bitset supporting `Copy` snapshots without heap sets.
12#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
13pub struct ButtonBitset {
14 /// Compact 16-bit mask storing pressed `PointerButton` states.
15 #[get(type(copy))]
16 pub(crate) mask: u16,
17}
18
19/// Zero-allocation `Copy` polled keyboard, pointer, and scroll input state for games and interactive viewports.
20#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
21pub struct InputState {
22 /// Bitset of keys currently held down.
23 #[new(skip)]
24 #[get(type(copy))]
25 pub(crate) keys_down: KeyBitset,
26 /// Bitset of keys pressed during the current frame.
27 #[new(skip)]
28 #[get(type(copy))]
29 pub(crate) keys_just_pressed: KeyBitset,
30 /// Bitset of keys released during the current frame.
31 #[new(skip)]
32 #[get(type(copy))]
33 pub(crate) keys_just_released: KeyBitset,
34 /// Bitset of pointer buttons currently held down.
35 #[new(skip)]
36 #[get(type(copy))]
37 pub(crate) buttons_down: ButtonBitset,
38 /// Bitset of pointer buttons pressed during the current frame.
39 #[new(skip)]
40 #[get(type(copy))]
41 pub(crate) buttons_just_pressed: ButtonBitset,
42 /// Bitset of pointer buttons released during the current frame.
43 #[new(skip)]
44 #[get(type(copy))]
45 pub(crate) buttons_just_released: ButtonBitset,
46 /// Latest logical pointer coordinates.
47 #[new(skip)]
48 #[get(type(copy))]
49 pub(crate) pointer_position: Point,
50 /// Accumulated logical pointer movement delta during the current frame.
51 #[new(skip)]
52 #[get(type(copy))]
53 pub(crate) pointer_delta: Point,
54 /// Accumulated scroll delta during the current frame.
55 #[new(skip)]
56 #[get(type(copy))]
57 pub(crate) scroll_delta: Point,
58 /// Virtual analog movement stick `(-1.0..=1.0, -1.0..=1.0)` fed by touch drag-joysticks or gamepads.
59 #[new(skip)]
60 #[get(type(copy))]
61 pub(crate) virtual_axis: Point,
62 /// Virtual touch/gamepad primary fire trigger state.
63 #[new(skip)]
64 #[get(type(copy))]
65 pub(crate) virtual_fire: bool,
66 /// Virtual touch/gamepad dash/boost trigger state.
67 #[new(skip)]
68 #[get(type(copy))]
69 pub(crate) virtual_dash: bool,
70 /// Latest keyboard modifier flags reported by key or pointer events.
71 #[new(skip)]
72 #[get(type(copy))]
73 pub(crate) modifiers: Modifiers,
74}
75
76/// Declarative multi-key and pointer-button binding table mapping physical inputs to `GameAction`s.
77#[derive(Clone, Data, Debug)]
78pub struct ActionMap {
79 /// Keyboard bindings grouped by semantic `GameAction`.
80 pub(crate) key_bindings: HashMap<GameAction, Vec<KeyCode>>,
81 /// Pointer button bindings grouped by semantic `GameAction`.
82 pub(crate) button_bindings: HashMap<GameAction, Vec<PointerButton>>,
83}