diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index fc20912964..1b3e4ef678 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -1,17 +1,34 @@ use crate::app_builder::AppBuilder; use bevy_ecs::{ParallelExecutor, Resources, Schedule, World}; -#[derive(Default)] pub struct App { pub world: World, pub resources: Resources, - pub runner: Option>, + pub runner: Box, pub schedule: Schedule, pub executor: ParallelExecutor, pub startup_schedule: Schedule, pub startup_executor: ParallelExecutor, } +impl Default for App { + fn default() -> Self { + Self { + world: Default::default(), + resources: Default::default(), + schedule: Default::default(), + executor: Default::default(), + startup_schedule: Default::default(), + startup_executor: Default::default(), + runner: Box::new(run_once), + } + } +} + +fn run_once(mut app: App) { + app.update(); +} + impl App { pub fn build() -> AppBuilder { AppBuilder::default() @@ -30,9 +47,9 @@ impl App { &mut self.world, &mut self.resources, ); - if let Some(run) = self.runner.take() { - run(self) - } + + let runner = std::mem::replace(&mut self.runner, Box::new(run_once)); + (runner)(self); } } diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index 1979f5efda..94c3078220 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -202,7 +202,7 @@ impl AppBuilder { } pub fn set_runner(&mut self, run_fn: impl Fn(App) + 'static) -> &mut Self { - self.app.runner = Some(Box::new(run_fn)); + self.app.runner = Box::new(run_fn); self } diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 788bf70f45..c90ea0ce7d 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -2,7 +2,6 @@ use bevy::prelude::*; fn main() { App::build() - .add_default_plugins() .add_system(hello_world_system.system()) .run(); }