aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-06-25 07:55:15 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-06-26 07:55:51 +0200
commitdd6fdbc60f53290af99ba0640c284917a85070e5 (patch)
tree37233372334a6f2bcc2891a27864cbb6e372e3dc
parent9d67e3a6e1304062ba40993077ce0617565b9df9 (diff)
downloadmum-dd6fdbc60f53290af99ba0640c284917a85070e5.tar.gz
newtype sound effect id
-rw-r--r--mumd/src/audio/sound_effects.rs11
1 files 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<Vec<f32>>,
- loaded_paths: HashMap<PathBuf, usize>,
+ loaded_paths: HashMap<PathBuf, SoundEffectId>,
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]
}
}