-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathengine_state.rs
More file actions
46 lines (38 loc) · 1.09 KB
/
engine_state.rs
File metadata and controls
46 lines (38 loc) · 1.09 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
use config::Config;
use std::sync::{Arc, Mutex};
use input::InputSystem;
use renderer::GraphicsState;
/// Proxy to the current state of the Engine
#[derive(Clone)]
pub struct EngineState {
/// Unique ID for actor recieving engine state.
id: u64,
input: Arc<Mutex<InputSystem>>,
/// Graphics State (Cameras, Geometry, etc.)
pub gfx: Arc<Mutex<GraphicsState>>,
/// Game Engine State (Resolution, quality, inputs, etc.)
config: Arc<Config>
}
impl EngineState {
pub fn new(id: u64, config: Arc<Config>, input: Arc<Mutex<InputSystem>>, gfx: Arc<Mutex<GraphicsState>> ) -> EngineState {
EngineState {
id,
input,
gfx,
config
}
}
pub fn id(self) -> u64 {
self.id
}
/// Get the value of an input axis
pub fn input_axis(&self, key: String) -> f32 {
match self.input.lock() {
Ok(input_guard) => {
let input_system = &*input_guard;
input_system.inputs.get(&key).unwrap_or(&0.0).clone()
},
_ => 0.0
}
}
}