euv-core 0.47.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
use super::*;

/// Zero-allocation 256-bit keyboard state operations for `KeyBitset`.
impl KeyBitset {
    /// Maps a `KeyCode` into a deterministic bit index in `0..256`.
    ///
    /// # Arguments
    ///
    /// - `KeyCode` - Keyboard key code to encode.
    ///
    /// # Returns
    ///
    /// - `usize` - Bit index in `0..256`.
    #[inline(always)]
    #[must_use]
    pub const fn key_bit_index(key: KeyCode) -> usize {
        match key {
            KeyCode::Unknown => 0,
            KeyCode::Enter => 1,
            KeyCode::Escape => 2,
            KeyCode::Back => 3,
            KeyCode::Tab => 4,
            KeyCode::Backspace => 5,
            KeyCode::Delete => 6,
            KeyCode::Space => 7,
            KeyCode::ArrowUp => 8,
            KeyCode::ArrowDown => 9,
            KeyCode::ArrowLeft => 10,
            KeyCode::ArrowRight => 11,
            KeyCode::Home => 12,
            KeyCode::End => 13,
            KeyCode::PageUp => 14,
            KeyCode::PageDown => 15,
            KeyCode::Character(ch) => {
                let code: u32 = ch as u32;
                if code < 128 {
                    32 + (code as usize)
                } else {
                    160 + ((code as usize) % 96)
                }
            }
        }
    }

    /// Clears all recorded key bits in O(1).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable key bitset.
    #[inline(always)]
    pub fn clear(&mut self) {
        self.set_words([0; 4]);
    }

    /// Returns `true` when zero key bits are set.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Key bitset reference.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when empty.
    #[inline(always)]
    #[must_use]
    pub fn is_empty(&self) -> bool {
        let w: [u64; 4] = self.get_words();
        let lo: u64 = w[0] | w[1];
        let hi: u64 = w[2] | w[3];
        (lo | hi) == 0
    }

    /// Sets the bit for `key`, returning `true` if the bit transitioned from `0` to `1`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable key bitset.
    /// - `KeyCode` - Key code to mark set.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` if `key` was not already set.
    #[inline(always)]
    pub fn insert(&mut self, key: KeyCode) -> bool {
        let idx: usize = Self::key_bit_index(key);
        let word_idx: usize = idx >> 6;
        let bit_mask: u64 = 1_u64 << (idx & 63);
        let mut w: [u64; 4] = self.get_words();
        let was_set: bool = (w[word_idx] & bit_mask) != 0;
        w[word_idx] |= bit_mask;
        self.set_words(w);
        !was_set
    }

    /// Clears the bit for `key`, returning `true` if the bit transitioned from `1` to `0`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable key bitset.
    /// - `&KeyCode` - Key code to clear.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` if `key` was previously set.
    #[inline(always)]
    pub fn remove(&mut self, key: &KeyCode) -> bool {
        let idx: usize = Self::key_bit_index(*key);
        let word_idx: usize = idx >> 6;
        let bit_mask: u64 = 1_u64 << (idx & 63);
        let mut w: [u64; 4] = self.get_words();
        let was_set: bool = (w[word_idx] & bit_mask) != 0;
        w[word_idx] &= !bit_mask;
        self.set_words(w);
        was_set
    }

    /// Returns `true` when the bit for `key` is set.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Key bitset reference.
    /// - `&KeyCode` - Key code to query.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` if set.
    #[inline(always)]
    #[must_use]
    pub fn contains(&self, key: &KeyCode) -> bool {
        let idx: usize = Self::key_bit_index(*key);
        let word_idx: usize = idx >> 6;
        let bit_mask: u64 = 1_u64 << (idx & 63);
        (self.get_words()[word_idx] & bit_mask) != 0
    }
}

