diff --git a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs index 6d473ac1b..a03212697 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs @@ -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; diff --git a/src/Artemis.Core/Models/Profile/Folder.cs b/src/Artemis.Core/Models/Profile/Folder.cs index 209d2dc56..6c28c72a1 100644 --- a/src/Artemis.Core/Models/Profile/Folder.cs +++ b/src/Artemis.Core/Models/Profile/Folder.cs @@ -215,7 +215,11 @@ namespace Artemis.Core if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished)) return; - RenderFolder(Timeline, canvas, canvasInfo); + 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); } } diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 77c632a32..70da32cd7 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -287,9 +287,13 @@ namespace Artemis.Core if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular) return; - RenderLayer(Timeline, canvas); - foreach (Timeline extraTimeline in Timeline.ExtraTimelines) - RenderLayer(extraTimeline, canvas); + 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); } } diff --git a/src/Artemis.Core/Models/Profile/Timeline.cs b/src/Artemis.Core/Models/Profile/Timeline.cs index be92d53e1..ee77e3b32 100644 --- a/src/Artemis.Core/Models/Profile/Timeline.cs +++ b/src/Artemis.Core/Models/Profile/Timeline.cs @@ -83,12 +83,12 @@ namespace Artemis.Core } /// - /// Gets the delta that was applied during the last call to + /// Gets the cumulative delta of all calls to that took place after the last call to /// - /// Note: If this is an extra timeline is always equal to + /// Note: If this is an extra timeline is always equal to /// /// - public TimeSpan LastDelta + public TimeSpan Delta { get => Parent == null ? _lastDelta : DeltaToParent; private set => SetAndNotify(ref _lastDelta, value); @@ -289,21 +289,24 @@ namespace Artemis.Core /// Whether to stick to the main segment, wrapping around if needed public void Update(TimeSpan delta, bool stickToMainSegment) { - LastDelta = delta; - Position += delta; - - if (stickToMainSegment && Position >= MainSegmentStartPosition) + lock (this) { - // 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); - } + Delta += delta; + Position += delta; - foreach (Timeline extraTimeline in _extraTimelines) - extraTimeline.Update(delta, false); + if (stickToMainSegment && Position >= MainSegmentStartPosition) + { + // 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); + } } /// @@ -311,13 +314,16 @@ namespace Artemis.Core /// public void JumpToStart() { - if (Position == TimeSpan.Zero) - return; + lock (this) + { + if (Position == TimeSpan.Zero) + return; - LastDelta = TimeSpan.Zero - Position; - Position = TimeSpan.Zero; + Delta = TimeSpan.Zero - Position; + Position = TimeSpan.Zero; - _extraTimelines.Clear(); + _extraTimelines.Clear(); + } } /// @@ -325,13 +331,16 @@ namespace Artemis.Core /// public void JumpToEndSegment() { - if (Position >= EndSegmentStartPosition) - return; + lock (this) + { + if (Position >= EndSegmentStartPosition) + return; - LastDelta = EndSegmentStartPosition - Position; - Position = EndSegmentStartPosition; + Delta = EndSegmentStartPosition - Position; + Position = EndSegmentStartPosition; - _extraTimelines.Clear(); + _extraTimelines.Clear(); + } } /// @@ -339,13 +348,16 @@ namespace Artemis.Core /// public void JumpToEnd() { - if (Position >= EndSegmentEndPosition) - return; + lock (this) + { + if (Position >= EndSegmentEndPosition) + return; - LastDelta = EndSegmentEndPosition - Position; - Position = EndSegmentEndPosition; + Delta = EndSegmentEndPosition - Position; + Position = EndSegmentEndPosition; - _extraTimelines.Clear(); + _extraTimelines.Clear(); + } } /// @@ -355,20 +367,26 @@ namespace Artemis.Core /// Whether to stick to the main segment, wrapping around if needed public void Override(TimeSpan position, bool stickToMainSegment) { - LastDelta = position - Position; - Position = position; - if (stickToMainSegment && Position >= MainSegmentStartPosition) - Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds); + lock (this) + { + Delta += position - Position; + Position = position; + if (stickToMainSegment && Position >= MainSegmentStartPosition) + Position = MainSegmentStartPosition + TimeSpan.FromMilliseconds(Position.TotalMilliseconds % MainSegmentLength.TotalMilliseconds); - _extraTimelines.Clear(); + _extraTimelines.Clear(); + } } /// - /// Sets the to + /// Sets the to /// 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