1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profiles - Fixed elements updating while disabled

This commit is contained in:
Robert 2022-11-26 22:59:24 +01:00
parent b607690286
commit 6b6ea0f973
2 changed files with 71 additions and 53 deletions

View File

@ -99,19 +99,26 @@ public sealed class Folder : RenderProfileElement
return; return;
} }
UpdateDisplayCondition(); try
UpdateTimeline(deltaTime); {
UpdateDisplayCondition();
UpdateTimeline(deltaTime);
if (ShouldBeEnabled) if (ShouldBeEnabled)
Enable(); Enable();
else if (Timeline.IsFinished) else if (Timeline.IsFinished)
Disable(); Disable();
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended)) foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
baseLayerEffect.InternalUpdate(Timeline); baseLayerEffect.InternalUpdate(Timeline);
foreach (ProfileElement child in Children) foreach (ProfileElement child in Children)
child.Update(deltaTime); child.Update(deltaTime);
}
finally
{
Timeline.ClearDelta();
}
} }
/// <inheritdoc /> /// <inheritdoc />
@ -224,8 +231,6 @@ public sealed class Folder : RenderProfileElement
canvas.Restore(); canvas.Restore();
layerPaint.DisposeSelfAndProperties(); layerPaint.DisposeSelfAndProperties();
} }
Timeline.ClearDelta();
} }
#endregion #endregion
@ -233,8 +238,10 @@ public sealed class Folder : RenderProfileElement
/// <inheritdoc /> /// <inheritdoc />
public override void Enable() public override void Enable()
{ {
// No checks here, effects will do their own checks to ensure they never enable twice if (!Enabled)
// Also not enabling children, they'll enable themselves during their own Update return;
// Not enabling children, they'll enable themselves during their own Update
foreach (BaseLayerEffect baseLayerEffect in LayerEffects) foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalEnable(); baseLayerEffect.InternalEnable();
@ -244,7 +251,9 @@ public sealed class Folder : RenderProfileElement
/// <inheritdoc /> /// <inheritdoc />
public override void Disable() public override void Disable()
{ {
// No checks here, effects will do their own checks to ensure they never disable twice if (!Enabled)
return;
foreach (BaseLayerEffect baseLayerEffect in LayerEffects) foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalDisable(); baseLayerEffect.InternalDisable();

View File

@ -40,7 +40,7 @@ public sealed class Layer : RenderProfileElement
Suspended = false; Suspended = false;
Leds = new ReadOnlyCollection<ArtemisLed>(_leds); Leds = new ReadOnlyCollection<ArtemisLed>(_leds);
Adapter = new LayerAdapter(this); Adapter = new LayerAdapter(this);
Initialize(); Initialize();
} }
@ -60,7 +60,7 @@ public sealed class Layer : RenderProfileElement
Parent = parent; Parent = parent;
Leds = new ReadOnlyCollection<ArtemisLed>(_leds); Leds = new ReadOnlyCollection<ArtemisLed>(_leds);
Adapter = new LayerAdapter(this); Adapter = new LayerAdapter(this);
Load(); Load();
Initialize(); Initialize();
if (loadNodeScript) if (loadNodeScript)
@ -370,41 +370,48 @@ public sealed class Layer : RenderProfileElement
return; return;
} }
UpdateDisplayCondition(); try
UpdateTimeline(deltaTime);
if (ShouldBeEnabled)
Enable();
else if (Suspended || (Timeline.IsFinished && !_renderCopies.Any()))
Disable();
if (Timeline.Delta == TimeSpan.Zero)
return;
General.Update(Timeline);
Transform.Update(Timeline);
LayerBrush?.InternalUpdate(Timeline);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
{ {
if (!baseLayerEffect.Suspended) UpdateDisplayCondition();
baseLayerEffect.InternalUpdate(Timeline); UpdateTimeline(deltaTime);
if (ShouldBeEnabled)
Enable();
else if (Suspended || (Timeline.IsFinished && !_renderCopies.Any()))
Disable();
if (!Enabled || Timeline.Delta == TimeSpan.Zero)
return;
General.Update(Timeline);
Transform.Update(Timeline);
LayerBrush?.InternalUpdate(Timeline);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
{
if (!baseLayerEffect.Suspended)
baseLayerEffect.InternalUpdate(Timeline);
}
// Remove render copies that finished their timeline and update the rest
for (int index = 0; index < _renderCopies.Count; index++)
{
Layer child = _renderCopies[index];
if (!child.Timeline.IsFinished)
{
child.Update(deltaTime);
}
else
{
_renderCopies.Remove(child);
child.Dispose();
index--;
}
}
} }
finally
// Remove render copies that finished their timeline and update the rest
for (int index = 0; index < _renderCopies.Count; index++)
{ {
Layer child = _renderCopies[index]; Timeline.ClearDelta();
if (!child.Timeline.IsFinished)
{
child.Update(deltaTime);
}
else
{
_renderCopies.Remove(child);
child.Dispose();
index--;
}
} }
} }
@ -485,8 +492,6 @@ public sealed class Layer : RenderProfileElement
{ {
layerPaint.DisposeSelfAndProperties(); layerPaint.DisposeSelfAndProperties();
} }
Timeline.ClearDelta();
} }
private void RenderCopies(SKCanvas canvas, SKPointI basePosition) private void RenderCopies(SKCanvas canvas, SKPointI basePosition)
@ -498,7 +503,9 @@ public sealed class Layer : RenderProfileElement
/// <inheritdoc /> /// <inheritdoc />
public override void Enable() public override void Enable()
{ {
// No checks here, the brush and effects will do their own checks to ensure they never enable twice if (Enabled)
return;
bool tryOrBreak = TryOrBreak(() => LayerBrush?.InternalEnable(), "Failed to enable layer brush"); bool tryOrBreak = TryOrBreak(() => LayerBrush?.InternalEnable(), "Failed to enable layer brush");
if (!tryOrBreak) if (!tryOrBreak)
return; return;
@ -517,7 +524,9 @@ public sealed class Layer : RenderProfileElement
/// <inheritdoc /> /// <inheritdoc />
public override void Disable() public override void Disable()
{ {
// No checks here, the brush and effects will do their own checks to ensure they never disable twice if (!Enabled)
return;
LayerBrush?.InternalDisable(); LayerBrush?.InternalDisable();
foreach (BaseLayerEffect baseLayerEffect in LayerEffects) foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.InternalDisable(); baseLayerEffect.InternalDisable();