From dd6fdbc60f53290af99ba0640c284917a85070e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 25 Jun 2021 07:55:15 +0200 Subject: newtype sound effect id --- mumd/src/audio/sound_effects.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mumd/src/audio/sound_effects.rs b/mumd/src/audio/sound_effects.rs index 14727f3..06d2e4d 100644 --- a/mumd/src/audio/sound_effects.rs +++ b/mumd/src/audio/sound_effects.rs @@ -17,9 +17,12 @@ use strum_macros::EnumIter; use crate::audio::SAMPLE_RATE; +#[derive(Debug, Clone, Copy)] +pub struct SoundEffectId(usize); + pub struct SoundEffects { data: Vec>, - loaded_paths: HashMap, + loaded_paths: HashMap, num_channels: usize, } @@ -46,18 +49,18 @@ impl SoundEffects { Entry::Occupied(o) => *o.get(), Entry::Vacant(v) => { if let Ok(samples) = open_and_unpack_audio(v.key(), self.num_channels) { - let idx = self.data.len(); + let idx = SoundEffectId(self.data.len()); self.data.push(samples); v.insert(idx); idx } else { // Default sound effect - 0 + SoundEffectId(0) } } }; - &self.data[idx] + &self.data[idx.0] } } -- cgit v1.2.1