mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
app: default app runner now runs the schedule once
This commit is contained in:
parent
2d829f5a06
commit
a4e291d9c8
3 changed files with 23 additions and 7 deletions
|
@ -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<Box<dyn Fn(App)>>,
|
||||
pub runner: Box<dyn Fn(App)>,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use bevy::prelude::*;
|
|||
|
||||
fn main() {
|
||||
App::build()
|
||||
.add_default_plugins()
|
||||
.add_system(hello_world_system.system())
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue