Skip to content

Commit

Permalink
Move mega-event dispatch back into winit
Browse files Browse the repository at this point in the history
  • Loading branch information
NthTensor committed Sep 3, 2024
1 parent 69bf0d6 commit 07748d1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 112 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_picking/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//!
//! The order in which interaction events are received is extremely important, and you can read more
//! about it on the docs for the dispatcher system: [`pointer_events`]. This system runs in
//! [`PreUpdate](bevy::app::PreUpdate) in [`Focus`](crate::picking::PickSet::Focus). All pointer-event observers
//! [`PreUpdate`](bevy::app::PreUpdate) in [`Focus`](crate::picking::PickSet::Focus). All pointer-event observers
//! resolve during the sync point between [`pointer_events`] and
//! [`update_interactions`](crate::focus::update_interactions).
//!
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_picking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ impl Plugin for PickingPlugin {
(PickSet::Input, PickSet::PostInput)
.after(bevy_time::TimeSystem)
.ambiguous_with(bevy_asset::handle_internal_asset_events)
.ambiguous_with(bevy_window::forward_window_events)
.after(bevy_ecs::event::EventUpdates)
.chain(),
)
Expand Down
102 changes: 1 addition & 101 deletions crates/bevy_window/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![allow(deprecated)]
use std::path::PathBuf;

use bevy_ecs::event::{Event, EventReader};
use bevy_ecs::system::SystemState;
use bevy_ecs::{entity::Entity, world::World};
use bevy_ecs::{entity::Entity, event::Event};
use bevy_input::{
gestures::*,
keyboard::{KeyboardFocusLost, KeyboardInput},
Expand Down Expand Up @@ -610,101 +608,3 @@ impl From<KeyboardFocusLost> for WindowEvent {
Self::KeyboardFocusLost(e)
}
}

/// Clones events from the unified `WindowEvent` stream into their own event buffers.
pub fn forward_window_events(
world: &mut World,
reader_state: &mut SystemState<EventReader<WindowEvent>>,
) {
let mut reader = reader_state.get_mut(world);
let window_events: Vec<_> = reader.read().cloned().collect();

for winit_event in window_events {
match winit_event.clone() {
WindowEvent::AppLifecycle(e) => {
world.send_event(e);
}
WindowEvent::CursorEntered(e) => {
world.send_event(e);
}
WindowEvent::CursorLeft(e) => {
world.send_event(e);
}
WindowEvent::CursorMoved(e) => {
world.send_event(e);
}
WindowEvent::FileDragAndDrop(e) => {
world.send_event(e);
}
WindowEvent::Ime(e) => {
world.send_event(e);
}
WindowEvent::ReceivedCharacter(e) => {
world.send_event(e);
}
WindowEvent::RequestRedraw(e) => {
world.send_event(e);
}
WindowEvent::WindowBackendScaleFactorChanged(e) => {
world.send_event(e);
}
WindowEvent::WindowCloseRequested(e) => {
world.send_event(e);
}
WindowEvent::WindowCreated(e) => {
world.send_event(e);
}
WindowEvent::WindowDestroyed(e) => {
world.send_event(e);
}
WindowEvent::WindowFocused(e) => {
world.send_event(e);
}
WindowEvent::WindowMoved(e) => {
world.send_event(e);
}
WindowEvent::WindowOccluded(e) => {
world.send_event(e);
}
WindowEvent::WindowResized(e) => {
world.send_event(e);
}
WindowEvent::WindowScaleFactorChanged(e) => {
world.send_event(e);
}
WindowEvent::WindowThemeChanged(e) => {
world.send_event(e);
}
WindowEvent::MouseButtonInput(e) => {
world.send_event(e);
}
WindowEvent::MouseMotion(e) => {
world.send_event(e);
}
WindowEvent::MouseWheel(e) => {
world.send_event(e);
}
WindowEvent::PinchGesture(e) => {
world.send_event(e);
}
WindowEvent::RotationGesture(e) => {
world.send_event(e);
}
WindowEvent::DoubleTapGesture(e) => {
world.send_event(e);
}
WindowEvent::PanGesture(e) => {
world.send_event(e);
}
WindowEvent::TouchInput(e) => {
world.send_event(e);
}
WindowEvent::KeyboardInput(e) => {
world.send_event(e);
}
WindowEvent::KeyboardFocusLost(e) => {
world.send_event(e);
}
}
}
}
5 changes: 0 additions & 5 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use std::sync::{Arc, Mutex};

use bevy_a11y::Focus;
use bevy_ecs::schedule::IntoSystemConfigs;

mod event;
mod monitor;
Expand Down Expand Up @@ -93,10 +92,6 @@ impl Plugin for WindowPlugin {
// User convenience events
#[allow(deprecated)]
app.add_event::<WindowEvent>()
.add_systems(
First,
forward_window_events.after(bevy_ecs::event::event_update_system),
)
.add_event::<WindowResized>()
.add_event::<WindowCreated>()
.add_event::<WindowClosing>()
Expand Down
95 changes: 92 additions & 3 deletions crates/bevy_winit/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use winit::window::WindowId;
use bevy_window::{
AppLifecycle, CursorEntered, CursorLeft, CursorMoved, FileDragAndDrop, Ime, ReceivedCharacter,
RequestRedraw, Window, WindowBackendScaleFactorChanged, WindowCloseRequested, WindowDestroyed,
WindowFocused, WindowMoved, WindowOccluded, WindowResized, WindowScaleFactorChanged,
WindowThemeChanged,
WindowEvent as BevyWindowEvent, WindowFocused, WindowMoved, WindowOccluded, WindowResized,
WindowScaleFactorChanged, WindowThemeChanged,
};
#[cfg(target_os = "android")]
use bevy_window::{PrimaryWindow, RawHandleWrapper};
Expand Down Expand Up @@ -696,8 +696,97 @@ impl<T: Event> WinitAppRunnerState<T> {

let world = self.world_mut();

for winit_event in buffered_events.iter() {
match winit_event.clone() {
BevyWindowEvent::AppLifecycle(e) => {
world.send_event(e);
}
BevyWindowEvent::CursorEntered(e) => {
world.send_event(e);
}
BevyWindowEvent::CursorLeft(e) => {
world.send_event(e);
}
BevyWindowEvent::CursorMoved(e) => {
world.send_event(e);
}
BevyWindowEvent::FileDragAndDrop(e) => {
world.send_event(e);
}
BevyWindowEvent::Ime(e) => {
world.send_event(e);
}
BevyWindowEvent::ReceivedCharacter(e) => {
world.send_event(e);
}
BevyWindowEvent::RequestRedraw(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowBackendScaleFactorChanged(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowCloseRequested(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowCreated(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowDestroyed(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowFocused(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowMoved(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowOccluded(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowResized(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowScaleFactorChanged(e) => {
world.send_event(e);
}
BevyWindowEvent::WindowThemeChanged(e) => {
world.send_event(e);
}
BevyWindowEvent::MouseButtonInput(e) => {
world.send_event(e);
}
BevyWindowEvent::MouseMotion(e) => {
world.send_event(e);
}
BevyWindowEvent::MouseWheel(e) => {
world.send_event(e);
}
BevyWindowEvent::PinchGesture(e) => {
world.send_event(e);
}
BevyWindowEvent::RotationGesture(e) => {
world.send_event(e);
}
BevyWindowEvent::DoubleTapGesture(e) => {
world.send_event(e);
}
BevyWindowEvent::PanGesture(e) => {
world.send_event(e);
}
BevyWindowEvent::TouchInput(e) => {
world.send_event(e);
}
BevyWindowEvent::KeyboardInput(e) => {
world.send_event(e);
}
BevyWindowEvent::KeyboardFocusLost(e) => {
world.send_event(e);
}
}
}

world
.resource_mut::<Events<bevy_window::WindowEvent>>()
.resource_mut::<Events<BevyWindowEvent>>()
.send_batch(buffered_events);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ecs/ambiguity_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
// Over time, we are working to reduce the number: your PR should not increase it.
// If you decrease this by fixing an ambiguity, reduce the number to prevent regressions.
// See https://github.com/bevyengine/bevy/issues/7386 for progress.
48,
47,
"Main app has unexpected ambiguities among the following schedules: \n{:#?}.",
main_app_ambiguities,
);
Expand Down

0 comments on commit 07748d1

Please sign in to comment.