Fix WASM build
This commit is contained in:
parent
972cd26876
commit
ce37ddd0bd
7 changed files with 38 additions and 203 deletions
24
src/audio.rs
24
src/audio.rs
|
|
@ -1,23 +1,25 @@
|
|||
// https://github.com/WeirdConstructor/HexoDSP/blob/master/examples/cpal_demo_node_api.rs
|
||||
|
||||
use crate::game::AudioMsg;
|
||||
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use crossbeam_channel::Receiver;
|
||||
use hexodsp::{matrix_repr::MatrixRepr, *};
|
||||
use std::io::Read;
|
||||
use ticktock::Clock;
|
||||
|
||||
pub enum AudioMsg {
|
||||
Color([f32; 3]),
|
||||
Jump,
|
||||
}
|
||||
|
||||
pub fn setup(event_channel: Receiver<AudioMsg>) {
|
||||
let mut buf = String::new();
|
||||
std::fs::File::open("assets/init.hxy")
|
||||
.unwrap()
|
||||
.read_to_string(&mut buf)
|
||||
.unwrap();
|
||||
let matrix_repr: MatrixRepr = MatrixRepr::deserialize(&buf).unwrap();
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let matrix_repr: MatrixRepr = {
|
||||
let mut buf = String::new();
|
||||
std::fs::File::open("assets/init.hxy")
|
||||
.unwrap()
|
||||
.read_to_string(&mut 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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#![allow(clippy::precedence)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
pub use crate::audio::AudioMsg;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
use bevy::{
|
||||
|
|
@ -13,6 +11,11 @@ use bevy::{
|
|||
use bevy_rapier2d::prelude::*;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
pub enum AudioMsg {
|
||||
Color([f32; 3]),
|
||||
Jump,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
||||
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 game;
|
||||
mod levels;
|
||||
mod menu;
|
||||
mod particle_effect;
|
||||
|
||||
use bevy::{
|
||||
core_pipeline::clear_color::ClearColorConfig,
|
||||
prelude::*,
|
||||
render::settings::{WgpuFeatures, WgpuSettings},
|
||||
};
|
||||
use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
|
|
@ -19,16 +16,13 @@ enum AppState {
|
|||
}
|
||||
|
||||
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));
|
||||
|
||||
let mut options = WgpuSettings::default();
|
||||
options
|
||||
.features
|
||||
.set(WgpuFeatures::VERTEX_WRITABLE_STORAGE, true);
|
||||
App::new()
|
||||
.insert_resource(options)
|
||||
.insert_resource(audio_event_sender)
|
||||
.add_state(AppState::Menu)
|
||||
.add_plugins(DefaultPlugins)
|
||||
|
|
@ -43,6 +37,9 @@ fn main() {
|
|||
}
|
||||
|
||||
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");
|
||||
commands.insert_resource(font);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ use bevy::{prelude::*, sprite::Mesh2dHandle};
|
|||
use rand::Rng;
|
||||
use rand_distr::{Distribution, UnitCircle};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
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 MAX_VELOCITY: f32 = 100.0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue