Skip to content

Commit 8df90d3

Browse files
aevyriemockersf
andcommitted
Review feedback: use captured var instead of Res<>
Co-authored-by: François <[email protected]>
1 parent c259331 commit 8df90d3

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

crates/bevy_winit/src/lib.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub struct WinitPlugin;
4040
impl Plugin for WinitPlugin {
4141
fn build(&self, app: &mut App) {
4242
app.init_non_send_resource::<WinitWindows>()
43-
.init_resource::<WinitPersistentState>()
4443
.init_resource::<WinitConfig>()
4544
.set_runner(winit_runner)
4645
.add_system_to_stage(CoreStage::PostUpdate, change_window.exclusive_system());
@@ -265,6 +264,7 @@ pub fn winit_runner_with(mut app: App) {
265264
let mut create_window_event_reader = ManualEventReader::<CreateWindow>::default();
266265
let mut app_exit_event_reader = ManualEventReader::<AppExit>::default();
267266
let mut redraw_event_reader = ManualEventReader::<RequestRedraw>::default();
267+
let mut winit_state = WinitPersistentState::default();
268268
app.world
269269
.insert_non_send_resource(event_loop.create_proxy());
270270

@@ -276,7 +276,6 @@ pub fn winit_runner_with(mut app: App) {
276276
control_flow: &mut ControlFlow| {
277277
match event {
278278
event::Event::NewEvents(start) => {
279-
let winit_state = app.world.resource::<WinitPersistentState>();
280279
let winit_config = app.world.resource::<WinitConfig>();
281280
let windows = app.world.resource::<Windows>();
282281
let focused = windows.iter().any(|w| w.is_focused());
@@ -293,8 +292,7 @@ pub fn winit_runner_with(mut app: App) {
293292
now.duration_since(winit_state.last_update) >= *max_wait
294293
}
295294
};
296-
let mut winit_state = app.world.resource_mut::<WinitPersistentState>();
297-
// The low_power_event state must be reset at the start of every frame.
295+
// The low_power_event state and timeout must be reset at the start of every frame.
298296
winit_state.low_power_event = false;
299297
winit_state.timeout_reached = auto_timeout_reached || manual_timeout_reached;
300298
}
@@ -323,11 +321,7 @@ pub fn winit_runner_with(mut app: App) {
323321
warn!("Skipped event for unknown Window Id {:?}", winit_window_id);
324322
return;
325323
};
326-
327-
world
328-
.get_resource_mut::<WinitPersistentState>()
329-
.unwrap()
330-
.low_power_event = true;
324+
winit_state.low_power_event = true;
331325

332326
match event {
333327
WindowEvent::Resized(size) => {
@@ -538,18 +532,17 @@ pub fn winit_runner_with(mut app: App) {
538532
});
539533
}
540534
event::Event::Suspended => {
541-
app.world.resource_mut::<WinitPersistentState>().active = false;
535+
winit_state.active = false;
542536
}
543537
event::Event::Resumed => {
544-
app.world.resource_mut::<WinitPersistentState>().active = true;
538+
winit_state.active = true;
545539
}
546540
event::Event::MainEventsCleared => {
547541
handle_create_window_events(
548542
&mut app.world,
549543
event_loop,
550544
&mut create_window_event_reader,
551545
);
552-
let winit_state = app.world.resource::<WinitPersistentState>();
553546
let winit_config = app.world.resource::<WinitConfig>();
554547
let update = if winit_state.active {
555548
let windows = app.world.resource::<Windows>();
@@ -566,7 +559,7 @@ pub fn winit_runner_with(mut app: App) {
566559
false
567560
};
568561
if update {
569-
app.world.resource_mut::<WinitPersistentState>().last_update = Instant::now();
562+
winit_state.last_update = Instant::now();
570563
app.update();
571564
}
572565
}
@@ -599,9 +592,7 @@ pub fn winit_runner_with(mut app: App) {
599592
*control_flow = ControlFlow::Exit;
600593
}
601594
}
602-
app.world
603-
.resource_mut::<WinitPersistentState>()
604-
.redraw_request_sent = redraw;
595+
winit_state.redraw_request_sent = redraw;
605596
}
606597
_ => (),
607598
}

0 commit comments

Comments
 (0)