From 0edd6b64110e763b7ec75d8be5c5e1fae16f551d Mon Sep 17 00:00:00 2001 From: Asuro Date: Sun, 29 Nov 2020 22:02:49 +0100 Subject: [PATCH] Input log settings --- config/input.toml | 24 ++++++++++++++++-------- config/log.toml | 8 ++++++-- src/config.rs | 8 +++++++- src/input.rs | 34 +++++++++++++++++++++------------- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/config/input.toml b/config/input.toml index 34b9065..fd5ad68 100644 --- a/config/input.toml +++ b/config/input.toml @@ -12,29 +12,37 @@ name = "print_framerate" scan_code = 33 [[button]] -name = "w" +name = "button_forward" scan_code = 17 [[button]] -name = "s" +name = "button_backward" scan_code = 31 [[button]] -name = "a" +name = "button_left" scan_code = 30 [[button]] -name = "d" +name = "button_right" scan_code = 32 [[button]] name = "test" scan_code = 20 +[[button]] +name = "quicksave" +scan_code = 63 + +[[button]] +name = "quickload" +scan_code = 64 + [[axis]] name = "move_forward" -positive_button = "w" -negative_button = "s" +positive_button = "button_forward" +negative_button = "button_backward" [[axis]] name = "move_forward" @@ -46,8 +54,8 @@ controller_axis = "LeftStickY" [[axis]] name = "move_sideways" -positive_button = "d" -negative_button = "a" +positive_button = "button_right" +negative_button = "button_left" [[axis]] name = "move_sideways" diff --git a/config/log.toml b/config/log.toml index 21f4239..73d0727 100644 --- a/config/log.toml +++ b/config/log.toml @@ -1,3 +1,7 @@ -input_events = false vulkan_validation_layers = true -mesh_load_info = true \ No newline at end of file +mesh_load_info = true + +[input] +mouse_motion = false +buttons = false +missing_bindings = true \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index aa42ae0..d181397 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,12 +1,18 @@ use serde_derive::{Serialize, Deserialize}; use toml; use std::fs; +#[derive(Debug, Serialize, Deserialize, Clone, Copy)] +pub struct LogConfigInput { + pub mouse_motion: bool, + pub buttons: bool, + pub missing_bindings: bool +} #[derive(Debug, Serialize, Deserialize, Clone, Copy)] pub struct LogConfig { - pub input_events: bool, pub vulkan_validation_layers: bool, pub mesh_load_info: bool, + pub input: LogConfigInput } impl LogConfig { diff --git a/src/input.rs b/src/input.rs index b1c59b0..e6eb131 100644 --- a/src/input.rs +++ b/src/input.rs @@ -191,19 +191,19 @@ impl InputState { pub fn on_window_event(self: &mut Self, event: &Event<()>) { match event { Event::WindowEvent { event: WindowEvent::KeyboardInput { device_id, input, .. }, .. } => { - if self.log_config.input_events { + if self.log_config.input.buttons { let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&input.modifiers)); if mods.len() > 0 { - println!("Keyboard {:?} {:?} {:?} + {:?}", device_id, input.state, &mods, input.virtual_keycode) + println!("Keyboard {:?} {:?} {:?} + {:?} {:?}", device_id, input.state, &mods, input.virtual_keycode, input.scancode) } else { - println!("Keyboard {:?} {:?} {:?}", device_id, input.state, input.virtual_keycode) + println!("Keyboard {:?} {:?} {:?} {:?}", device_id, input.state, input.virtual_keycode, input.scancode) } } self.on_keyboard_event(input.state, input.scancode, KeyboardModifierState::from_deprecated_state(&input.modifiers)); }, Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => { - if self.log_config.input_events { + if self.log_config.input.buttons { let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers)); if mods.len() > 0 { println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button) @@ -215,7 +215,7 @@ impl InputState { self.on_mouse_event(state, button, &KeyboardModifierState::from_deprecated_state(&modifiers)); }, Event::WindowEvent { event: WindowEvent::MouseWheel { device_id, delta, phase, modifiers }, .. } => { - if self.log_config.input_events { + if self.log_config.input.buttons { let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers)); if mods.len() > 0 { println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta) @@ -227,7 +227,7 @@ impl InputState { self.on_mouse_wheel_event(delta, &KeyboardModifierState::from_deprecated_state(&modifiers)); }, Event::DeviceEvent { device_id, event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) } } => { - if self.log_config.input_events { + if self.log_config.input.mouse_motion { println!("MouseMotion {:?}, ({:?},{:?})", device_id, delta_x, delta_y); } self.mouse_delta_x += *delta_x; @@ -243,7 +243,9 @@ impl InputState { virtual_button.digital_inputs.iter().any(|vi| self.digital_input_pressed(vi)) } None => { - assert!(false, format!("Button {:?} not found!", button_code)); + if self.log_config.input.buttons { + println!("Button {:?} not found!", button_code); + } false } } @@ -261,7 +263,9 @@ impl InputState { }) } None => { - assert!(false, format!("Button {:?} not found!", button_code)); + if self.log_config.input.missing_bindings { + println!("Button {:?} not found!", button_code); + } false } } @@ -279,7 +283,9 @@ impl InputState { }) } None => { - assert!(false, format!("Button {:?} not found!", button_code)); + if self.log_config.input.missing_bindings { + println!("Button {:?} not found!", button_code); + } false } } @@ -313,7 +319,9 @@ impl InputState { } }).fold(0.0, fold_axis_value) } else { - assert!(false, format!("Axis {:?} not found!", axis_code)); + if self.log_config.input.missing_bindings { + println!("Axis {:?} not found!", axis_code); + } 0.0 } } @@ -407,17 +415,17 @@ impl InputState { while let Some(event) = self.controller_input.next_event() { match event.event { EventType::ButtonPressed(button, _) => { - if self.log_config.input_events { println!("ControllerButton Pressed {:?} {:?}", event.id, button); } + if self.log_config.input.buttons { println!("ControllerButton Pressed {:?} {:?}", event.id, button); } self.input_events.insert(DigitalInputEvent::Pressed(DigitalInput::Controller(ControllerInput { button }))); }, EventType::ButtonRepeated(_, _) => {}, EventType::ButtonReleased(button, _) => { - if self.log_config.input_events { println!("ControllerButton Released {:?} {:?}", event.id, button); } + if self.log_config.input.buttons { println!("ControllerButton Released {:?} {:?}", event.id, button); } self.input_events.insert(DigitalInputEvent::Released(DigitalInput::Controller(ControllerInput { button }))); }, EventType::ButtonChanged(_, _, _) => {}, EventType::AxisChanged(axis, value, _) => { - if self.log_config.input_events { println!("ControllerAxis {:?} {:?} {:?}", event.id, axis, value); } + if self.log_config.input.buttons { println!("ControllerAxis {:?} {:?} {:?}", event.id, axis, value); } }, EventType::Connected => {}, EventType::Disconnected => {},