Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Gamepad type is Copy; do not require / return references to it in Gamepads API #5296

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ pub struct Gamepads {

impl Gamepads {
/// Returns `true` if the `gamepad` is connected.
pub fn contains(&self, gamepad: &Gamepad) -> bool {
self.gamepads.contains(gamepad)
pub fn contains(&self, gamepad: Gamepad) -> bool {
self.gamepads.contains(&gamepad)
}

/// An iterator visiting all connected [`Gamepad`]s in arbitrary order.
pub fn iter(&self) -> impl Iterator<Item = &Gamepad> + '_ {
self.gamepads.iter()
/// Returns an iterator over registered [`Gamepad`]s in an arbitrary order.
pub fn iter(&self) -> impl Iterator<Item = Gamepad> + '_ {
self.gamepads.iter().copied()
}

/// Registers the `gamepad` marking it as connected.
/// Registers the `gamepad`, marking it as connected.
fn register(&mut self, gamepad: Gamepad) {
self.gamepads.insert(gamepad);
}

/// Deregisters the `gamepad` marking it as disconnected.
fn deregister(&mut self, gamepad: &Gamepad) {
self.gamepads.remove(gamepad);
/// Deregisters the `gamepad`, marking it as disconnected.
fn deregister(&mut self, gamepad: Gamepad) {
self.gamepads.remove(&gamepad);
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ impl GamepadEvent {
/// button_inputs: ResMut<Input<GamepadButton>>,
/// ) {
/// let gamepad = gamepads.iter().next().unwrap();
/// let gamepad_button= GamepadButton::new(*gamepad, GamepadButtonType::South);
/// let gamepad_button= GamepadButton::new(gamepad, GamepadButtonType::South);
///
/// my_resource.0 = button_inputs.pressed(gamepad_button);
/// }
Expand Down Expand Up @@ -673,7 +673,7 @@ pub fn gamepad_connection_system(
info!("{:?} Connected", event.gamepad);
}
GamepadEventType::Disconnected => {
gamepads.deregister(&event.gamepad);
gamepads.deregister(event.gamepad);
info!("{:?} Disconnected", event.gamepad);
}
_ => (),
Expand Down
2 changes: 1 addition & 1 deletion examples/input/gamepad_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn gamepad_system(
button_axes: Res<Axis<GamepadButton>>,
axes: Res<Axis<GamepadAxis>>,
) {
for gamepad in gamepads.iter().cloned() {
for gamepad in gamepads.iter() {
if button_inputs.just_pressed(GamepadButton::new(gamepad, GamepadButtonType::South)) {
info!("{:?} just pressed South", gamepad);
} else if button_inputs.just_released(GamepadButton::new(gamepad, GamepadButtonType::South))
Expand Down