Fix WASM build
This commit is contained in:
parent
972cd26876
commit
ce37ddd0bd
7 changed files with 38 additions and 203 deletions
176
Cargo.lock
generated
176
Cargo.lock
generated
|
@ -1301,121 +1301,6 @@ dependencies = [
|
||||||
"windows",
|
"windows",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bd96bba738454eb373087df6d6891b18009361123fef90930def4978e3837448"
|
|
||||||
dependencies = [
|
|
||||||
"cranelift-codegen",
|
|
||||||
"cranelift-frontend",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-bforest"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "529ffacce2249ac60edba2941672dfedf3d96558b415d0d8083cd007456e0f55"
|
|
||||||
dependencies = [
|
|
||||||
"cranelift-entity",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-codegen"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "427d105f617efc8cb55f8d036a7fded2e227892d8780b4985e5551f8d27c4a92"
|
|
||||||
dependencies = [
|
|
||||||
"cranelift-bforest",
|
|
||||||
"cranelift-codegen-meta",
|
|
||||||
"cranelift-codegen-shared",
|
|
||||||
"cranelift-entity",
|
|
||||||
"cranelift-isle",
|
|
||||||
"gimli",
|
|
||||||
"log",
|
|
||||||
"regalloc2",
|
|
||||||
"smallvec",
|
|
||||||
"target-lexicon",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-codegen-meta"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "551674bed85b838d45358e3eab4f0ffaa6790c70dc08184204b9a54b41cdb7d1"
|
|
||||||
dependencies = [
|
|
||||||
"cranelift-codegen-shared",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-codegen-shared"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2b3a63ae57498c3eb495360944a33571754241e15e47e3bcae6082f40fec5866"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-entity"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "11aa8aa624c72cc1c94ea3d0739fa61248260b5b14d3646f51593a88d67f3e6e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-frontend"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "544ee8f4d1c9559c9aa6d46e7aaeac4a13856d620561094f35527356c7d21bd0"
|
|
||||||
dependencies = [
|
|
||||||
"cranelift-codegen",
|
|
||||||
"log",
|
|
||||||
"smallvec",
|
|
||||||
"target-lexicon",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-isle"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ed16b14363d929b8c37e3c557d0a7396791b383ecc302141643c054343170aad"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-jit"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0308e7418208639fb96c1a3dc04955fa41c4bc92dfce9106635185f71d5caf46"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"cranelift-codegen",
|
|
||||||
"cranelift-entity",
|
|
||||||
"cranelift-module",
|
|
||||||
"cranelift-native",
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
"region",
|
|
||||||
"target-lexicon",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-module"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "76979aac10dbcf0c222cd5902565bc93597ac30bbe9d879a2aa5f2402d1561f2"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"cranelift-codegen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cranelift-native"
|
|
||||||
version = "0.86.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "51617cf8744634f2ed3c989c3c40cd6444f63377c6d994adab0d85807f3eb682"
|
|
||||||
dependencies = [
|
|
||||||
"cranelift-codegen",
|
|
||||||
"libc",
|
|
||||||
"target-lexicon",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -1854,15 +1739,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gimli"
|
|
||||||
version = "0.26.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glam"
|
name = "glam"
|
||||||
version = "0.21.3"
|
version = "0.21.3"
|
||||||
|
@ -2058,7 +1934,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"synfx-dsp",
|
"synfx-dsp",
|
||||||
"synfx-dsp-jit",
|
|
||||||
"triple_buffer",
|
"triple_buffer",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3189,18 +3064,6 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regalloc2"
|
|
||||||
version = "0.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779"
|
|
||||||
dependencies = [
|
|
||||||
"fxhash",
|
|
||||||
"log",
|
|
||||||
"slice-group-by",
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
|
@ -3227,18 +3090,6 @@ version = "0.6.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "region"
|
|
||||||
version = "2.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"libc",
|
|
||||||
"mach",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "renderdoc-sys"
|
name = "renderdoc-sys"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
@ -3402,12 +3253,6 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "slice-group-by"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slotmap"
|
name = "slotmap"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
|
@ -3491,21 +3336,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "synfx-dsp-jit"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "git+https://github.com/WeirdConstructor/synfx-dsp-jit#f199ec697292ed59e92976d7404d6988e0a8d6b0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"cranelift",
|
|
||||||
"cranelift-codegen",
|
|
||||||
"cranelift-jit",
|
|
||||||
"cranelift-module",
|
|
||||||
"cranelift-native",
|
|
||||||
"ringbuf",
|
|
||||||
"synfx-dsp",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "taffy"
|
name = "taffy"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -3519,12 +3349,6 @@ dependencies = [
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "target-lexicon"
|
|
||||||
version = "0.12.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "termcolor"
|
name = "termcolor"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -9,12 +9,16 @@ edition = "2021"
|
||||||
bevy = "0.8.0"
|
bevy = "0.8.0"
|
||||||
bevy-inspector-egui = "0.12.1"
|
bevy-inspector-egui = "0.12.1"
|
||||||
bevy_rapier2d = "0.16.2"
|
bevy_rapier2d = "0.16.2"
|
||||||
cpal = "0.14.0"
|
|
||||||
crossbeam-channel = "0.5.6"
|
crossbeam-channel = "0.5.6"
|
||||||
hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP" }
|
|
||||||
ticktock = "0.8.0"
|
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rand_distr = "0.4.3"
|
rand_distr = "0.4.3"
|
||||||
|
|
||||||
|
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
|
||||||
|
cpal = "0.14.0"
|
||||||
|
hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP", default-features = false }
|
||||||
|
ticktock = "0.8.0"
|
||||||
|
|
||||||
|
[target."cfg(target_arch = \"wasm32\")".dependencies]
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
|
@ -24,6 +24,8 @@ cargo build --release
|
||||||
|
|
||||||
### WASM
|
### WASM
|
||||||
|
|
||||||
|
**Audio does not work in WASM!**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
rustup target add wasm32-unknown-unknown
|
rustup target add wasm32-unknown-unknown
|
||||||
cargo install wasm-bindgen-cli
|
cargo install wasm-bindgen-cli
|
||||||
|
|
14
src/audio.rs
14
src/audio.rs
|
@ -1,23 +1,25 @@
|
||||||
// https://github.com/WeirdConstructor/HexoDSP/blob/master/examples/cpal_demo_node_api.rs
|
// https://github.com/WeirdConstructor/HexoDSP/blob/master/examples/cpal_demo_node_api.rs
|
||||||
|
|
||||||
|
use crate::game::AudioMsg;
|
||||||
|
|
||||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
use crossbeam_channel::Receiver;
|
use crossbeam_channel::Receiver;
|
||||||
use hexodsp::{matrix_repr::MatrixRepr, *};
|
use hexodsp::{matrix_repr::MatrixRepr, *};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use ticktock::Clock;
|
use ticktock::Clock;
|
||||||
|
|
||||||
pub enum AudioMsg {
|
|
||||||
Color([f32; 3]),
|
|
||||||
Jump,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn setup(event_channel: Receiver<AudioMsg>) {
|
pub fn setup(event_channel: Receiver<AudioMsg>) {
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
let matrix_repr: MatrixRepr = {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
std::fs::File::open("assets/init.hxy")
|
std::fs::File::open("assets/init.hxy")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read_to_string(&mut buf)
|
.read_to_string(&mut buf)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let matrix_repr: MatrixRepr = MatrixRepr::deserialize(&buf).unwrap();
|
MatrixRepr::deserialize(&buf).unwrap()
|
||||||
|
};
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
let matrix_repr: MatrixRepr = MatrixRepr::deserialize(include_str!("../assets/init.hxy")).unwrap();
|
||||||
|
|
||||||
let (node_conf, node_exec) = new_node_engine();
|
let (node_conf, node_exec) = new_node_engine();
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#![allow(clippy::precedence)]
|
#![allow(clippy::precedence)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
pub use crate::audio::AudioMsg;
|
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
@ -13,6 +11,11 @@ use bevy::{
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
|
pub enum AudioMsg {
|
||||||
|
Color([f32; 3]),
|
||||||
|
Jump,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
||||||
pub struct LevelId(pub u32);
|
pub struct LevelId(pub u32);
|
||||||
|
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -1,14 +1,11 @@
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod audio;
|
mod audio;
|
||||||
mod game;
|
mod game;
|
||||||
mod levels;
|
mod levels;
|
||||||
mod menu;
|
mod menu;
|
||||||
mod particle_effect;
|
mod particle_effect;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
|
||||||
core_pipeline::clear_color::ClearColorConfig,
|
|
||||||
prelude::*,
|
|
||||||
render::settings::{WgpuFeatures, WgpuSettings},
|
|
||||||
};
|
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
@ -19,16 +16,13 @@ enum AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (audio_event_sender, audio_event_receiver) = crossbeam_channel::bounded(512);
|
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));
|
std::thread::spawn(move || audio::setup(audio_event_receiver));
|
||||||
|
|
||||||
let mut options = WgpuSettings::default();
|
|
||||||
options
|
|
||||||
.features
|
|
||||||
.set(WgpuFeatures::VERTEX_WRITABLE_STORAGE, true);
|
|
||||||
App::new()
|
App::new()
|
||||||
.insert_resource(options)
|
|
||||||
.insert_resource(audio_event_sender)
|
.insert_resource(audio_event_sender)
|
||||||
.add_state(AppState::Menu)
|
.add_state(AppState::Menu)
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
|
@ -43,6 +37,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
|
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
|
||||||
commands.insert_resource(font);
|
commands.insert_resource(font);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,10 @@ use bevy::{prelude::*, sprite::Mesh2dHandle};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand_distr::{Distribution, UnitCircle};
|
use rand_distr::{Distribution, UnitCircle};
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub const POOL_COUNT: usize = 100;
|
pub const POOL_COUNT: usize = 100;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub const POOL_COUNT: usize = 50;
|
||||||
|
|
||||||
pub const MIN_VELOCITY: f32 = 10.0;
|
pub const MIN_VELOCITY: f32 = 10.0;
|
||||||
pub const MAX_VELOCITY: f32 = 100.0;
|
pub const MAX_VELOCITY: f32 = 100.0;
|
||||||
|
|
Loading…
Reference in a new issue