print controller input
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
input = false
|
input_events = false
|
||||||
vulkan_validation_layers = true
|
vulkan_validation_layers = true
|
||||||
|
mesh_load_info = true
|
||||||
@@ -2,10 +2,11 @@ use serde_derive::{Serialize, Deserialize};
|
|||||||
use toml;
|
use toml;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
pub struct LogConfig {
|
pub struct LogConfig {
|
||||||
pub input: bool,
|
pub input_events: bool,
|
||||||
pub vulkan_validation_layers: bool,
|
pub vulkan_validation_layers: bool,
|
||||||
|
pub mesh_load_info: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LogConfig {
|
impl LogConfig {
|
||||||
|
|||||||
22
src/input.rs
22
src/input.rs
@@ -67,7 +67,7 @@ struct InputConfigAxis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct InputState<'a> {
|
pub struct InputState {
|
||||||
pub virtual_buttons: HashMap<String, VirtualButton>,
|
pub virtual_buttons: HashMap<String, VirtualButton>,
|
||||||
pub virtual_axes: HashMap<String, VirtualAxis>,
|
pub virtual_axes: HashMap<String, VirtualAxis>,
|
||||||
pub mouse_delta_x: f64,
|
pub mouse_delta_x: f64,
|
||||||
@@ -77,12 +77,12 @@ pub struct InputState<'a> {
|
|||||||
pressed_mouse_buttons: HashSet<MouseButton>,
|
pressed_mouse_buttons: HashSet<MouseButton>,
|
||||||
analog_wheel_state: f32,
|
analog_wheel_state: f32,
|
||||||
config: InputConfigConfig,
|
config: InputConfigConfig,
|
||||||
log_config: &'a LogConfig,
|
log_config: LogConfig,
|
||||||
controller_input: Gilrs,
|
controller_input: Gilrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a> InputState<'a> {
|
impl InputState {
|
||||||
pub fn new(toml_path: &str, log_config: &'a LogConfig) -> InputState<'a> {
|
pub fn new(toml_path: &str, log_config: LogConfig) -> InputState {
|
||||||
let config: InputConfig = toml::from_slice(&fs::read(toml_path).expect("Failed to read input config!")).expect("Failed to parse input config!");
|
let config: InputConfig = toml::from_slice(&fs::read(toml_path).expect("Failed to read input config!")).expect("Failed to parse input config!");
|
||||||
|
|
||||||
let mut state = InputState { virtual_buttons: HashMap::new(), virtual_axes: HashMap::new(),
|
let mut state = InputState { virtual_buttons: HashMap::new(), virtual_axes: HashMap::new(),
|
||||||
@@ -170,7 +170,7 @@ impl <'a> InputState<'a> {
|
|||||||
pub fn on_window_event(self: &mut Self, event: &Event) {
|
pub fn on_window_event(self: &mut Self, event: &Event) {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event: WindowEvent::KeyboardInput { device_id, input }, .. } => {
|
Event::WindowEvent { event: WindowEvent::KeyboardInput { device_id, input }, .. } => {
|
||||||
if self.log_config.input {
|
if self.log_config.input_events {
|
||||||
let mods = mods_to_string(&input.modifiers);
|
let mods = mods_to_string(&input.modifiers);
|
||||||
if mods.len() > 0 {
|
if mods.len() > 0 {
|
||||||
println!("Keyboard {:?} {:?} {:?} + {:?}", device_id, input.state, &mods, input.scancode)
|
println!("Keyboard {:?} {:?} {:?} + {:?}", device_id, input.state, &mods, input.scancode)
|
||||||
@@ -182,7 +182,7 @@ impl <'a> InputState<'a> {
|
|||||||
self.on_keyboard_event(input.state, input.scancode, input.modifiers);
|
self.on_keyboard_event(input.state, input.scancode, input.modifiers);
|
||||||
},
|
},
|
||||||
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
|
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
|
||||||
if self.log_config.input {
|
if self.log_config.input_events {
|
||||||
let mods = mods_to_string(&modifiers);
|
let mods = mods_to_string(&modifiers);
|
||||||
if mods.len() > 0 {
|
if mods.len() > 0 {
|
||||||
println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button)
|
println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button)
|
||||||
@@ -194,7 +194,7 @@ impl <'a> InputState<'a> {
|
|||||||
self.on_mouse_event(state, button, modifiers);
|
self.on_mouse_event(state, button, modifiers);
|
||||||
},
|
},
|
||||||
Event::WindowEvent { event: WindowEvent::MouseWheel { device_id, delta, phase, modifiers }, .. } => {
|
Event::WindowEvent { event: WindowEvent::MouseWheel { device_id, delta, phase, modifiers }, .. } => {
|
||||||
if self.log_config.input {
|
if self.log_config.input_events {
|
||||||
let mods = mods_to_string(&modifiers);
|
let mods = mods_to_string(&modifiers);
|
||||||
if mods.len() > 0 {
|
if mods.len() > 0 {
|
||||||
println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta)
|
println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta)
|
||||||
@@ -206,7 +206,7 @@ impl <'a> InputState<'a> {
|
|||||||
self.on_mouse_wheel_event(delta, modifiers);
|
self.on_mouse_wheel_event(delta, modifiers);
|
||||||
},
|
},
|
||||||
Event::DeviceEvent { device_id, event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) } } => {
|
Event::DeviceEvent { device_id, event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) } } => {
|
||||||
if self.log_config.input {
|
if self.log_config.input_events {
|
||||||
println!("MouseMotion {:?}, ({:?},{:?})", device_id, delta_x, delta_y);
|
println!("MouseMotion {:?}, ({:?},{:?})", device_id, delta_x, delta_y);
|
||||||
}
|
}
|
||||||
self.mouse_delta_x += *delta_x;
|
self.mouse_delta_x += *delta_x;
|
||||||
@@ -385,14 +385,18 @@ impl <'a> InputState<'a> {
|
|||||||
while let Some(event) = self.controller_input.next_event() {
|
while let Some(event) = self.controller_input.next_event() {
|
||||||
match event.event {
|
match event.event {
|
||||||
EventType::ButtonPressed(button, _) => {
|
EventType::ButtonPressed(button, _) => {
|
||||||
|
if self.log_config.input_events { println!("ControllerButton Pressed {:?} {:?}", event.id, button); }
|
||||||
self.input_events.insert(DigitalInputEvent::Pressed(DigitalInput::Controller(ControllerInput { button })));
|
self.input_events.insert(DigitalInputEvent::Pressed(DigitalInput::Controller(ControllerInput { button })));
|
||||||
},
|
},
|
||||||
EventType::ButtonRepeated(_, _) => {},
|
EventType::ButtonRepeated(_, _) => {},
|
||||||
EventType::ButtonReleased(button, _) => {
|
EventType::ButtonReleased(button, _) => {
|
||||||
|
if self.log_config.input_events { println!("ControllerButton Released {:?} {:?}", event.id, button); }
|
||||||
self.input_events.insert(DigitalInputEvent::Released(DigitalInput::Controller(ControllerInput { button })));
|
self.input_events.insert(DigitalInputEvent::Released(DigitalInput::Controller(ControllerInput { button })));
|
||||||
},
|
},
|
||||||
EventType::ButtonChanged(_, _, _) => {},
|
EventType::ButtonChanged(_, _, _) => {},
|
||||||
EventType::AxisChanged(_, _, _) => {},
|
EventType::AxisChanged(axis, value, _) => {
|
||||||
|
if self.log_config.input_events { println!("ControllerAxis {:?} {:?} {:?}", event.id, axis, value); }
|
||||||
|
},
|
||||||
EventType::Connected => {},
|
EventType::Connected => {},
|
||||||
EventType::Disconnected => {},
|
EventType::Disconnected => {},
|
||||||
EventType::Dropped => {},
|
EventType::Dropped => {},
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@@ -12,23 +12,24 @@ use crate::config::LogConfig;
|
|||||||
|
|
||||||
mod mesh;
|
mod mesh;
|
||||||
|
|
||||||
struct TestGame<'a> {
|
struct TestGame {
|
||||||
input: InputState<'a>,
|
input: InputState,
|
||||||
cam_position: Vector3<f32>,
|
cam_position: Vector3<f32>,
|
||||||
cam_rotation: Quaternion<f32>,
|
cam_rotation: Quaternion<f32>,
|
||||||
cube_mesh: Option<MeshHandle>,
|
cube_mesh: Option<MeshHandle>,
|
||||||
cubes: Vec<GameObjectHandle>,
|
cubes: Vec<GameObjectHandle>,
|
||||||
|
log_config: LogConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game for TestGame<'_> {
|
impl Game for TestGame {
|
||||||
fn on_window_event(self: &mut Self, event: &Event) {
|
fn on_window_event(self: &mut Self, event: &Event) {
|
||||||
self.input.on_window_event(event);
|
self.input.on_window_event(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestGame<'_> {
|
impl TestGame {
|
||||||
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
||||||
self.cube_mesh = Some(renderer.upload_mesh(mesh::load_mesh("models/cube.dae", true).into_iter().nth(0).unwrap()));
|
self.cube_mesh = Some(renderer.upload_mesh(mesh::load_mesh("models/cube.dae", self.log_config.mesh_load_info).into_iter().nth(0).unwrap()));
|
||||||
println!("Game started.");
|
println!("Game started.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,11 +90,12 @@ fn main() {
|
|||||||
let log_config = LogConfig::from_file("config/log.toml");
|
let log_config = LogConfig::from_file("config/log.toml");
|
||||||
|
|
||||||
let mut game = TestGame {
|
let mut game = TestGame {
|
||||||
input: InputState::new("config/input.toml", &log_config),
|
input: InputState::new("config/input.toml", log_config),
|
||||||
cam_rotation: Quaternion::one(),
|
cam_rotation: Quaternion::one(),
|
||||||
cam_position: Vector3::new(0.0, 0.0, -10.0),
|
cam_position: Vector3::new(0.0, 0.0, -10.0),
|
||||||
cube_mesh: None,
|
cube_mesh: None,
|
||||||
cubes: vec![],
|
cubes: vec![],
|
||||||
|
log_config
|
||||||
};
|
};
|
||||||
|
|
||||||
let line_count = 30;
|
let line_count = 30;
|
||||||
|
|||||||
Reference in New Issue
Block a user