-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmod.rs
More file actions
56 lines (42 loc) · 1.23 KB
/
mod.rs
File metadata and controls
56 lines (42 loc) · 1.23 KB
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
/*!
# Input Module
This module takes care of all input events processed by the engine.
It's modeled similarly to the axis system in Unreal Engine 4.
*/
mod events;
use winit::Event;
use config::Config;
use std::clone::Clone;
use std::collections::HashMap;
use std::sync::Arc;
/// Core Input System
pub struct InputSystem {
config: Arc<Config>,
pub inputs: HashMap<String, f32>,
}
//Input System
impl InputSystem {
pub fn new(config: Arc<Config>) -> InputSystem {
let inputs: HashMap<String, f32> =
config.input.keys().map(|k| (k.clone(), 0.0)).collect();
InputSystem {
inputs,
config
}
}
/// Polls window events
pub fn poll(&mut self, ev: &Event) {
// Axis Map
for (string_key, axis) in self.config.input.iter() {
for axis_value in axis {
let out = events::string_to_wevent(&axis_value.key, &ev);
// @TODO - Check axis_value.meta for additional checks.
// Write to axis map
match out {
Some(x) => *self.inputs.get_mut(string_key).unwrap() = x,
None => (),
};
}
}
}
}