Skip to content

Commit 666590c

Browse files
committed
Use removal events as event
1 parent 77076bc commit 666590c

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

crates/bevy_window/src/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{PrimaryWindow, Window, WindowCloseRequested, WindowClosed, WindowFocus};
1+
use crate::{PrimaryWindow, Window, WindowCloseRequested, WindowFocus};
22

33
use bevy_app::AppExit;
44
use bevy_ecs::prelude::*;

crates/bevy_winit/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Plugin for WinitPlugin {
6969
.with_system(update_cursor_position)
7070
.with_system(update_resize_constraints),
7171
)
72-
.add_system_to_stage(CoreStage::Last, despawn_window);
72+
.add_system_to_stage(CoreStage::PreUpdate, despawn_window);
7373

7474
#[cfg(target_arch = "wasm32")]
7575
app.add_plugin(web_resize::CanvasParentResizePlugin);
@@ -238,6 +238,7 @@ pub fn winit_runner(mut app: App) {
238238
// TODO move all system state fetch up here?
239239
if let Some(app_exit_events) = app.world.get_resource::<Events<AppExit>>() {
240240
if app_exit_event_reader.iter(app_exit_events).last().is_some() {
241+
warn!("exitting");
241242
*control_flow = ControlFlow::Exit;
242243
return;
243244
}

crates/bevy_winit/src/system.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use bevy_ecs::{
22
entity::{Entities, Entity},
33
event::EventWriter,
44
prelude::{Added, Changed, With},
5-
system::{Commands, NonSendMut, Query, RemovedComponents, Res},
5+
removal_detection::RemovedComponent,
6+
system::{Commands, NonSendMut, Query, Res},
67
};
78
use bevy_utils::tracing::{error, info};
89
use bevy_window::{
@@ -62,19 +63,21 @@ pub fn despawn_window(
6263
mut commands: Commands,
6364
entities: &Entities,
6465
primary: Option<Res<PrimaryWindow>>,
65-
closed: RemovedComponents<Window>,
66+
mut closed: RemovedComponent<Window>,
6667
mut close_events: EventWriter<WindowClosed>,
6768
mut winit_windows: NonSendMut<WinitWindows>,
6869
) {
6970
for window in closed.iter() {
71+
info!("closing window: {:?}", window);
7072
winit_windows.remove_window(window);
7173

72-
if entities.contains(window) {
73-
commands.entity(window).despawn();
74-
}
74+
//if entities.contains(window) {
75+
//commands.entity(window).despawn();
76+
//}
7577

7678
if let Some(ref primary) = primary {
7779
if primary.window == window {
80+
info!("removing primary");
7881
commands.remove_resource::<PrimaryWindow>();
7982
}
8083
}

examples/ecs/removal_detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn remove_component(
5151
}
5252
}
5353

54-
fn react_on_removal(removed: RemovedComponents<MyComponent>, mut query: Query<&mut Sprite>) {
54+
fn react_on_removal(mut removed: RemovedComponent<MyComponent>, mut query: Query<&mut Sprite>) {
5555
// `RemovedComponents<T>::iter()` returns an interator with the `Entity`s that had their
5656
// `Component` `T` (in this case `MyComponent`) removed at some point earlier during the frame.
5757
for entity in removed.iter() {

examples/window/multiple_windows.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn main() {
1313
// A window bundle inserted as a resource acts as the descriptor
1414
// for a primary window.
1515
.insert_resource(WindowBundle::default())
16+
.insert_resource(RemovedComponents::default())
1617
.add_startup_system(setup_scene)
1718
.add_startup_system(setup_extra_windows)
1819
.add_system(bevy::window::close_on_esc)
@@ -51,7 +52,7 @@ fn setup_extra_windows(mut commands: Commands) {
5152
.spawn_bundle(WindowBundle {
5253
title: WindowTitle::new("Second window"),
5354
// A window can start minimized.
54-
state: WindowState::Minimized,
55+
//state: WindowState::Minimized,
5556
..Default::default()
5657
})
5758
.id();

0 commit comments

Comments
 (0)