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:
parent
ad5c83e5b3
commit
f179980ac4
@ -144,7 +144,7 @@ namespace Artemis.Core
|
|||||||
throw new ObjectDisposedException("DataBinding");
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
// Data bindings cannot go back in time like brushes
|
// Data bindings cannot go back in time like brushes
|
||||||
TimeSpan deltaTime = timeline.LastDelta;
|
TimeSpan deltaTime = timeline.Delta;
|
||||||
if (deltaTime < TimeSpan.Zero)
|
if (deltaTime < TimeSpan.Zero)
|
||||||
deltaTime = TimeSpan.Zero;
|
deltaTime = TimeSpan.Zero;
|
||||||
|
|
||||||
|
|||||||
@ -215,7 +215,11 @@ namespace Artemis.Core
|
|||||||
if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished))
|
if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RenderFolder(Timeline, canvas, canvasInfo);
|
lock (Timeline)
|
||||||
|
{
|
||||||
|
RenderFolder(Timeline, canvas, canvasInfo);
|
||||||
|
Timeline.ClearDelta();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareForRender(Timeline timeline)
|
private void PrepareForRender(Timeline timeline)
|
||||||
@ -223,7 +227,7 @@ namespace Artemis.Core
|
|||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||||
{
|
{
|
||||||
baseLayerEffect.BaseProperties?.Update(timeline);
|
baseLayerEffect.BaseProperties?.Update(timeline);
|
||||||
baseLayerEffect.Update(timeline.LastDelta.TotalSeconds);
|
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -287,9 +287,13 @@ namespace Artemis.Core
|
|||||||
if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular)
|
if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RenderLayer(Timeline, canvas);
|
lock (Timeline)
|
||||||
foreach (Timeline extraTimeline in Timeline.ExtraTimelines)
|
{
|
||||||
RenderLayer(extraTimeline, canvas);
|
RenderLayer(Timeline, canvas);
|
||||||
|
foreach (Timeline extraTimeline in Timeline.ExtraTimelines)
|
||||||
|
RenderLayer(extraTimeline, canvas);
|
||||||
|
Timeline.ClearDelta();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareForRender(Timeline timeline)
|
private void PrepareForRender(Timeline timeline)
|
||||||
@ -297,12 +301,12 @@ namespace Artemis.Core
|
|||||||
General.Update(timeline);
|
General.Update(timeline);
|
||||||
Transform.Update(timeline);
|
Transform.Update(timeline);
|
||||||
LayerBrush.BaseProperties?.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))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||||
{
|
{
|
||||||
baseLayerEffect.BaseProperties?.Update(timeline);
|
baseLayerEffect.BaseProperties?.Update(timeline);
|
||||||
baseLayerEffect.Update(timeline.LastDelta.TotalSeconds);
|
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,12 +83,12 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// <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>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeSpan LastDelta
|
public TimeSpan Delta
|
||||||
{
|
{
|
||||||
get => Parent == null ? _lastDelta : DeltaToParent;
|
get => Parent == null ? _lastDelta : DeltaToParent;
|
||||||
private set => SetAndNotify(ref _lastDelta, value);
|
private set => SetAndNotify(ref _lastDelta, value);
|
||||||
@ -289,21 +289,24 @@ namespace Artemis.Core
|
|||||||
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
|
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
|
||||||
public void Update(TimeSpan delta, bool stickToMainSegment)
|
public void Update(TimeSpan delta, bool stickToMainSegment)
|
||||||
{
|
{
|
||||||
LastDelta = delta;
|
lock (this)
|
||||||
Position += delta;
|
|
||||||
|
|
||||||
if (stickToMainSegment && Position >= MainSegmentStartPosition)
|
|
||||||
{
|
{
|
||||||
// If the main segment has no length, simply stick to the start of the segment
|
Delta += delta;
|
||||||
if (MainSegmentLength == TimeSpan.Zero)
|
Position += delta;
|
||||||
Position = MainSegmentStartPosition;
|
|
||||||
// Ensure wrapping back around retains the delta time
|
|
||||||
else
|
|
||||||
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Timeline extraTimeline in _extraTimelines)
|
if (stickToMainSegment && Position >= MainSegmentStartPosition)
|
||||||
extraTimeline.Update(delta, false);
|
{
|
||||||
|
// If the main segment has no length, simply stick to the start of the segment
|
||||||
|
if (MainSegmentLength == TimeSpan.Zero)
|
||||||
|
Position = MainSegmentStartPosition;
|
||||||
|
// Ensure wrapping back around retains the delta time
|
||||||
|
else
|
||||||
|
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Timeline extraTimeline in _extraTimelines)
|
||||||
|
extraTimeline.Update(delta, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -311,13 +314,16 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void JumpToStart()
|
public void JumpToStart()
|
||||||
{
|
{
|
||||||
if (Position == TimeSpan.Zero)
|
lock (this)
|
||||||
return;
|
{
|
||||||
|
if (Position == TimeSpan.Zero)
|
||||||
|
return;
|
||||||
|
|
||||||
LastDelta = TimeSpan.Zero - Position;
|
Delta = TimeSpan.Zero - Position;
|
||||||
Position = TimeSpan.Zero;
|
Position = TimeSpan.Zero;
|
||||||
|
|
||||||
_extraTimelines.Clear();
|
_extraTimelines.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -325,13 +331,16 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void JumpToEndSegment()
|
public void JumpToEndSegment()
|
||||||
{
|
{
|
||||||
if (Position >= EndSegmentStartPosition)
|
lock (this)
|
||||||
return;
|
{
|
||||||
|
if (Position >= EndSegmentStartPosition)
|
||||||
|
return;
|
||||||
|
|
||||||
LastDelta = EndSegmentStartPosition - Position;
|
Delta = EndSegmentStartPosition - Position;
|
||||||
Position = EndSegmentStartPosition;
|
Position = EndSegmentStartPosition;
|
||||||
|
|
||||||
_extraTimelines.Clear();
|
_extraTimelines.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -339,13 +348,16 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void JumpToEnd()
|
public void JumpToEnd()
|
||||||
{
|
{
|
||||||
if (Position >= EndSegmentEndPosition)
|
lock (this)
|
||||||
return;
|
{
|
||||||
|
if (Position >= EndSegmentEndPosition)
|
||||||
|
return;
|
||||||
|
|
||||||
LastDelta = EndSegmentEndPosition - Position;
|
Delta = EndSegmentEndPosition - Position;
|
||||||
Position = EndSegmentEndPosition;
|
Position = EndSegmentEndPosition;
|
||||||
|
|
||||||
_extraTimelines.Clear();
|
_extraTimelines.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -355,20 +367,26 @@ namespace Artemis.Core
|
|||||||
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
|
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
|
||||||
public void Override(TimeSpan position, bool stickToMainSegment)
|
public void Override(TimeSpan position, bool stickToMainSegment)
|
||||||
{
|
{
|
||||||
LastDelta = position - Position;
|
lock (this)
|
||||||
Position = position;
|
{
|
||||||
if (stickToMainSegment && Position >= MainSegmentStartPosition)
|
Delta += position - Position;
|
||||||
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
|
Position = position;
|
||||||
|
if (stickToMainSegment && Position >= MainSegmentStartPosition)
|
||||||
|
Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds);
|
||||||
|
|
||||||
_extraTimelines.Clear();
|
_extraTimelines.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the <see cref="LastDelta" /> to <see cref="TimeSpan.Zero" />
|
/// Sets the <see cref="Delta" /> to <see cref="TimeSpan.Zero" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearDelta()
|
public void ClearDelta()
|
||||||
{
|
{
|
||||||
LastDelta = TimeSpan.Zero;
|
lock (this)
|
||||||
|
{
|
||||||
|
Delta = TimeSpan.Zero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -398,6 +416,11 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Progress: {Position}/{Length} - delta: {Delta}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal enum TimelineSegment
|
internal enum TimelineSegment
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user