| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
use bevy::{app::ScheduleRunnerPlugin, log::LogPlugin, prelude::*}; |
| 14 |
use core::time::Duration; |
| 15 |
|
| 16 |
fn main() { |
| 17 |
if cfg!(feature = "bevy_window") { |
| 18 |
println!("This example is running with the bevy_window feature enabled and will not run headless."); |
| 19 |
println!("Disable the default features and rerun the example to run headless."); |
| 20 |
println!("To do so, run:"); |
| 21 |
println!(); |
| 22 |
println!(" cargo run --example headless --no-default-features --features bevy_log"); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
App::new() |
| 28 |
.add_plugins(DefaultPlugins.set(ScheduleRunnerPlugin::run_once())) |
| 29 |
.add_systems(Update, hello_world_system) |
| 30 |
.run(); |
| 31 |
|
| 32 |
|
| 33 |
App::new() |
| 34 |
.add_plugins( |
| 35 |
DefaultPlugins |
| 36 |
.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64( |
| 37 |
1.0 / 60.0, |
| 38 |
))) |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
.disable::<LogPlugin>(), |
| 43 |
) |
| 44 |
.add_systems(Update, counter) |
| 45 |
.run(); |
| 46 |
} |
| 47 |
|
| 48 |
fn hello_world_system() { |
| 49 |
println!("hello world"); |
| 50 |
} |
| 51 |
|
| 52 |
fn counter(mut state: Local<CounterState>) { |
| 53 |
if state.count.is_multiple_of(60) { |
| 54 |
println!("{}", state.count); |
| 55 |
} |
| 56 |
state.count += 1; |
| 57 |
} |
| 58 |
|
| 59 |
#[derive(Default)] |
| 60 |
struct CounterState { |
| 61 |
count: u32, |
| 62 |
} |