From: Bernie Innocenti Date: Sat, 8 Apr 2017 17:41:33 +0000 (-0400) Subject: Make music optional. X-Git-Tag: v0.4.0~3 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=6c807504ba6d388b7756433469d0836f42409d44;p=mandelwow.git Make music optional. --- diff --git a/Cargo.toml b/Cargo.toml index cada459..d529ef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,4 @@ sdl2 = "*" [[bin]] name = "mandelwow" -path = "mandelwow.rs" +path = "main.rs" diff --git a/main.rs b/main.rs index dac8b37..1b33688 100644 --- a/main.rs +++ b/main.rs @@ -95,7 +95,7 @@ fn bounding_box(display: &glium::Display, } fn main() { - sound::start(); + let _soundplayer = sound::start(); let display = glium::glutin::WindowBuilder::new() //.with_dimensions(1024, 768) diff --git a/sound.rs b/sound.rs index 4b94686..d88850b 100644 --- a/sound.rs +++ b/sound.rs @@ -18,7 +18,7 @@ impl AudioCallback for XmCallback { } pub struct SoundPlayer { - _device: AudioDevice, + _device: Option>, } fn play_xm(raw_xm: &[u8]) -> SoundPlayer { @@ -42,14 +42,21 @@ fn play_xm(raw_xm: &[u8]) -> SoundPlayer { device.resume(); SoundPlayer { - _device: device, + _device: Some(device), } } pub fn start() -> SoundPlayer { - let mut xm = Vec::new(); let filename = "flora.xm"; - File::open(filename).unwrap() - .read_to_end(&mut xm).unwrap(); - return play_xm(&xm); + match File::open(filename) { + Result::Ok(mut f) => { + let mut xm = Vec::new(); + f.read_to_end(&mut xm).unwrap(); + return play_xm(&xm); + }, + Result::Err(err) => { + println!("Couldn't open module {}: {:?}", filename, err); + }, + } + return SoundPlayer { _device: None }; }