diff --git a/CHANGELOG.md b/CHANGELOG.md index d672dad..5ecf16e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Improvements - Added customizable overloads for Keybind, Combination and GenericInput ToString methods - Moved ColorHelper.Invert to ColorExtensions.Invert - Removed LINQ Any and All usage in various methods to improve memory usage +- Allow enumerating SoundEffectInstanceHandler entries Fixes - Set default values for InputHandler held and pressed keys to avoid an exception if buttons are held in the very first frame diff --git a/MLEM/Sound/SoundEffectInstanceHandler.cs b/MLEM/Sound/SoundEffectInstanceHandler.cs index 9273c88..2e77d58 100644 --- a/MLEM/Sound/SoundEffectInstanceHandler.cs +++ b/MLEM/Sound/SoundEffectInstanceHandler.cs @@ -10,7 +10,7 @@ namespace MLEM.Sound { /// Additionally, a callback can be registered that is invoked when the finishes playing. /// Note that an object of this class can be added to a using its . /// - public class SoundEffectInstanceHandler : GameComponent, IEnumerable { + public class SoundEffectInstanceHandler : GameComponent, IEnumerable { private readonly List playingSounds = new List(); private AudioListener[] listeners; @@ -110,28 +110,42 @@ namespace MLEM.Sound { } /// - public IEnumerator GetEnumerator() { - foreach (var sound in this.playingSounds) - yield return sound.Instance; + public IEnumerator GetEnumerator() { + return this.playingSounds.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } - private readonly struct Entry { + /// + /// An entry in a . + /// Each entry stores the that is being played, as well as the additional data passed through . + /// + public readonly struct Entry { + /// + /// The sound effect instance that this entry is playing + /// public readonly SoundEffectInstance Instance; + /// + /// An action that is invoked when this entry's is stopped. + /// This action is invoked in . + /// public readonly Action OnStopped; + /// + /// The that this sound effect instance is linked to. + /// If the underlying handler's method has been called, 3D sound will be applied. + /// public readonly AudioEmitter Emitter; - public Entry(SoundEffectInstance instance, Action onStopped, AudioEmitter emitter) { + internal Entry(SoundEffectInstance instance, Action onStopped, AudioEmitter emitter) { this.Instance = instance; this.OnStopped = onStopped; this.Emitter = emitter; } - public void TryApply3D(AudioListener[] listeners) { + internal void TryApply3D(AudioListener[] listeners) { if (listeners != null && listeners.Length > 0 && this.Emitter != null) this.Instance.Apply3D(listeners, this.Emitter); }