/// Zero-allocation 16-bit pointer button operations for `ButtonBitset`.
impl ButtonBitset {
    /// Maps a `PointerButton` into a deterministic bit mask in `u16`.
    ///
    /// # Arguments
    ///
    /// - `PointerButton` - Pointer button to encode.
    ///
    /// # Returns
    ///
    /// - `u16` - Single-bit mask for the button.
    #[inline(always)]
    #[must_use]
    pub const fn button_mask(button: PointerButton) -> u16 {
        match button {
            PointerButton::Primary => 1_u16 << 0,
            PointerButton::Secondary => 1_u16 << 1,
            PointerButton::Auxiliary => 1_u16 << 2,
        }
    }

    /// Clears all recorded button bits in O(1).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable button bitset.
    #[inline(always)]
    pub fn clear(&mut self) {
        self.set_mask(0);
    }

    /// Returns `true` when zero button bits are set.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Button bitset reference.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when empty.
    #[inline(always)]
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.get_mask() == 0
    }

    /// Sets the bit for `button`, returning `true` if the bit transitioned from `0` to `1`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable button bitset.
    /// - `PointerButton` - Button to mark set.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` if `button` was not already set.
    #[inline(always)]
    pub fn insert(&mut self, button: PointerButton) -> bool {
        let bit: u16 = Self::button_mask(button);
        let cur: u16 = self.get_mask();
        let was_set: bool = (cur & bit) != 0;
        self.set_mask(cur | bit);
        !was_set
    }

    /// Clears the bit for `button`, returning `true` if the bit transitioned from `1` to `0`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable button bitset.
    /// - `&PointerButton` - Button to clear.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` if `button` was previously set.
    #[inline(always)]
    pub fn remove(&mut self, button: &PointerButton) -> bool {
        let bit: u16 = Self::button_mask(*button);
        let cur: u16 = self.get_mask();
        let was_set: bool = (cur & bit) != 0;
        self.set_mask(cur & !bit);
        was_set
    }

    /// Returns `true` when the bit for `button` is set.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Button bitset reference.
    /// - `&PointerButton` - Button to query.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` if set.
    #[inline(always)]
    #[must_use]
    pub fn contains(&self, button: &PointerButton) -> bool {
        (self.get_mask() & Self::button_mask(*button)) != 0
    }
}

/// Per-frame input ingestion and real-time polling helpers for `InputState`.
impl InputState {
    /// Clears transient per-frame edge states (`just_pressed`, `just_released`, deltas) after a frame step.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable input state.
    pub fn begin_frame(&mut self) {
        self.get_mut_keys_just_pressed().clear();
        self.get_mut_keys_just_released().clear();
        self.get_mut_buttons_just_pressed().clear();
        self.get_mut_buttons_just_released().clear();
        self.set_pointer_delta(Point::new(0.0, 0.0));
        self.set_scroll_delta(Point::new(0.0, 0.0));
    }

    /// Returns a zero-allocation `Copy` snapshot containing held keys/buttons and axes with all transient edge events cleared.
    ///
    /// Used when executing subsequent fixed-timestep substeps so press/release edges are consumed exactly once.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    ///
    /// # Returns
    ///
    /// - `Self` - Edge-cleared input snapshot preserving held state.
    #[must_use]
    pub fn without_edges(&self) -> Self {
        let mut copy: Self = *self;
        copy.begin_frame();
        copy
    }

    /// Returns `true` when any transient edge (`just_pressed`, `just_released`, pointer/scroll delta) is latched.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether pending edge events remain unconsumed.
    #[must_use]
    pub fn has_pending_edges(&self) -> bool {
        let key_edges: bool =
            !self.get_keys_just_pressed().is_empty() || !self.get_keys_just_released().is_empty();
        let btn_edges: bool = !self.get_buttons_just_pressed().is_empty()
            || !self.get_buttons_just_released().is_empty();
        let p_delta: Point = self.get_pointer_delta();
        let s_delta: Point = self.get_scroll_delta();
        let motion_edges: bool = p_delta.get_x() != 0.0
            || p_delta.get_y() != 0.0
            || s_delta.get_x() != 0.0
            || s_delta.get_y() != 0.0;
        if key_edges || btn_edges {
            true
        } else {
            motion_edges
        }
    }

