From 328652f9930940735fc438768a284659da6a36b0 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Sat, 5 Sep 2020 20:51:32 +0200 Subject: [PATCH] Initialize+Run systems when running the app This is required, so Local<> resources get initialized before systems run. --- crates/bevy_app/src/schedule_runner.rs | 4 ++-- examples/app/headless.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/bevy_app/src/schedule_runner.rs b/crates/bevy_app/src/schedule_runner.rs index 68bce06b51f00..d80a174e0f890 100644 --- a/crates/bevy_app/src/schedule_runner.rs +++ b/crates/bevy_app/src/schedule_runner.rs @@ -51,7 +51,7 @@ impl Plugin for ScheduleRunnerPlugin { let mut app_exit_event_reader = EventReader::::default(); match run_mode { RunMode::Once => { - app.schedule.run(&mut app.world, &mut app.resources); + app.update(); } RunMode::Loop { wait } => loop { let start_time = Instant::now(); @@ -62,7 +62,7 @@ impl Plugin for ScheduleRunnerPlugin { } } - app.schedule.run(&mut app.world, &mut app.resources); + app.update(); if let Some(app_exit_events) = app.resources.get_mut::>() { if app_exit_event_reader.latest(&app_exit_events).is_some() { diff --git a/examples/app/headless.rs b/examples/app/headless.rs index 5aaec61c49e71..34a6d3e94b1e6 100644 --- a/examples/app/headless.rs +++ b/examples/app/headless.rs @@ -20,7 +20,7 @@ fn main() { .add_plugin(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64( 1.0 / 60.0, ))) - .add_system(some_other_system.system()) + .add_system(counter.system()) .run(); } @@ -28,4 +28,14 @@ fn hello_world_system() { println!("hello world"); } -fn some_other_system() {} +fn counter(mut state: Local) { + if state.count % 60 == 0 { + println!("{}", state.count); + } + state.count += 1; +} + +#[derive(Default)] +struct CounterState { + count: u32, +}