2020-07-17 01:47:51 +00:00
|
|
|
use bevy::{app::ScheduleRunnerPlugin, prelude::*};
|
2020-03-30 18:52:33 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2020-04-07 00:03:21 +00:00
|
|
|
// This example disables the default plugins by not registering them during setup.
|
|
|
|
// You can also completely remove rendering / windowing Plugin code from bevy
|
|
|
|
// by making your import look like this in your Cargo.toml
|
|
|
|
//
|
|
|
|
// [dependencies]
|
2020-08-22 16:48:52 +00:00
|
|
|
// bevy = { version = "0.1.3", default-features = false, features = ["headless"] }
|
2020-04-07 00:03:21 +00:00
|
|
|
|
2020-03-30 18:52:33 +00:00
|
|
|
fn main() {
|
2020-04-07 04:32:19 +00:00
|
|
|
// this app runs once
|
2020-03-30 18:52:33 +00:00
|
|
|
App::build()
|
2020-05-01 20:12:47 +00:00
|
|
|
.add_plugin(ScheduleRunnerPlugin::run_once())
|
2020-04-30 20:52:11 +00:00
|
|
|
.add_system(hello_world_system.system())
|
2020-03-30 18:52:33 +00:00
|
|
|
.run();
|
|
|
|
|
2020-04-07 04:32:19 +00:00
|
|
|
// this app loops forever at 60 fps
|
2020-03-30 18:52:33 +00:00
|
|
|
App::build()
|
2020-05-01 20:55:07 +00:00
|
|
|
.add_plugin(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(
|
|
|
|
1.0 / 60.0,
|
|
|
|
)))
|
2020-09-10 19:56:37 +00:00
|
|
|
.add_system(counter.system())
|
2020-03-30 18:52:33 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:52:11 +00:00
|
|
|
fn hello_world_system() {
|
2020-04-30 17:42:22 +00:00
|
|
|
println!("hello world");
|
2020-03-30 18:52:33 +00:00
|
|
|
}
|
2020-05-01 20:55:07 +00:00
|
|
|
|
2020-09-10 19:56:37 +00:00
|
|
|
fn counter(mut state: Local<CounterState>) {
|
|
|
|
if state.count % 60 == 0 {
|
|
|
|
println!("{}", state.count);
|
|
|
|
}
|
|
|
|
state.count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct CounterState {
|
|
|
|
count: u32,
|
|
|
|
}
|