mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 23:24:44 +00:00
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
This commit is contained in:
parent
2974293682
commit
997eae6185
2 changed files with 11 additions and 16 deletions
|
@ -1,13 +1,13 @@
|
||||||
use crate::converter::{convert_axis, convert_button, convert_gamepad_id};
|
use crate::converter::{convert_axis, convert_button, convert_gamepad_id};
|
||||||
use bevy_app::Events;
|
use bevy_app::Events;
|
||||||
use bevy_ecs::world::World;
|
use bevy_ecs::system::{NonSend, NonSendMut, ResMut};
|
||||||
use bevy_input::{gamepad::GamepadEventRaw, prelude::*};
|
use bevy_input::{gamepad::GamepadEventRaw, prelude::*};
|
||||||
use gilrs::{EventType, Gilrs};
|
use gilrs::{EventType, Gilrs};
|
||||||
|
|
||||||
pub fn gilrs_event_startup_system(world: &mut World) {
|
pub fn gilrs_event_startup_system(
|
||||||
let world = world.cell();
|
gilrs: NonSend<Gilrs>,
|
||||||
let gilrs = world.get_non_send::<Gilrs>().unwrap();
|
mut event: ResMut<Events<GamepadEventRaw>>,
|
||||||
let mut event = world.get_resource_mut::<Events<GamepadEventRaw>>().unwrap();
|
) {
|
||||||
for (id, _) in gilrs.gamepads() {
|
for (id, _) in gilrs.gamepads() {
|
||||||
event.send(GamepadEventRaw(
|
event.send(GamepadEventRaw(
|
||||||
convert_gamepad_id(id),
|
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) {
|
pub fn gilrs_event_system(
|
||||||
let world = world.cell();
|
mut gilrs: NonSendMut<Gilrs>,
|
||||||
let mut gilrs = world.get_non_send_mut::<Gilrs>().unwrap();
|
mut event: ResMut<Events<GamepadEventRaw>>,
|
||||||
let mut event = world.get_resource_mut::<Events<GamepadEventRaw>>().unwrap();
|
) {
|
||||||
event.update();
|
|
||||||
while let Some(gilrs_event) = gilrs.next_event() {
|
while let Some(gilrs_event) = gilrs.next_event() {
|
||||||
match gilrs_event.event {
|
match gilrs_event.event {
|
||||||
EventType::Connected => {
|
EventType::Connected => {
|
||||||
|
|
|
@ -2,7 +2,6 @@ mod converter;
|
||||||
mod gilrs_system;
|
mod gilrs_system;
|
||||||
|
|
||||||
use bevy_app::{App, CoreStage, Plugin, StartupStage};
|
use bevy_app::{App, CoreStage, Plugin, StartupStage};
|
||||||
use bevy_ecs::system::IntoExclusiveSystem;
|
|
||||||
use bevy_utils::tracing::error;
|
use bevy_utils::tracing::error;
|
||||||
use gilrs::GilrsBuilder;
|
use gilrs::GilrsBuilder;
|
||||||
use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
|
use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
|
||||||
|
@ -21,12 +20,9 @@ impl Plugin for GilrsPlugin {
|
||||||
app.insert_non_send_resource(gilrs)
|
app.insert_non_send_resource(gilrs)
|
||||||
.add_startup_system_to_stage(
|
.add_startup_system_to_stage(
|
||||||
StartupStage::PreStartup,
|
StartupStage::PreStartup,
|
||||||
gilrs_event_startup_system.exclusive_system(),
|
gilrs_event_startup_system,
|
||||||
)
|
)
|
||||||
.add_system_to_stage(
|
.add_system_to_stage(CoreStage::PreUpdate, gilrs_event_system);
|
||||||
CoreStage::PreUpdate,
|
|
||||||
gilrs_event_system.exclusive_system(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(err) => error!("Failed to start Gilrs. {}", err),
|
Err(err) => error!("Failed to start Gilrs. {}", err),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue