Fix clippy::collapsible_match, collapse it

This commit is contained in:
ice_iix 2021-06-18 15:23:00 -07:00
parent 53a0bc9fb6
commit 728367c59b
1 changed files with 41 additions and 41 deletions

View File

@ -631,53 +631,53 @@ fn handle_window_event<T>(
use winit::event::*; use winit::event::*;
match event { match event {
Event::MainEventsCleared => return true, Event::MainEventsCleared => return true,
Event::DeviceEvent { event, .. } => { Event::DeviceEvent {
if let DeviceEvent::MouseMotion { event: DeviceEvent::MouseMotion {
delta: (xrel, yrel), delta: (xrel, yrel),
} = event },
{ ..
let (rx, ry) = if xrel > 1000.0 || yrel > 1000.0 { } => {
// Heuristic for if we were passed an absolute value instead of relative let (rx, ry) = if xrel > 1000.0 || yrel > 1000.0 {
// Workaround https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM // Heuristic for if we were passed an absolute value instead of relative
// Note SDL2 had a hint to handle this scenario: // Workaround https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
// sdl2::hint::set_with_priority("SDL_MOUSE_RELATIVE_MODE_WARP", "1", &sdl2::hint::Hint::Override); // Note SDL2 had a hint to handle this scenario:
let s = 8000.0 + 0.01; // sdl2::hint::set_with_priority("SDL_MOUSE_RELATIVE_MODE_WARP", "1", &sdl2::hint::Hint::Override);
( let s = 8000.0 + 0.01;
(xrel - game.last_mouse_xrel) / s, (
(yrel - game.last_mouse_yrel) / s, (xrel - game.last_mouse_xrel) / s,
) (yrel - game.last_mouse_yrel) / s,
} else { )
let s = 2000.0 + 0.01; } else {
(xrel / s, yrel / s) let s = 2000.0 + 0.01;
}; (xrel / s, yrel / s)
};
game.last_mouse_xrel = xrel; game.last_mouse_xrel = xrel;
game.last_mouse_yrel = yrel; game.last_mouse_yrel = yrel;
use std::f64::consts::PI; use std::f64::consts::PI;
if game.focused { if game.focused {
window.set_cursor_grab(true).unwrap(); window.set_cursor_grab(true).unwrap();
window.set_cursor_visible(false); window.set_cursor_visible(false);
if let Some(player) = game.server.player { if let Some(player) = game.server.player {
let rotation = game let rotation = game
.server .server
.entities .entities
.get_component_mut(player, game.server.rotation) .get_component_mut(player, game.server.rotation)
.unwrap(); .unwrap();
rotation.yaw -= rx; rotation.yaw -= rx;
rotation.pitch -= ry; rotation.pitch -= ry;
if rotation.pitch < (PI / 2.0) + 0.01 { if rotation.pitch < (PI / 2.0) + 0.01 {
rotation.pitch = (PI / 2.0) + 0.01; rotation.pitch = (PI / 2.0) + 0.01;
} }
if rotation.pitch > (PI / 2.0) * 3.0 - 0.01 { if rotation.pitch > (PI / 2.0) * 3.0 - 0.01 {
rotation.pitch = (PI / 2.0) * 3.0 - 0.01; rotation.pitch = (PI / 2.0) * 3.0 - 0.01;
}
} }
} else {
window.set_cursor_grab(false).unwrap();
window.set_cursor_visible(true);
} }
} else {
window.set_cursor_grab(false).unwrap();
window.set_cursor_visible(true);
} }
} }