fix: window input uses get_keys() for held state, glyph atlas for FPS

Input fix: get_keys_pressed(No) only fires on initial press, not held.
Switched to get_keys() which returns all currently-down keys every frame.
Jump still edge-triggered via jump_was_down flag.

Performance fix: pre-build glyph atlas at startup (all ASCII chars
rasterized once into 128x256 alpha bitmap). No per-frame cloning.
draw_cell reads atlas alpha + blends fg/bg inline. Zero allocations
in render loop.

109 tests, 0 warnings
This commit is contained in:
Emil
2026-06-21 00:01:28 +03:00
parent 19bd883645
commit 65752b4cfe
3 changed files with 90 additions and 69 deletions
+10 -14
View File
@@ -10,6 +10,7 @@ pub struct WindowInput {
pub cam_down: bool,
pub quit: bool,
pub paint: Option<u8>,
jump_was_down: bool,
}
impl WindowInput {
@@ -18,30 +19,25 @@ impl WindowInput {
left: false, right: false, jump: false,
cam_left: false, cam_right: false, cam_up: false, cam_down: false,
quit: false, paint: None,
jump_was_down: false,
}
}
pub fn update(&mut self, keys: &[Key]) {
let was_jump = self.jump;
let now_left = keys.contains(&Key::A) || keys.contains(&Key::Left);
let now_right = keys.contains(&Key::D) || keys.contains(&Key::Right);
let now_jump = keys.contains(&Key::W) || keys.contains(&Key::Space) || keys.contains(&Key::Up);
let now_cam_left = keys.contains(&Key::H);
let now_cam_right = keys.contains(&Key::L);
let now_cam_up = keys.contains(&Key::K);
let now_cam_down = keys.contains(&Key::J);
self.left = now_left && !now_right;
self.right = now_right && !now_left;
if now_left && now_right {
self.left = false;
self.right = false;
}
self.jump = now_jump && !was_jump;
self.cam_left = now_cam_left;
self.cam_right = now_cam_right;
self.cam_up = now_cam_up;
self.cam_down = now_cam_down;
self.jump = now_jump && !self.jump_was_down;
self.jump_was_down = now_jump;
self.cam_left = keys.contains(&Key::H);
self.cam_right = keys.contains(&Key::L);
self.cam_up = keys.contains(&Key::K);
self.cam_down = keys.contains(&Key::J);
self.quit = keys.contains(&Key::Q) || keys.contains(&Key::Escape);
self.paint = None;