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 2 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
20 changes: 10 additions & 10 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ pub struct Gamepads {
}

impl Gamepads {
/// Returns `true` if the `gamepad` is connected.
pub fn contains(&self, gamepad: &Gamepad) -> bool {
self.gamepads.contains(gamepad)
/// Returns true if [`Gamepads`] contains a [`Gamepad`].
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
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()
/// Iterates over registered [`Gamepad`]s
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
pub fn iter(&self) -> impl Iterator<Item = Gamepad> + '_ {
self.gamepads.iter().copied()
}

/// Registers the `gamepad` marking it as connected.
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
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.
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
fn deregister(&mut self, gamepad: Gamepad) {
self.gamepads.remove(&gamepad);
}
}

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