Revert App::run() behavior/Remove winit specific code from bevy_app (#10389)

# Objective
The way `bevy_app` works was changed unnecessarily in #9826 whose
changes should have been specific to `bevy_winit`.
I'm somewhat disappointed that happened and we can see in
https://github.com/bevyengine/bevy/pull/10195 that it made things more
complicated.

Even worse, in #10385 it's clear that this breaks the clean abstraction
over another engine someone built with Bevy!

Fixes #10385.

## Solution

- Move the changes made to `bevy_app` in #9826 to `bevy_winit`
- Revert the changes to `ScheduleRunnerPlugin` and the `run_once` runner
in #10195 as they're no longer necessary.

While this code is breaking relative to `0.12.0`, it reverts the
behavior of `bevy_app` back to how it was in `0.11`.
Due to the nature of the breakage relative to `0.11` I hope this will be
considered for `0.12.1`.
This commit is contained in:
irate 2023-11-16 22:50:17 +01:00 committed by GitHub
parent efc7dc0859
commit bc9e159b26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 26 deletions

View file

@ -309,14 +309,6 @@ impl App {
panic!("App::run() was called from within Plugin::build(), which is not allowed."); panic!("App::run() was called from within Plugin::build(), which is not allowed.");
} }
if app.plugins_state() == PluginsState::Ready {
// If we're already ready, we finish up now and advance one frame.
// This prevents black frames during the launch transition on iOS.
app.finish();
app.cleanup();
app.update();
}
let runner = std::mem::replace(&mut app.runner, Box::new(run_once)); let runner = std::mem::replace(&mut app.runner, Box::new(run_once));
(runner)(app); (runner)(app);
} }
@ -986,20 +978,14 @@ impl App {
} }
fn run_once(mut app: App) { fn run_once(mut app: App) {
let plugins_state = app.plugins_state(); while app.plugins_state() == PluginsState::Adding {
if plugins_state != PluginsState::Cleaned { #[cfg(not(target_arch = "wasm32"))]
while app.plugins_state() == PluginsState::Adding { bevy_tasks::tick_global_task_pools_on_main_thread();
#[cfg(not(target_arch = "wasm32"))]
bevy_tasks::tick_global_task_pools_on_main_thread();
}
app.finish();
app.cleanup();
} }
app.finish();
app.cleanup();
// if plugins where cleaned before the runner start, an update already ran app.update();
if plugins_state != PluginsState::Cleaned {
app.update();
}
} }
/// An event that indicates the [`App`] should exit. This will fully exit the app process at the /// An event that indicates the [`App`] should exit. This will fully exit the app process at the

View file

@ -84,12 +84,7 @@ impl Plugin for ScheduleRunnerPlugin {
let mut app_exit_event_reader = ManualEventReader::<AppExit>::default(); let mut app_exit_event_reader = ManualEventReader::<AppExit>::default();
match run_mode { match run_mode {
RunMode::Once => { RunMode::Once => app.update(),
// if plugins where cleaned before the runner start, an update already ran
if plugins_state != PluginsState::Cleaned {
app.update();
}
}
RunMode::Loop { wait } => { RunMode::Loop { wait } => {
let mut tick = move |app: &mut App, let mut tick = move |app: &mut App,
wait: Option<Duration>| wait: Option<Duration>|

View file

@ -349,6 +349,14 @@ impl Default for WinitAppRunnerState {
/// Overriding the app's [runner](bevy_app::App::runner) while using `WinitPlugin` will bypass the /// Overriding the app's [runner](bevy_app::App::runner) while using `WinitPlugin` will bypass the
/// `EventLoop`. /// `EventLoop`.
pub fn winit_runner(mut app: App) { pub fn winit_runner(mut app: App) {
if app.plugins_state() == PluginsState::Ready {
// If we're already ready, we finish up now and advance one frame.
// This prevents black frames during the launch transition on iOS.
app.finish();
app.cleanup();
app.update();
}
let mut event_loop = app let mut event_loop = app
.world .world
.remove_non_send_resource::<EventLoop<()>>() .remove_non_send_resource::<EventLoop<()>>()