From 997eae61854b362c10810884966ac605121e04d7 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Fri, 8 Oct 2021 00:37:08 +0000 Subject: [PATCH] Remove double Events::update in bevy-gilrs (#2894) # Objective - Remove duplicate `Events::update` call in `gilrs_event_system` (fixes #2893) - See #2893 for context - While there, make the systems no longer exclusive, as that is not required of them ## Solution - Do the change r? @alice-i-cecile --- crates/bevy_gilrs/src/gilrs_system.rs | 19 +++++++++---------- crates/bevy_gilrs/src/lib.rs | 8 ++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/crates/bevy_gilrs/src/gilrs_system.rs b/crates/bevy_gilrs/src/gilrs_system.rs index 4f34370e91..812153304b 100644 --- a/crates/bevy_gilrs/src/gilrs_system.rs +++ b/crates/bevy_gilrs/src/gilrs_system.rs @@ -1,13 +1,13 @@ use crate::converter::{convert_axis, convert_button, convert_gamepad_id}; use bevy_app::Events; -use bevy_ecs::world::World; +use bevy_ecs::system::{NonSend, NonSendMut, ResMut}; use bevy_input::{gamepad::GamepadEventRaw, prelude::*}; use gilrs::{EventType, Gilrs}; -pub fn gilrs_event_startup_system(world: &mut World) { - let world = world.cell(); - let gilrs = world.get_non_send::().unwrap(); - let mut event = world.get_resource_mut::>().unwrap(); +pub fn gilrs_event_startup_system( + gilrs: NonSend, + mut event: ResMut>, +) { for (id, _) in gilrs.gamepads() { event.send(GamepadEventRaw( convert_gamepad_id(id), @@ -16,11 +16,10 @@ pub fn gilrs_event_startup_system(world: &mut World) { } } -pub fn gilrs_event_system(world: &mut World) { - let world = world.cell(); - let mut gilrs = world.get_non_send_mut::().unwrap(); - let mut event = world.get_resource_mut::>().unwrap(); - event.update(); +pub fn gilrs_event_system( + mut gilrs: NonSendMut, + mut event: ResMut>, +) { while let Some(gilrs_event) = gilrs.next_event() { match gilrs_event.event { EventType::Connected => { diff --git a/crates/bevy_gilrs/src/lib.rs b/crates/bevy_gilrs/src/lib.rs index 406b947cc2..3803e259c4 100644 --- a/crates/bevy_gilrs/src/lib.rs +++ b/crates/bevy_gilrs/src/lib.rs @@ -2,7 +2,6 @@ mod converter; mod gilrs_system; use bevy_app::{App, CoreStage, Plugin, StartupStage}; -use bevy_ecs::system::IntoExclusiveSystem; use bevy_utils::tracing::error; use gilrs::GilrsBuilder; use gilrs_system::{gilrs_event_startup_system, gilrs_event_system}; @@ -21,12 +20,9 @@ impl Plugin for GilrsPlugin { app.insert_non_send_resource(gilrs) .add_startup_system_to_stage( StartupStage::PreStartup, - gilrs_event_startup_system.exclusive_system(), + gilrs_event_startup_system, ) - .add_system_to_stage( - CoreStage::PreUpdate, - gilrs_event_system.exclusive_system(), - ); + .add_system_to_stage(CoreStage::PreUpdate, gilrs_event_system); } Err(err) => error!("Failed to start Gilrs. {}", err), }