Compare commits

..

No commits in common. "ce37ddd0bdae2aa1698cb03cf8404e3dac7bd2f3" and "6809a30faa3b88ffc8efd8ee67f1fa57d9f71cd2" have entirely different histories.

7 changed files with 223 additions and 52 deletions

176
Cargo.lock generated
View file

@ -1301,6 +1301,121 @@ 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"
@ -1739,6 +1854,15 @@ 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"
@ -1934,6 +2058,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"synfx-dsp", "synfx-dsp",
"synfx-dsp-jit",
"triple_buffer", "triple_buffer",
] ]
@ -3064,6 +3189,18 @@ 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"
@ -3090,6 +3227,18 @@ 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"
@ -3253,6 +3402,12 @@ 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"
@ -3336,6 +3491,21 @@ 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"
@ -3349,6 +3519,12 @@ 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"

View file

@ -9,16 +9,12 @@ 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

View file

@ -24,8 +24,6 @@ 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

View file

@ -1,25 +1,23 @@
// 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();
MatrixRepr::deserialize(&buf).unwrap() let matrix_repr: MatrixRepr = 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();

View file

@ -1,6 +1,8 @@
#![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::{
@ -11,11 +13,6 @@ 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);
@ -116,11 +113,9 @@ pub fn spawn_character(
selected_character_id: &mut Mut<SelectedCharacterId>, selected_character_id: &mut Mut<SelectedCharacterId>,
character_id_list: &mut Mut<CharacterIdList>, character_id_list: &mut Mut<CharacterIdList>,
audio: &Res<crossbeam_channel::Sender<AudioMsg>>, audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
mut transform: Transform, transform: Transform,
color: Color, color: Color,
) { ) {
transform.translation.z = transform.translation.z.max(1.0);
let character_id = CharacterId( let character_id = CharacterId(
character_id_list character_id_list
.0 .0
@ -308,13 +303,11 @@ fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
} }
fn move_camera( fn move_camera(
mut camera_query: Query<(&Camera, &mut Transform)>, mut camera_query: Query<(&Camera, &mut Transform, &GlobalTransform)>,
characters: Query<(&CharacterId, &Transform), Without<Camera>>, characters: Query<(&CharacterId, &Transform), Without<Camera>>,
level_query: Query<&SelectedCharacterId>, level_query: Query<&SelectedCharacterId>,
time: Res<Time>,
) { ) {
const MARGIN: f32 = 300.0; const MARGIN: f32 = 128.0;
const FOLLOW_SPEED: f32 = std::f32::consts::PI;
if let Ok(selected_character_id) = level_query.get_single() { if let Ok(selected_character_id) = level_query.get_single() {
if let Some(selected_character_id) = &selected_character_id.0 { if let Some(selected_character_id) = &selected_character_id.0 {
@ -322,15 +315,25 @@ fn move_camera(
.iter() .iter()
.find(|(character_id, _transform)| *character_id == selected_character_id) .find(|(character_id, _transform)| *character_id == selected_character_id)
{ {
let (camera, mut camera_transform) = let (camera, mut camera_transform, camera_global_transform) =
camera_query.single_mut(); camera_query.single_mut();
let size: Vec2 = camera.logical_viewport_size().unwrap(); let pos = camera
let half_height: f32 = size.y * 0.5; .world_to_viewport(camera_global_transform, transform.translation)
camera_transform.translation = camera_transform.translation.lerp(transform.translation, time.delta_seconds() * FOLLOW_SPEED); .unwrap();
// prevent camera from going too low let size = camera.logical_viewport_size().unwrap();
camera_transform.translation.y = camera_transform.translation.y.max(half_height-MARGIN); if pos.x < MARGIN {
camera_transform.translation.z = 999.0; camera_transform.translation.x += pos.x - MARGIN;
}
if pos.x > size.x - MARGIN {
camera_transform.translation.x += MARGIN + pos.x - size.x;
}
if pos.y < MARGIN {
camera_transform.translation.y += pos.y - MARGIN;
}
if pos.y > size.y - MARGIN {
camera_transform.translation.y += MARGIN + pos.y - size.y;
}
} }
} }
} }

View file

@ -1,11 +1,14 @@
#[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::{core_pipeline::clear_color::ClearColorConfig, prelude::*}; use bevy::{
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)]
@ -16,13 +19,16 @@ enum AppState {
} }
fn main() { fn main() {
let (audio_event_sender, audio_event_receiver) = let (audio_event_sender, audio_event_receiver) = crossbeam_channel::bounded(512);
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)
@ -37,9 +43,6 @@ 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);

View file

@ -2,10 +2,7 @@ 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;