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] - Remove double Events::update in bevy-gilrs #2894

Closed
wants to merge 2 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
19 changes: 9 additions & 10 deletions crates/bevy_gilrs/src/gilrs_system.rs
Original file line number Diff line number Diff line change
@@ -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::<Gilrs>().unwrap();
let mut event = world.get_resource_mut::<Events<GamepadEventRaw>>().unwrap();
pub fn gilrs_event_startup_system(
gilrs: NonSend<Gilrs>,
mut event: ResMut<Events<GamepadEventRaw>>,
) {
for (id, _) in gilrs.gamepads() {
event.send(GamepadEventRaw(
convert_gamepad_id(id),
Expand All @@ -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::<Gilrs>().unwrap();
let mut event = world.get_resource_mut::<Events<GamepadEventRaw>>().unwrap();
event.update();
pub fn gilrs_event_system(
mut gilrs: NonSendMut<Gilrs>,
mut event: ResMut<Events<GamepadEventRaw>>,
) {
while let Some(gilrs_event) = gilrs.next_event() {
match gilrs_event.event {
EventType::Connected => {
Expand Down
8 changes: 2 additions & 6 deletions crates/bevy_gilrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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),
}
Expand Down