bevy/examples/wasm/headless_wasm.rs
Nathan Stocks 9871e7e24b
Remove add_default_plugins and add MinimalPlugins for simple "headless" scenarios (#767)
Remove add_default_plugins and add MinimalPlugins for simple "headless" scenarios
2020-11-02 18:38:37 -08:00

41 lines
994 B
Rust

#[cfg(target_arch = "wasm32")]
extern crate console_error_panic_hook;
use bevy::{
app::{ScheduleRunnerPlugin, ScheduleRunnerSettings},
prelude::*,
};
use std::time::Duration;
fn main() {
#[cfg(target_arch = "wasm32")]
{
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init_with_level(log::Level::Debug).expect("cannot initialize console_log");
}
App::build()
.add_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / 60.0,
)))
.add_plugin(ScheduleRunnerPlugin::default())
.add_startup_system(hello_world_system.system())
.add_system(counter.system())
.run();
}
fn hello_world_system() {
log::info!("hello wasm");
}
fn counter(mut state: Local<CounterState>) {
if state.count % 60 == 0 {
log::info!("counter system: {}", state.count);
}
state.count += 1;
}
#[derive(Default)]
struct CounterState {
count: u32,
}