bevy/examples/app/headless.rs
bjorn3 6d6bc2a8b4 Merge AppBuilder into App (#2531)
This is extracted out of eb8f973646476b4a4926ba644a77e2b3a5772159 and includes some additional changes to remove all references to AppBuilder and fix examples that still used App::build() instead of App::new(). In addition I didn't extract the sub app feature as it isn't ready yet.

You can use `git diff --diff-filter=M eb8f973646476b4a4926ba644a77e2b3a5772159` to find all differences in this PR. The `--diff-filtered=M` filters all files added in the original commit but not in this commit away.

Co-Authored-By: Carter Anderson <mcanders1@gmail.com>
2021-07-27 20:21:06 +00:00

44 lines
1.1 KiB
Rust

use bevy::{app::ScheduleRunnerSettings, prelude::*, utils::Duration};
// This example only enables a minimal set of plugins required for bevy to run.
// You can also completely remove rendering / windowing Plugin code from bevy
// by making your import look like this in your Cargo.toml
//
// [dependencies]
// bevy = { version = "*", default-features = false }
// # replace "*" with the most recent version of bevy
fn main() {
// this app runs once
App::new()
.insert_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_system(hello_world_system.system())
.run();
// this app loops forever at 60 fps
App::new()
.insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / 60.0,
)))
.add_plugins(MinimalPlugins)
.add_system(counter.system())
.run();
}
fn hello_world_system() {
println!("hello world");
}
fn counter(mut state: Local<CounterState>) {
if state.count % 60 == 0 {
println!("{}", state.count);
}
state.count += 1;
}
#[derive(Default)]
struct CounterState {
count: u32,
}