mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 16:28:42 -06:00
input system updates
This commit is contained in:
parent
567e6d8d85
commit
9c802a6e70
10
src/input.rs
10
src/input.rs
|
@ -3,17 +3,20 @@ use shipyard::{AllStoragesView, Unique};
|
|||
use hashbrown::HashMap;
|
||||
use nohash_hasher::BuildNoHashHasher;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(u8)]
|
||||
pub enum Action {
|
||||
Move(f32, f32),
|
||||
Look(f32, f32),
|
||||
}
|
||||
|
||||
pub type MouseCallback<A> = fn(x: f32, y: f32) -> A;
|
||||
|
||||
#[derive(Unique)]
|
||||
pub struct InputSystem<A: 'static> {
|
||||
pub keyboard_keymap: HashMap<VirtualKeyCode, A, BuildNoHashHasher<u32>>,
|
||||
mouse_map: Option<fn(f32, f32) -> A>,
|
||||
mouse_map: Option<MouseCallback<A>>,
|
||||
pub mouse_sensitivity: f32,
|
||||
keyboard_state: HashMap<VirtualKeyCode, bool, BuildNoHashHasher<u32>>,
|
||||
mouse_delta: (f32, f32),
|
||||
mouse_position: (f32, f32),
|
||||
|
@ -23,12 +26,13 @@ impl<A> InputSystem<A> {
|
|||
Self {
|
||||
keyboard_keymap: HashMap::with_hasher(BuildNoHashHasher::default()),
|
||||
mouse_map: None,
|
||||
mouse_sensitivity: 1.,
|
||||
keyboard_state: HashMap::with_hasher(BuildNoHashHasher::default()),
|
||||
mouse_delta: (0., 0.),
|
||||
mouse_position: (0., 0.),
|
||||
}
|
||||
}
|
||||
pub fn map_to_mouse(&mut self, function: fn(f32, f32) -> A) {
|
||||
pub fn map_to_mouse(&mut self, function: MouseCallback<A>) {
|
||||
self.mouse_map = Some(function);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue