wasm thread

This commit is contained in:
Nixon 2022-08-26 18:38:52 +08:00
commit 61cb0ce6b4
5 changed files with 131 additions and 8 deletions

View file

@ -13,6 +13,11 @@ use bevy::{
use bevy_common_assets::json::JsonAssetPlugin;
use bevy_rapier2d::prelude::*;
#[cfg(not(target_arch = "wasm32"))]
use std::thread;
#[cfg(target_arch = "wasm32")]
use wasm_thread as thread;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum AppState {
Menu,
@ -20,12 +25,23 @@ enum AppState {
Win,
}
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen(start)] pub fn dummy_main() {}
#[wasm_bindgen]
pub fn run() {
main();
}
fn main() {
let (audio_event_sender, audio_event_receiver) =
crossbeam_channel::bounded::<game::AudioMsg>(512);
#[cfg(not(target_arch = "wasm32"))]
std::thread::spawn(move || audio::setup(audio_event_receiver));
thread::spawn(move || audio::setup(audio_event_receiver));
thread::spawn(|| {/* ... */});
#[cfg(not(target_arch = "wasm32"))]
let first_level = game::LevelId(