using System; using RGB.NET.Core; using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { /// /// Represents a basic update-queue performing updates for razer devices. /// public abstract class RazerUpdateQueue : UpdateQueue { #region Properties & Fields private Guid? _lastEffect; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used to update this queue. protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger) : base(updateTrigger) { } #endregion #region Methods /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { IntPtr effectParams = CreateEffectParams(dataSet); Guid effectId = Guid.NewGuid(); CreateEffect(effectParams, ref effectId); _RazerSDK.SetEffect(effectId); if (_lastEffect.HasValue) _RazerSDK.DeleteEffect(_lastEffect.Value); _lastEffect = effectId; } /// /// Creates the effect used to update this device. /// /// The parameters of the effect. /// The id this effect is created with. protected abstract void CreateEffect(IntPtr effectParams, ref Guid effectId); /// public override void Reset() { if (_lastEffect.HasValue) { _RazerSDK.DeleteEffect(_lastEffect.Value); _lastEffect = null; } } /// /// Creates the device-specific effect parameters for the led-update. /// /// The data to be updated. /// An pointing to the effect parameter struct. protected abstract IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); #endregion } }