blob: 90ddbb28c9e4f73b68081444158dd6d103d4e1b7 (
plain)
use crossterm::event::KeyCode;
use rustc_hash::FxHashSet;
#[derive(Debug, Default, Clone)]
pub struct InputManager {
pressed_keys: FxHashSet<KeyCode>,
}
impl InputManager {
pub fn new() -> Self {
Self {
pressed_keys: FxHashSet::default(),
}
}
pub fn press_key(&mut self, key_code: KeyCode) {
self.pressed_keys.insert(key_code);
}
pub fn reset_next_frame(&mut self) {
puffin::profile_function!();
self.pressed_keys.clear();
}
pub fn is_key_pressed_this_frame(&self, key_code: KeyCode) -> bool {
self.pressed_keys.contains(&key_code)
}
}
|