From aaaa15ff093dbfe3587f00842e2340df7cf30235 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Sun, 18 Oct 2020 22:45:50 +0530 Subject: [PATCH] Changed parameter of get and remove of Axis from &T to T This makes Axis more analogous to Input --- crates/bevy_input/src/axis.rs | 8 ++++---- crates/bevy_input/src/gamepad.rs | 8 ++++---- examples/input/gamepad_input.rs | 11 ++++------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/bevy_input/src/axis.rs b/crates/bevy_input/src/axis.rs index df1ff289d62c1b..e1863969e8926a 100644 --- a/crates/bevy_input/src/axis.rs +++ b/crates/bevy_input/src/axis.rs @@ -24,11 +24,11 @@ where self.axis_data.insert(axis, value) } - pub fn get(&self, axis: &T) -> Option { - self.axis_data.get(axis).copied() + pub fn get(&self, axis: T) -> Option { + self.axis_data.get(&axis).copied() } - pub fn remove(&mut self, axis: &T) -> Option { - self.axis_data.remove(axis) + pub fn remove(&mut self, axis: T) -> Option { + self.axis_data.remove(&axis) } } diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index b00e5cad21d0ac..8bfa00a9735091 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -226,24 +226,24 @@ pub fn gamepad_event_system( for button_type in ALL_BUTTON_TYPES.iter() { let gamepad_button = GamepadButton(*gamepad, *button_type); button.reset(gamepad_button); - button_axis.remove(&gamepad_button); + button_axis.remove(gamepad_button); } for axis_type in ALL_AXIS_TYPES.iter() { - axis.remove(&GamepadAxis(*gamepad, *axis_type)); + axis.remove(GamepadAxis(*gamepad, *axis_type)); } } GamepadEventType::AxisChanged(axis_type, value) => { let gamepad_axis = GamepadAxis(*gamepad, *axis_type); let value = properties .get_axis_properties(gamepad_axis) - .filter(*value, axis.get(&gamepad_axis)); + .filter(*value, axis.get(gamepad_axis)); axis.set(gamepad_axis, value); } GamepadEventType::ButtonChanged(button_type, value) => { let gamepad_button = GamepadButton(*gamepad, *button_type); let filtered_value = properties .get_button_axis_properties(gamepad_button) - .filter(*value, button_axis.get(&gamepad_button)); + .filter(*value, button_axis.get(gamepad_button)); button_axis.set(gamepad_button, filtered_value); let button_property = properties.get_button_properties(gamepad_button); diff --git a/examples/input/gamepad_input.rs b/examples/input/gamepad_input.rs index dc871efa46e865..1c6e29b74ee521 100644 --- a/examples/input/gamepad_input.rs +++ b/examples/input/gamepad_input.rs @@ -77,11 +77,8 @@ fn button_system( } else if inputs.just_released(GamepadButton(*gamepad, *button_type)) { println!("{:?} Released", gamepad_button); } - if let Some(value) = button_axes.get(gamepad_button) { - if !approx_eq( - data.button.get(&gamepad_button).copied().unwrap_or(0.0), - value, - ) { + if let Some(value) = button_axes.get(&gamepad_button) { + if data.button.get(&gamepad_button).copied().unwrap_or(0.0) != value { data.button.insert(gamepad_button, value); println!("{:?} is {}", gamepad_button, value); } @@ -104,8 +101,8 @@ fn axis_system(lobby: Res, axes: Res>, mut data: ResMut for gamepad in lobby.gamepad.iter() { for axis_type in axis_types.iter() { let gamepad_axis = GamepadAxis(*gamepad, *axis_type); - if let Some(value) = axes.get(gamepad_axis) { - if !approx_eq(data.axis.get(&gamepad_axis).copied().unwrap_or(0.0), value) { + if let Some(value) = axes.get(&gamepad_axis) { + if data.axis.get(&gamepad_axis).copied().unwrap_or(0.0) != value { data.axis.insert(gamepad_axis, value); println!("{:?} is {}", gamepad_axis, value); }