    /// Updates continuous and edge-triggered states from a platform `WindowEvent`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable input state.
    /// - `&WindowEvent` - Incoming OS or test event.
    pub fn ingest(&mut self, event: &WindowEvent) {
        match event {
            WindowEvent::KeyDown(_, key) => {
                self.set_modifiers(key.get_modifiers());
                let code: KeyCode = key.get_code();
                if self.get_mut_keys_down().insert(code) {
                    let _: bool = self.get_mut_keys_just_pressed().insert(code);
                }
            }
            WindowEvent::KeyUp(_, key) => {
                self.set_modifiers(key.get_modifiers());
                let code: KeyCode = key.get_code();
                if self.get_mut_keys_down().remove(&code) {
                    let _: bool = self.get_mut_keys_just_released().insert(code);
                }
            }
            WindowEvent::PointerMove(_, ptr) => {
                self.set_modifiers(ptr.get_modifiers());
                let prev: Point = self.get_pointer_position();
                let next: Point = ptr.get_position();
                let delta: Point = self.get_pointer_delta();
                self.set_pointer_delta(Point::new(
                    delta.get_x() + (next.get_x() - prev.get_x()),
                    delta.get_y() + (next.get_y() - prev.get_y()),
                ));
                self.set_pointer_position(next);
            }
            WindowEvent::PointerDown(_, ptr) => {
                self.set_modifiers(ptr.get_modifiers());
                self.set_pointer_position(ptr.get_position());
                let btn: PointerButton = ptr.get_button();
                if self.get_mut_buttons_down().insert(btn) {
                    let _: bool = self.get_mut_buttons_just_pressed().insert(btn);
                }
            }
            WindowEvent::PointerUp(_, ptr) => {
                self.set_modifiers(ptr.get_modifiers());
                self.set_pointer_position(ptr.get_position());
                let btn: PointerButton = ptr.get_button();
                if self.get_mut_buttons_down().remove(&btn) {
                    let _: bool = self.get_mut_buttons_just_released().insert(btn);
                }
            }
            WindowEvent::Scroll(_, delta) => {
                let cur: Point = self.get_scroll_delta();
                self.set_scroll_delta(Point::new(
                    cur.get_x() + delta.get_x(),
                    cur.get_y() + delta.get_y(),
                ));
            }
            WindowEvent::Focused(_, false) => {
                self.get_mut_keys_down().clear();
                self.get_mut_buttons_down().clear();
                self.set_modifiers(Modifiers::default());
            }
            _ => {}
        }
    }

    /// Returns `true` while `key` is held down.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `KeyCode` - Key to query.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the key is held.
    #[inline(always)]
    #[must_use]
    pub fn is_key_down(&self, key: KeyCode) -> bool {
        self.get_keys_down().contains(&key)
    }

    /// Returns `true` if `key` transitioned from up to down during the current frame.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `KeyCode` - Key to query.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the key was just pressed.
    #[inline(always)]
    #[must_use]
    pub fn is_key_just_pressed(&self, key: KeyCode) -> bool {
        self.get_keys_just_pressed().contains(&key)
    }

    /// Returns `true` if `key` transitioned from down to up during the current frame.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `KeyCode` - Key to query.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the key was just released.
    #[inline(always)]
    #[must_use]
    pub fn is_key_just_released(&self, key: KeyCode) -> bool {
        self.get_keys_just_released().contains(&key)
    }

    /// Returns `true` while pointer `button` is held down.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `PointerButton` - Button to query.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the button is held.
    #[inline(always)]
    #[must_use]
    pub fn is_button_down(&self, button: PointerButton) -> bool {
        self.get_buttons_down().contains(&button)
    }

