Skip to content

Commit

Permalink
attempt to fix issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
prixt committed Feb 6, 2020
1 parent 498d0f2 commit a0adc49
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/*.rs.bk
/soundpack
/soundpack_modified
/ignore.txt
/ignore.txt
soundpack.zip
2 changes: 1 addition & 1 deletion src/sound/sound_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl SoundChannel {
}

pub fn maintain(&mut self, device: &Device, rng: &mut ThreadRng, _ui_handle: Option<&UIHandle>) {
let delay = self.delay.checked_sub(100).unwrap_or(0);
let delay = self.delay.saturating_sub(100);
self.delay = delay;
self.one_shots.retain(|s| {
if delay != 0 {
Expand Down
8 changes: 4 additions & 4 deletions src/sound/sound_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct SoundManager {
impl SoundManager {
pub fn new(sound_dir: &Path, mut ui_handle: UIHandle) -> Self {
let mut sounds = Vec::new();
let device = default_output_device().unwrap();
let device = default_output_device().expect("Failed to get default audio output device.");
let mut channels : HashMap<Box<str>, SoundChannel> = HashMap::new();
channels.insert(
String::from("misc").into_boxed_str(),
Expand All @@ -28,7 +28,7 @@ impl SoundManager {
let path = entry.path();
if path.is_dir() {
visit_dir(&path, func);
} else if path.is_file() && path.extension().unwrap() == "xml" {
} else if path.is_file() && path.extension().map_or(false, |ext| ext=="xml") {
func(&path);
}
}
Expand Down Expand Up @@ -241,8 +241,8 @@ impl SoundManager {
let sounds = &mut self.sounds;
let recent = &mut self.recent;
recent.retain(|&i| {
let timeout = sounds[i].current_timeout.checked_sub(100).unwrap_or(0);
let recent_call = sounds[i].recent_call.checked_sub(1).unwrap_or(0);
let timeout = sounds[i].current_timeout.saturating_sub(100);
let recent_call = sounds[i].recent_call.saturating_sub(1);
sounds[i].current_timeout = timeout;
sounds[i].recent_call = recent_call;
timeout != 0
Expand Down

0 comments on commit a0adc49

Please sign in to comment.