From 1a80c83ea6b4e7239a0ea298a2797c0f2c60e5ef Mon Sep 17 00:00:00 2001 From: ionarevamp Date: Thu, 4 Apr 2024 19:58:29 -0600 Subject: [PATCH] Fixed build config for multiple linux targets. --- .cargo/config.toml | 8 ++++---- Cargo.toml | 2 +- src/extras/mod.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 1181993..3c7d48a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,13 +3,13 @@ rustflags = [ "-C", "linker=g++", ] -[dependencies.sdl2] -version = "0.36" -default-features = false - [target.x86_64-unknown-linux-musl] rustflags = [ "-C", "linker=g++", ] +[target.'cfg(not(target-family "android"))'.dependencies.sdl2] +git = "https://github.com/rust-sdl2/rust-sdl2" +default-features = false +features = ["static-link","bundled"] diff --git a/Cargo.toml b/Cargo.toml index 3548ecc..426c854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,4 @@ ratatui = "0.26.1" [dependencies.sdl2] git = "https://github.com/rust-sdl2/rust-sdl2" default-features = false -features = ["ttf","image","gfx","mixer","bundled","static-link"] +features = ["ttf","image","gfx","mixer"] diff --git a/src/extras/mod.rs b/src/extras/mod.rs index 66c8ab7..eb402a1 100644 --- a/src/extras/mod.rs +++ b/src/extras/mod.rs @@ -18,6 +18,9 @@ impl Sound { pub fn volume(&self) -> f32 { self.volume.clone() } + pub fn pos(&self) -> usize { + self.pos + } pub fn fade_in(&mut self, rate: f32, max: f32) { if self.volume < max { self.volume += rate; @@ -151,3 +154,50 @@ pub fn generate_sound( } // ^ This returns a device and an audio spec... +// + + + +#[allow(dead_code)] +#[test] +pub fn loop_test() -> Result<()> { + + println!("Loading..."); + let sdl_context = sdl2::init().expect("Unable to initialize SDL2"); println!("SDL2 initialized."); + let audio_subsystem = sdl_context + .audio() + .expect("Unable to initialize audio subsystem"); + println!("Audio subsystem initialized."); + + let wav = Cow::from(Path::new("Ominous.wav")); + let mut device = generate_sound(&audio_subsystem, &wav, 0.5, 0).unwrap().0; + + device.resume(); + let (mut loop_count, loop_limit) = (0,2); + loop { + device.lock().fade_percent(0.05, 1.0); + if device.lock().pos() >= 1154609*2 { + device.lock().restart(); + device.lock().set_volume(0.5); + loop_count += 1; + if loop_count >= loop_limit { break; } + } + } + + let wav = Cow::from(Path::new("Mysterious_Cyborg.wav")); + device = generate_sound(&audio_subsystem, &wav, 0.3, 0).unwrap().0; + + device.resume(); loop_count = 0; + loop { + device.lock().fade_percent(0.02, 1.0); + if device.lock().pos() >= (44100 as f64 * 21.33) as usize *2 { + device.lock().restart(); + device.lock().set_volume(0.5); + loop_count += 1; + if loop_count >= loop_limit { break; } + } + } + + Ok(()) + +}