    /// Returns `true` if pointer `button` transitioned from up to down during the current frame.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `PointerButton` - Button to query.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the button was just pressed.
    #[inline(always)]
    #[must_use]
    pub fn is_button_just_pressed(&self, button: PointerButton) -> bool {
        self.get_buttons_just_pressed().contains(&button)
    }

    /// Returns `true` if pointer `button` transitioned from down to up during the current frame.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `PointerButton` - Button to query.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the button was just released.
    #[inline(always)]
    #[must_use]
    pub fn is_button_just_released(&self, button: PointerButton) -> bool {
        self.get_buttons_just_released().contains(&button)
    }

    /// Computes a normalized `-1.0..=1.0` movement axis from negative and positive key bindings.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Input state reference.
    /// - `KeyCode` - Negative direction key.
    /// - `KeyCode` - Positive direction key.
    ///
    /// # Returns
    ///
    /// - `f32` - Axis value in `{-1.0, 0.0, 1.0}`.
    #[must_use]
    pub fn axis(&self, negative: KeyCode, positive: KeyCode) -> f32 {
        let mut value: f32 = 0.0;
        if self.is_key_down(negative) {
            value -= 1.0;
        }
        if self.is_key_down(positive) {
            value += 1.0;
        }
        value
    }

    /// Sets the normalized analog virtual stick vector `(dx, dy)` for mobile touch joysticks or gamepads.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable input state.
    /// - `f32` - Horizontal axis in `[-1.0, 1.0]`.
    /// - `f32` - Vertical axis in `[-1.0, 1.0]`.
    pub fn set_virtual_stick(&mut self, dx: f32, dy: f32) {
        self.set_virtual_axis(Point::new(dx.clamp(-1.0, 1.0), dy.clamp(-1.0, 1.0)));
    }

    /// Resets the virtual analog stick to neutral `(0.0, 0.0)`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable input state.
    pub fn clear_virtual_stick(&mut self) {
        self.set_virtual_axis(Point::new(0.0, 0.0));
    }
}

/// Default arcade action map binding WASD + Arrows, Space/Click fire, Shift/E dash, and P/Esc pause.
impl Default for ActionMap {
    /// Creates an `ActionMap` pre-populated with standard desktop/web arcade controls.
    ///
    /// # Returns
    ///
    /// - `Self` - Standard arcade action map.
    fn default() -> Self {
        let mut map: Self = Self {
            key_bindings: HashMap::new(),
            button_bindings: HashMap::new(),
        };
        map.bind_key(GameAction::MoveLeft, KeyCode::ArrowLeft);
        map.bind_key(GameAction::MoveLeft, KeyCode::Character('a'));
        map.bind_key(GameAction::MoveLeft, KeyCode::Character('A'));
        map.bind_key(GameAction::MoveRight, KeyCode::ArrowRight);
        map.bind_key(GameAction::MoveRight, KeyCode::Character('d'));
        map.bind_key(GameAction::MoveRight, KeyCode::Character('D'));
        map.bind_key(GameAction::MoveUp, KeyCode::ArrowUp);
        map.bind_key(GameAction::MoveUp, KeyCode::Character('w'));
        map.bind_key(GameAction::MoveUp, KeyCode::Character('W'));
        map.bind_key(GameAction::MoveDown, KeyCode::ArrowDown);
        map.bind_key(GameAction::MoveDown, KeyCode::Character('s'));
        map.bind_key(GameAction::MoveDown, KeyCode::Character('S'));
        map.bind_key(GameAction::Fire, KeyCode::Space);
        map.bind_key(GameAction::Fire, KeyCode::Character('j'));
        map.bind_button(GameAction::Fire, PointerButton::Primary);
        map.bind_key(GameAction::Dash, KeyCode::Character('e'));
        map.bind_key(GameAction::Dash, KeyCode::Character('E'));
        map.bind_key(GameAction::Jump, KeyCode::Space);
        map.bind_key(GameAction::Pause, KeyCode::Escape);
        map.bind_key(GameAction::Pause, KeyCode::Character('p'));
        map.bind_key(GameAction::ActionAlt, KeyCode::Character('r'));
        map.bind_key(GameAction::ActionAlt, KeyCode::Character('R'));
        map
    }
}

/// Binding registration and real-time input queries for `ActionMap`.
impl ActionMap {
    /// Binds a `KeyCode` to `action`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable action map.
    /// - `GameAction` - Semantic game action.
    /// - `KeyCode` - Keyboard key to bind.
    pub fn bind_key(&mut self, action: GameAction, key: KeyCode) {
        self.get_mut_key_bindings()
            .entry(action)
            .or_default()
            .push(key);
    }

    /// Binds a `PointerButton` to `action`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable action map.
    /// - `GameAction` - Semantic game action.
    /// - `PointerButton` - Mouse/touch button to bind.
    pub fn bind_button(&mut self, action: GameAction, button: PointerButton) {
        self.get_mut_button_bindings()
            .entry(action)
            .or_default()
            .push(button);
    }

    /// Returns `true` while any key or button bound to `action` is held in `input`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Action map reference.
    /// - `GameAction` - Action to query.
    /// - `&InputState` - Current polled input snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether `action` is currently active.
    #[must_use]
    pub fn is_active(&self, action: GameAction, input: &InputState) -> bool {
        if action == GameAction::Fire && input.get_virtual_fire() {
            return true;
        }
        if action == GameAction::Dash && input.get_virtual_dash() {
            return true;
        }
        let key_hit: bool = self
            .get_key_bindings()
            .get(&action)
            .map(|keys: &Vec<KeyCode>| keys.iter().copied().any(|k: KeyCode| input.is_key_down(k)))
            .unwrap_or(false);
        if key_hit {
            return true;
        }
        self.get_button_bindings()
            .get(&action)
            .map(|btns: &Vec<PointerButton>| {
                btns.iter()
                    .copied()
                    .any(|b: PointerButton| input.is_button_down(b))
            })
            .unwrap_or(false)
    }

    /// Returns `true` when any key bound to `action` transitioned down on this frame.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Action map reference.
    /// - `GameAction` - Action to query.
    /// - `&InputState` - Current polled input snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether `action` was just triggered.
    #[must_use]
    pub fn is_just_pressed(&self, action: GameAction, input: &InputState) -> bool {
        self.get_key_bindings()
            .get(&action)
            .map(|keys: &Vec<KeyCode>| {
                keys.iter()
                    .copied()
                    .any(|k: KeyCode| input.is_key_just_pressed(k))
            })
            .unwrap_or(false)
    }

    /// Computes a normalized 2D movement vector `(dx, dy)` from directional action bindings.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Action map reference.
    /// - `&InputState` - Current polled input snapshot.
    ///
    /// # Returns
    ///
    /// - `Point` - Normalized movement vector with length `<= 1.0`.
    #[must_use]
    pub fn movement_vector(&self, input: &InputState) -> Point {
        let mut dx: f32 = input.get_virtual_axis().get_x();
        let mut dy: f32 = input.get_virtual_axis().get_y();
        if self.is_active(GameAction::MoveLeft, input) {
            dx -= 1.0;
        }
        if self.is_active(GameAction::MoveRight, input) {
            dx += 1.0;
        }
        if self.is_active(GameAction::MoveUp, input) {
            dy -= 1.0;
        }
        if self.is_active(GameAction::MoveDown, input) {
            dy += 1.0;
        }
        let len: f32 = (dx * dx + dy * dy).sqrt();
        if len > 1.0 {
            Point::new(dx / len, dy / len)
        } else {
            Point::new(dx, dy)
        }
    }
}