Return a way to get back at the channel

This commit is contained in:
Gwilym Kuiper 2021-06-25 21:38:10 +01:00
parent 754abd58bd
commit 27a470c648

View file

@ -6,15 +6,17 @@ use crate::number::Num;
pub struct Mixer { pub struct Mixer {
buffer: MixerBuffer, buffer: MixerBuffer,
channels: [Option<SoundChannel>; 16], channels: [Option<SoundChannel>; 16],
indices: [i32; 16],
} }
pub struct ChannelId(usize); pub struct ChannelId(usize, i32);
impl Mixer { impl Mixer {
pub(super) fn new() -> Self { pub(super) fn new() -> Self {
Mixer { Mixer {
buffer: MixerBuffer::new(), buffer: MixerBuffer::new(),
channels: Default::default(), channels: Default::default(),
indices: Default::default(),
} }
} }
@ -40,7 +42,8 @@ impl Mixer {
} }
channel.replace(new_channel); channel.replace(new_channel);
return Some(ChannelId(i)); self.indices[i] += 1;
return Some(ChannelId(i, self.indices[i]));
} }
if new_channel.priority == SoundPriority::Low { if new_channel.priority == SoundPriority::Low {
@ -53,7 +56,8 @@ impl Mixer {
} }
channel.replace(new_channel); channel.replace(new_channel);
return Some(ChannelId(i)); self.indices[i] += 1;
return Some(ChannelId(i, self.indices[i]));
} }
panic!("Cannot play more than 16 sounds at once"); panic!("Cannot play more than 16 sounds at once");