Input log settings

This commit is contained in:
2020-11-29 22:02:49 +01:00
parent 62ec222749
commit 0edd6b6411
4 changed files with 50 additions and 24 deletions

View File

@@ -12,29 +12,37 @@ name = "print_framerate"
scan_code = 33 scan_code = 33
[[button]] [[button]]
name = "w" name = "button_forward"
scan_code = 17 scan_code = 17
[[button]] [[button]]
name = "s" name = "button_backward"
scan_code = 31 scan_code = 31
[[button]] [[button]]
name = "a" name = "button_left"
scan_code = 30 scan_code = 30
[[button]] [[button]]
name = "d" name = "button_right"
scan_code = 32 scan_code = 32
[[button]] [[button]]
name = "test" name = "test"
scan_code = 20 scan_code = 20
[[button]]
name = "quicksave"
scan_code = 63
[[button]]
name = "quickload"
scan_code = 64
[[axis]] [[axis]]
name = "move_forward" name = "move_forward"
positive_button = "w" positive_button = "button_forward"
negative_button = "s" negative_button = "button_backward"
[[axis]] [[axis]]
name = "move_forward" name = "move_forward"
@@ -46,8 +54,8 @@ controller_axis = "LeftStickY"
[[axis]] [[axis]]
name = "move_sideways" name = "move_sideways"
positive_button = "d" positive_button = "button_right"
negative_button = "a" negative_button = "button_left"
[[axis]] [[axis]]
name = "move_sideways" name = "move_sideways"

View File

@@ -1,3 +1,7 @@
input_events = false
vulkan_validation_layers = true vulkan_validation_layers = true
mesh_load_info = true mesh_load_info = true
[input]
mouse_motion = false
buttons = false
missing_bindings = true

View File

@@ -1,12 +1,18 @@
use serde_derive::{Serialize, Deserialize}; use serde_derive::{Serialize, Deserialize};
use toml; use toml;
use std::fs; 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)] #[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub struct LogConfig { pub struct LogConfig {
pub input_events: bool,
pub vulkan_validation_layers: bool, pub vulkan_validation_layers: bool,
pub mesh_load_info: bool, pub mesh_load_info: bool,
pub input: LogConfigInput
} }
impl LogConfig { impl LogConfig {

View File

@@ -191,19 +191,19 @@ impl InputState {
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_events { if self.log_config.input.buttons {
let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&input.modifiers)); let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&input.modifiers));
if mods.len() > 0 { 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 { } 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)); self.on_keyboard_event(input.state, input.scancode, KeyboardModifierState::from_deprecated_state(&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_events { if self.log_config.input.buttons {
let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers)); let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers));
if mods.len() > 0 { if mods.len() > 0 {
println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button) println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button)
@@ -215,7 +215,7 @@ impl InputState {
self.on_mouse_event(state, button, &KeyboardModifierState::from_deprecated_state(&modifiers)); self.on_mouse_event(state, button, &KeyboardModifierState::from_deprecated_state(&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_events { if self.log_config.input.buttons {
let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers)); let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers));
if mods.len() > 0 { if mods.len() > 0 {
println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta) println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta)
@@ -227,7 +227,7 @@ impl InputState {
self.on_mouse_wheel_event(delta, &KeyboardModifierState::from_deprecated_state(&modifiers)); self.on_mouse_wheel_event(delta, &KeyboardModifierState::from_deprecated_state(&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_events { if self.log_config.input.mouse_motion {
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;
@@ -243,7 +243,9 @@ impl InputState {
virtual_button.digital_inputs.iter().any(|vi| self.digital_input_pressed(vi)) virtual_button.digital_inputs.iter().any(|vi| self.digital_input_pressed(vi))
} }
None => { None => {
assert!(false, format!("Button {:?} not found!", button_code)); if self.log_config.input.buttons {
println!("Button {:?} not found!", button_code);
}
false false
} }
} }
@@ -261,7 +263,9 @@ impl InputState {
}) })
} }
None => { None => {
assert!(false, format!("Button {:?} not found!", button_code)); if self.log_config.input.missing_bindings {
println!("Button {:?} not found!", button_code);
}
false false
} }
} }
@@ -279,7 +283,9 @@ impl InputState {
}) })
} }
None => { None => {
assert!(false, format!("Button {:?} not found!", button_code)); if self.log_config.input.missing_bindings {
println!("Button {:?} not found!", button_code);
}
false false
} }
} }
@@ -313,7 +319,9 @@ impl InputState {
} }
}).fold(0.0, fold_axis_value) }).fold(0.0, fold_axis_value)
} else { } else {
assert!(false, format!("Axis {:?} not found!", axis_code)); if self.log_config.input.missing_bindings {
println!("Axis {:?} not found!", axis_code);
}
0.0 0.0
} }
} }
@@ -407,17 +415,17 @@ impl InputState {
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); } if self.log_config.input.buttons { 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); } if self.log_config.input.buttons { 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(axis, value, _) => { 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::Connected => {},
EventType::Disconnected => {}, EventType::Disconnected => {},