input refactor
This commit is contained in:
65
src/main.rs
65
src/main.rs
@@ -1,23 +1,23 @@
|
||||
use winit::{Event, WindowEvent, DeviceEvent};
|
||||
use winit::{Event};
|
||||
use cgmath::{Matrix4, Rad, Vector3, Deg, Quaternion, Rotation3, One, Rotation};
|
||||
|
||||
mod vulkan;
|
||||
use crate::vulkan::{GameData, Game, LinePoint};
|
||||
|
||||
mod input;
|
||||
use crate::input::{InputState, mods_to_string};
|
||||
use crate::input::{InputState};
|
||||
|
||||
mod config;
|
||||
use crate::config::LogConfig;
|
||||
|
||||
struct TestGame {
|
||||
input: InputState,
|
||||
struct TestGame<'a> {
|
||||
input: InputState<'a>,
|
||||
cam_position: Vector3<f32>,
|
||||
cam_rotation: Quaternion<f32>,
|
||||
log_config: LogConfig,
|
||||
log_config: &'a LogConfig,
|
||||
}
|
||||
|
||||
impl Game for TestGame {
|
||||
impl Game for TestGame<'_> {
|
||||
fn validation_layers_enabled(self: &Self) -> bool {
|
||||
self.log_config.vulkan_validation_layers
|
||||
}
|
||||
@@ -71,61 +71,18 @@ impl Game for TestGame {
|
||||
}
|
||||
|
||||
fn on_window_event(self: &mut Self, event: &Event) {
|
||||
match event {
|
||||
Event::WindowEvent { event: WindowEvent::KeyboardInput { device_id, input }, .. } => {
|
||||
if self.log_config.input {
|
||||
let mods = mods_to_string(&input.modifiers);
|
||||
if mods.len() > 0 {
|
||||
println!("Keyboard {:?} {:?} {:?} + {:?}", device_id, input.state, &mods, input.scancode)
|
||||
} else {
|
||||
println!("Keyboard {:?} {:?} {:?}", device_id, input.state, input.scancode)
|
||||
}
|
||||
}
|
||||
|
||||
self.input.on_keyboard_event(input.state, input.scancode, input.modifiers);
|
||||
},
|
||||
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
|
||||
if self.log_config.input {
|
||||
let mods = mods_to_string(modifiers);
|
||||
if mods.len() > 0 {
|
||||
println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button)
|
||||
} else {
|
||||
println!("Mouse {:?} {:?} {:?}", device_id, state, button)
|
||||
}
|
||||
}
|
||||
|
||||
self.input.on_mouse_event(state, button, modifiers);
|
||||
},
|
||||
Event::WindowEvent { event: WindowEvent::MouseWheel { device_id, delta, phase, modifiers }, .. } => {
|
||||
if self.log_config.input {
|
||||
let mods = mods_to_string(modifiers);
|
||||
if mods.len() > 0 {
|
||||
println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta)
|
||||
} else {
|
||||
println!("Scroll {:?} {:?} {:?}", device_id, phase, delta)
|
||||
}
|
||||
}
|
||||
|
||||
self.input.on_mouse_wheel_event(&delta, &modifiers);
|
||||
},
|
||||
Event::DeviceEvent { device_id, event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) } } => {
|
||||
if self.log_config.input {
|
||||
println!("MouseMotion {:?}, ({:?},{:?})", device_id, delta_x, delta_y);
|
||||
}
|
||||
self.input.mouse_delta_x += *delta_x;
|
||||
self.input.mouse_delta_y += *delta_y;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.input.on_window_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let log_config = LogConfig::from_file("config/log.toml");
|
||||
|
||||
let mut game = TestGame {
|
||||
input: InputState::new("config/input.toml"),
|
||||
input: InputState::new("config/input.toml", &log_config),
|
||||
cam_rotation: Quaternion::one(),
|
||||
cam_position: Vector3::new(0.0, 0.0, -10.0),
|
||||
log_config: LogConfig::from_file("config/log.toml"),
|
||||
log_config: &log_config,
|
||||
};
|
||||
|
||||
let line_count = 30;
|
||||
|
||||
Reference in New Issue
Block a user