using System.Collections.Generic; namespace Nerfed.Runtime.Audio; internal class SourceVoicePool { private AudioDevice Device; Dictionary<(System.Type, Format), Queue> VoiceLists = new Dictionary<(System.Type, Format), Queue>(); public SourceVoicePool(AudioDevice device) { Device = device; } public T Obtain(Format format) where T : SourceVoice, IPoolable { if (!VoiceLists.ContainsKey((typeof(T), format))) { VoiceLists.Add((typeof(T), format), new Queue()); } Queue list = VoiceLists[(typeof(T), format)]; if (list.Count == 0) { list.Enqueue(T.Create(Device, format)); } return (T) list.Dequeue(); } public void Return(SourceVoice voice) { Queue list = VoiceLists[(voice.GetType(), voice.Format)]; list.Enqueue(voice); } }