app: default app runner now runs the schedule once

This commit is contained in:
Carter Anderson 2020-07-22 13:32:17 -07:00
parent 2d829f5a06
commit a4e291d9c8
3 changed files with 23 additions and 7 deletions

View file

@ -1,17 +1,34 @@
use crate::app_builder::AppBuilder; use crate::app_builder::AppBuilder;
use bevy_ecs::{ParallelExecutor, Resources, Schedule, World}; use bevy_ecs::{ParallelExecutor, Resources, Schedule, World};
#[derive(Default)]
pub struct App { pub struct App {
pub world: World, pub world: World,
pub resources: Resources, pub resources: Resources,
pub runner: Option<Box<dyn Fn(App)>>, pub runner: Box<dyn Fn(App)>,
pub schedule: Schedule, pub schedule: Schedule,
pub executor: ParallelExecutor, pub executor: ParallelExecutor,
pub startup_schedule: Schedule, pub startup_schedule: Schedule,
pub startup_executor: ParallelExecutor, 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 { impl App {
pub fn build() -> AppBuilder { pub fn build() -> AppBuilder {
AppBuilder::default() AppBuilder::default()
@ -30,9 +47,9 @@ impl App {
&mut self.world, &mut self.world,
&mut self.resources, &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);
} }
} }

View file

@ -202,7 +202,7 @@ impl AppBuilder {
} }
pub fn set_runner(&mut self, run_fn: impl Fn(App) + 'static) -> &mut Self { 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 self
} }

View file

@ -2,7 +2,6 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins()
.add_system(hello_world_system.system()) .add_system(hello_world_system.system())
.run(); .run();
} }