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

Profiles - Made timeline thread safe and slightly tweaked delta logic

This commit is contained in:
Robert 2020-10-30 20:38:36 +01:00
parent ad5c83e5b3
commit f179980ac4
4 changed files with 77 additions and 46 deletions

View File

@ -144,7 +144,7 @@ namespace Artemis.Core
throw new ObjectDisposedException("DataBinding");
// Data bindings cannot go back in time like brushes
TimeSpan deltaTime = timeline.LastDelta;
TimeSpan deltaTime = timeline.Delta;
if (deltaTime < TimeSpan.Zero)
deltaTime = TimeSpan.Zero;

View File

@ -215,7 +215,11 @@ namespace Artemis.Core
if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished))
return;
lock (Timeline)
{
RenderFolder(Timeline, canvas, canvasInfo);
Timeline.ClearDelta();
}
}
private void PrepareForRender(Timeline timeline)
@ -223,7 +227,7 @@ namespace Artemis.Core
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
{
baseLayerEffect.BaseProperties?.Update(timeline);
baseLayerEffect.Update(timeline.LastDelta.TotalSeconds);
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
}
}

View File

@ -287,9 +287,13 @@ namespace Artemis.Core
if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular)
return;
lock (Timeline)
{
RenderLayer(Timeline, canvas);
foreach (Timeline extraTimeline in Timeline.ExtraTimelines)
RenderLayer(extraTimeline, canvas);
Timeline.ClearDelta();
}
}
private void PrepareForRender(Timeline timeline)
@ -297,12 +301,12 @@ namespace Artemis.Core
General.Update(timeline);
Transform.Update(timeline);
LayerBrush.BaseProperties?.Update(timeline);
LayerBrush.Update(timeline.LastDelta.TotalSeconds);
LayerBrush.Update(timeline.Delta.TotalSeconds);
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
{
baseLayerEffect.BaseProperties?.Update(timeline);
baseLayerEffect.Update(timeline.LastDelta.TotalSeconds);
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
}
}

View File

@ -83,12 +83,12 @@ namespace Artemis.Core
}
/// <summary>
/// Gets the delta that was applied during the last call to <see cref="Update" />
/// Gets the cumulative delta of all calls to <see cref="Update" /> that took place after the last call to <see cref="ClearDelta"/>
/// <para>
/// Note: If this is an extra timeline <see cref="LastDelta" /> is always equal to <see cref="DeltaToParent" />
/// Note: If this is an extra timeline <see cref="Delta" /> is always equal to <see cref="DeltaToParent" />
/// </para>
/// </summary>
public TimeSpan LastDelta
public TimeSpan Delta
{
get => Parent == null ? _lastDelta : DeltaToParent;
private set => SetAndNotify(ref _lastDelta, value);
@ -289,7 +289,9 @@ namespace Artemis.Core
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
public void Update(TimeSpan delta, bool stickToMainSegment)
{
LastDelta = delta;
lock (this)
{
Delta += delta;
Position += delta;
if (stickToMainSegment && Position >= MainSegmentStartPosition)
@ -305,48 +307,58 @@ namespace Artemis.Core
foreach (Timeline extraTimeline in _extraTimelines)
extraTimeline.Update(delta, false);
}
}
/// <summary>
/// Moves the position of the timeline backwards to the very start of the timeline
/// </summary>
public void JumpToStart()
{
lock (this)
{
if (Position == TimeSpan.Zero)
return;
LastDelta = TimeSpan.Zero - Position;
Delta = TimeSpan.Zero - Position;
Position = TimeSpan.Zero;
_extraTimelines.Clear();
}
}
/// <summary>
/// Moves the position of the timeline forwards to the beginning of the end segment
/// </summary>
public void JumpToEndSegment()
{
lock (this)
{
if (Position >= EndSegmentStartPosition)
return;
LastDelta = EndSegmentStartPosition - Position;
Delta = EndSegmentStartPosition - Position;
Position = EndSegmentStartPosition;
_extraTimelines.Clear();
}
}
/// <summary>
/// Moves the position of the timeline forwards to the very end of the timeline
/// </summary>
public void JumpToEnd()
{
lock (this)
{
if (Position >= EndSegmentEndPosition)
return;
LastDelta = EndSegmentEndPosition - Position;
Delta = EndSegmentEndPosition - Position;
Position = EndSegmentEndPosition;
_extraTimelines.Clear();
}
}
/// <summary>
/// Overrides the <see cref="Position" /> to the specified time and clears any extra time lines
@ -355,20 +367,26 @@ namespace Artemis.Core
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
public void Override(TimeSpan position, bool stickToMainSegment)
{
LastDelta = position - Position;
lock (this)
{
Delta += position - Position;
Position = position;
if (stickToMainSegment && Position >= MainSegmentStartPosition)
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
_extraTimelines.Clear();
}
}
/// <summary>
/// Sets the <see cref="LastDelta" /> to <see cref="TimeSpan.Zero" />
/// Sets the <see cref="Delta" /> to <see cref="TimeSpan.Zero" />
/// </summary>
public void ClearDelta()
{
LastDelta = TimeSpan.Zero;
lock (this)
{
Delta = TimeSpan.Zero;
}
}
#endregion
@ -398,6 +416,11 @@ namespace Artemis.Core
}
#endregion
public override string ToString()
{
return $"Progress: {Position}/{Length} - delta: {Delta}";
}
}
internal enum TimelineSegment