2020-10-02 19:24:30 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
2020-09-16 01:05:31 +00:00
|
|
|
extern crate console_error_panic_hook;
|
2020-10-02 19:24:30 +00:00
|
|
|
|
2020-09-16 01:05:31 +00:00
|
|
|
use bevy::{app::ScheduleRunnerPlugin, prelude::*};
|
2020-10-02 19:24:30 +00:00
|
|
|
use std::time::Duration;
|
2020-09-16 01:05:31 +00:00
|
|
|
|
|
|
|
fn main() {
|
2020-10-02 19:24:30 +00:00
|
|
|
#[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");
|
|
|
|
}
|
2020-09-16 01:05:31 +00:00
|
|
|
|
|
|
|
App::build()
|
|
|
|
.add_plugin(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(
|
|
|
|
1.0 / 60.0,
|
|
|
|
)))
|
|
|
|
.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,
|
|
|
|
}
|