From c05007804fb715b5d542535bcb224d5bd67b8b58 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 3 Mar 2024 20:46:58 +0300 Subject: [PATCH 01/38] Use more direct way to apply transforms --- .../Formats/LegacyStoryboardDecoder.cs | 2 +- osu.Game/Storyboards/CommandTimeline.cs | 10 ++- osu.Game/Storyboards/CommandTimelineGroup.cs | 23 +++--- osu.Game/Storyboards/StoryboardSprite.cs | 77 +++++++++++++------ 4 files changed, 75 insertions(+), 37 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index cf4700bf85..a9a4d9cc49 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -212,7 +212,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.Scale.Add(easing, startTime, endTime, startValue, endValue); + timelineGroup?.Scale.Add(easing, startTime, endTime, new Vector2(startValue), new Vector2(endValue)); break; } diff --git a/osu.Game/Storyboards/CommandTimeline.cs b/osu.Game/Storyboards/CommandTimeline.cs index 0650c97165..2bb606d2bb 100644 --- a/osu.Game/Storyboards/CommandTimeline.cs +++ b/osu.Game/Storyboards/CommandTimeline.cs @@ -24,6 +24,13 @@ namespace osu.Game.Storyboards public T StartValue { get; private set; } public T EndValue { get; private set; } + public string PropertyName { get; } + + public CommandTimeline(string propertyName) + { + PropertyName = propertyName; + } + public void Add(Easing easing, double startTime, double endTime, T startValue, T endValue) { if (endTime < startTime) @@ -31,7 +38,7 @@ namespace osu.Game.Storyboards endTime = startTime; } - commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue }); + commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName }); if (startTime < StartTime) { @@ -55,6 +62,7 @@ namespace osu.Game.Storyboards public double StartTime { get; set; } public double EndTime { get; set; } public double Duration => EndTime - StartTime; + public string PropertyName { get; set; } public T StartValue; public T EndValue; diff --git a/osu.Game/Storyboards/CommandTimelineGroup.cs b/osu.Game/Storyboards/CommandTimelineGroup.cs index 0b96db6861..cb795e0ffe 100644 --- a/osu.Game/Storyboards/CommandTimelineGroup.cs +++ b/osu.Game/Storyboards/CommandTimelineGroup.cs @@ -3,11 +3,11 @@ using System; using osuTK; -using osuTK.Graphics; using osu.Framework.Graphics; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Framework.Graphics.Colour; namespace osu.Game.Storyboards { @@ -15,16 +15,16 @@ namespace osu.Game.Storyboards public class CommandTimelineGroup { - public CommandTimeline X = new CommandTimeline(); - public CommandTimeline Y = new CommandTimeline(); - public CommandTimeline Scale = new CommandTimeline(); - public CommandTimeline VectorScale = new CommandTimeline(); - public CommandTimeline Rotation = new CommandTimeline(); - public CommandTimeline Colour = new CommandTimeline(); - public CommandTimeline Alpha = new CommandTimeline(); - public CommandTimeline BlendingParameters = new CommandTimeline(); - public CommandTimeline FlipH = new CommandTimeline(); - public CommandTimeline FlipV = new CommandTimeline(); + public CommandTimeline X = new CommandTimeline("X"); + public CommandTimeline Y = new CommandTimeline("Y"); + public CommandTimeline Scale = new CommandTimeline("Scale"); + public CommandTimeline VectorScale = new CommandTimeline("VectorScale"); + public CommandTimeline Rotation = new CommandTimeline("Rotation"); + public CommandTimeline Colour = new CommandTimeline("Colour"); + public CommandTimeline Alpha = new CommandTimeline("Alpha"); + public CommandTimeline BlendingParameters = new CommandTimeline("Blending"); + public CommandTimeline FlipH = new CommandTimeline("FlipH"); + public CommandTimeline FlipV = new CommandTimeline("FlipV"); private readonly ICommandTimeline[] timelines; @@ -109,6 +109,7 @@ namespace osu.Game.Storyboards EndTime = offset + command.EndTime, StartValue = command.StartValue, EndValue = command.EndValue, + PropertyName = command.PropertyName }); } diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 982185d51b..4d3f1c158f 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -98,8 +98,6 @@ namespace osu.Game.Storyboards private delegate void DrawablePropertyInitializer(Drawable drawable, T value); - private delegate void DrawableTransformer(Drawable drawable, T value, double duration, Easing easing); - public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) { Path = path; @@ -132,27 +130,23 @@ namespace osu.Game.Storyboards List generated = new List(); - generateCommands(generated, getCommands(g => g.X, triggeredGroups), (d, value) => d.X = value, (d, value, duration, easing) => d.MoveToX(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value, (d, value, duration, easing) => d.MoveToY(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = new Vector2(value), (d, value, duration, easing) => d.ScaleTo(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value, (d, value, duration, easing) => d.RotateTo(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value, (d, value, duration, easing) => d.FadeColour(value, duration, easing)); - generateCommands(generated, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value, (d, value, duration, easing) => d.FadeTo(value, duration, easing)); - generateCommands(generated, getCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, (d, value, duration, _) => d.TransformBlendingMode(value, duration), - false); + generateCommands(generated, getCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); + generateCommands(generated, getCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); + generateCommands(generated, getCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); + generateCommands(generated, getCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); + generateCommands(generated, getCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); + generateCommands(generated, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); + generateCommands(generated, getCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); if (drawable is IVectorScalable vectorScalable) { - generateCommands(generated, getCommands(g => g.VectorScale, triggeredGroups), (_, value) => vectorScalable.VectorScale = value, - (_, value, duration, easing) => vectorScalable.VectorScaleTo(value, duration, easing)); + generateCommands(generated, getCommands(g => g.VectorScale, triggeredGroups), (_, value) => vectorScalable.VectorScale = value); } if (drawable is IFlippable flippable) { - generateCommands(generated, getCommands(g => g.FlipH, triggeredGroups), (_, value) => flippable.FlipH = value, (_, value, duration, _) => flippable.TransformFlipH(value, duration), - false); - generateCommands(generated, getCommands(g => g.FlipV, triggeredGroups), (_, value) => flippable.FlipV = value, (_, value, duration, _) => flippable.TransformFlipV(value, duration), - false); + generateCommands(generated, getCommands(g => g.FlipH, triggeredGroups), (_, value) => flippable.FlipH = value, false); + generateCommands(generated, getCommands(g => g.FlipV, triggeredGroups), (_, value) => flippable.FlipV = value, false); } foreach (var command in generated.OrderBy(g => g.StartTime)) @@ -160,7 +154,7 @@ namespace osu.Game.Storyboards } private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, - DrawablePropertyInitializer initializeProperty, DrawableTransformer transform, bool alwaysInitialize = true) + DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) { bool initialized = false; @@ -175,7 +169,7 @@ namespace osu.Game.Storyboards initialized = true; } - resultList.Add(new GeneratedCommand(command, initFunc, transform)); + resultList.Add(new GeneratedCommand(command, initFunc)); } } @@ -209,24 +203,59 @@ namespace osu.Game.Storyboards public double StartTime => command.StartTime; private readonly DrawablePropertyInitializer? initializeProperty; - private readonly DrawableTransformer transform; private readonly CommandTimeline.TypedCommand command; - public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty, DrawableTransformer transform) + public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) { this.command = command; this.initializeProperty = initializeProperty; - this.transform = transform; } public void ApplyTo(Drawable drawable) { initializeProperty?.Invoke(drawable, command.StartValue); - using (drawable.BeginAbsoluteSequence(command.StartTime)) + switch (command.PropertyName) { - transform(drawable, command.StartValue, 0, Easing.None); - transform(drawable, command.EndValue, command.Duration, command.Easing); + case "VectorScale": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + + break; + + case "FlipH": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + } + + break; + + case "FlipV": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + } + + break; + + case "Blending": + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + } + + break; + + default: + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + + break; } } } From 7193ec66a4dee4abe516bd8984d3ed50559df35d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 3 Mar 2024 21:30:46 +0300 Subject: [PATCH 02/38] Make use of framework's transform loops --- osu.Game/Storyboards/CommandLoop.cs | 18 ++++-- osu.Game/Storyboards/CommandTimeline.cs | 2 + osu.Game/Storyboards/StoryboardSprite.cs | 75 +++++++++++++++++++----- 3 files changed, 76 insertions(+), 19 deletions(-) diff --git a/osu.Game/Storyboards/CommandLoop.cs b/osu.Game/Storyboards/CommandLoop.cs index 480d69c12f..a912daea44 100644 --- a/osu.Game/Storyboards/CommandLoop.cs +++ b/osu.Game/Storyboards/CommandLoop.cs @@ -38,11 +38,21 @@ namespace osu.Game.Storyboards public override IEnumerable.TypedCommand> GetCommands(CommandTimelineSelector timelineSelector, double offset = 0) { - for (int loop = 0; loop < TotalIterations; loop++) + double fullLoopDuration = CommandsEndTime - CommandsStartTime; + + foreach (var command in timelineSelector(this).Commands) { - double loopOffset = LoopStartTime + loop * CommandsDuration; - foreach (var command in base.GetCommands(timelineSelector, offset + loopOffset)) - yield return command; + yield return new CommandTimeline.TypedCommand + { + Easing = command.Easing, + StartTime = offset + LoopStartTime + command.StartTime, + EndTime = offset + LoopStartTime + command.EndTime, + StartValue = command.StartValue, + EndValue = command.EndValue, + PropertyName = command.PropertyName, + LoopCount = TotalIterations, + Delay = fullLoopDuration - command.EndTime + command.StartTime + }; } } diff --git a/osu.Game/Storyboards/CommandTimeline.cs b/osu.Game/Storyboards/CommandTimeline.cs index 2bb606d2bb..ce25bfe25b 100644 --- a/osu.Game/Storyboards/CommandTimeline.cs +++ b/osu.Game/Storyboards/CommandTimeline.cs @@ -63,6 +63,8 @@ namespace osu.Game.Storyboards public double EndTime { get; set; } public double Duration => EndTime - StartTime; public string PropertyName { get; set; } + public int LoopCount { get; set; } + public double Delay { get; set; } public T StartValue; public T EndValue; diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 4d3f1c158f..2c04e4c983 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -218,41 +218,86 @@ namespace osu.Game.Storyboards switch (command.PropertyName) { case "VectorScale": - using (drawable.BeginAbsoluteSequence(command.StartTime)) + if (command.LoopCount == 0) { - ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + } + else + { + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) + .Loop(command.Delay, command.LoopCount); + } } break; case "FlipH": - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); - } - - break; - case "FlipV": - using (drawable.BeginAbsoluteSequence(command.StartTime)) + if (command.LoopCount == 0) { - ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue); + } + } + else + { + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue) + .Loop(command.Delay, command.LoopCount); + } } break; case "Blending": - using (drawable.BeginAbsoluteSequence(command.StartTime)) + if (command.LoopCount == 0) { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue); + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue); + } + } + else + { + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue) + .Loop(command.Delay, command.LoopCount); + } } break; default: - using (drawable.BeginAbsoluteSequence(command.StartTime)) + if (command.LoopCount == 0) { - drawable.TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + } + else + { + using (drawable.BeginAbsoluteSequence(command.StartTime)) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) + .Loop(command.Delay, command.LoopCount); + } } break; From f5d24e6804e64ffa720adc57116323cd682107e3 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 3 Mar 2024 21:54:37 +0300 Subject: [PATCH 03/38] Remove unused transform extensions --- .../Drawables/DrawablesExtensions.cs | 30 ------------- osu.Game/Storyboards/Drawables/IFlippable.cs | 42 ------------------- .../Storyboards/Drawables/IVectorScalable.cs | 8 ---- 3 files changed, 80 deletions(-) delete mode 100644 osu.Game/Storyboards/Drawables/DrawablesExtensions.cs diff --git a/osu.Game/Storyboards/Drawables/DrawablesExtensions.cs b/osu.Game/Storyboards/Drawables/DrawablesExtensions.cs deleted file mode 100644 index bbc55a336d..0000000000 --- a/osu.Game/Storyboards/Drawables/DrawablesExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Graphics; -using osu.Framework.Graphics.Transforms; - -namespace osu.Game.Storyboards.Drawables -{ - public static class DrawablesExtensions - { - /// - /// Adjusts after a delay. - /// - /// A to which further transforms can be added. - public static TransformSequence TransformBlendingMode(this T drawable, BlendingParameters newValue, double delay = 0) - where T : Drawable - => drawable.TransformTo(drawable.PopulateTransform(new TransformBlendingParameters(), newValue, delay)); - } - - public class TransformBlendingParameters : Transform - { - private BlendingParameters valueAt(double time) - => time < EndTime ? StartValue : EndValue; - - public override string TargetMember => nameof(Drawable.Blending); - - protected override void Apply(Drawable d, double time) => d.Blending = valueAt(time); - protected override void ReadIntoStartValue(Drawable d) => StartValue = d.Blending; - } -} diff --git a/osu.Game/Storyboards/Drawables/IFlippable.cs b/osu.Game/Storyboards/Drawables/IFlippable.cs index 165b3d97cc..2a931875ea 100644 --- a/osu.Game/Storyboards/Drawables/IFlippable.cs +++ b/osu.Game/Storyboards/Drawables/IFlippable.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; namespace osu.Game.Storyboards.Drawables @@ -11,45 +10,4 @@ namespace osu.Game.Storyboards.Drawables bool FlipH { get; set; } bool FlipV { get; set; } } - - internal class TransformFlipH : Transform - { - private bool valueAt(double time) - => time < EndTime ? StartValue : EndValue; - - public override string TargetMember => nameof(IFlippable.FlipH); - - protected override void Apply(IFlippable d, double time) => d.FlipH = valueAt(time); - protected override void ReadIntoStartValue(IFlippable d) => StartValue = d.FlipH; - } - - internal class TransformFlipV : Transform - { - private bool valueAt(double time) - => time < EndTime ? StartValue : EndValue; - - public override string TargetMember => nameof(IFlippable.FlipV); - - protected override void Apply(IFlippable d, double time) => d.FlipV = valueAt(time); - protected override void ReadIntoStartValue(IFlippable d) => StartValue = d.FlipV; - } - - internal static class FlippableExtensions - { - /// - /// Adjusts after a delay. - /// - /// A to which further transforms can be added. - public static TransformSequence TransformFlipH(this T flippable, bool newValue, double delay = 0) - where T : class, IFlippable - => flippable.TransformTo(flippable.PopulateTransform(new TransformFlipH(), newValue, delay)); - - /// - /// Adjusts after a delay. - /// - /// A to which further transforms can be added. - public static TransformSequence TransformFlipV(this T flippable, bool newValue, double delay = 0) - where T : class, IFlippable - => flippable.TransformTo(flippable.PopulateTransform(new TransformFlipV(), newValue, delay)); - } } diff --git a/osu.Game/Storyboards/Drawables/IVectorScalable.cs b/osu.Game/Storyboards/Drawables/IVectorScalable.cs index 60a297e126..ab0452df80 100644 --- a/osu.Game/Storyboards/Drawables/IVectorScalable.cs +++ b/osu.Game/Storyboards/Drawables/IVectorScalable.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; using osuTK; @@ -11,11 +10,4 @@ namespace osu.Game.Storyboards.Drawables { Vector2 VectorScale { get; set; } } - - internal static class VectorScalableExtensions - { - public static TransformSequence VectorScaleTo(this T target, Vector2 newVectorScale, double duration = 0, Easing easing = Easing.None) - where T : class, IVectorScalable - => target.TransformTo(nameof(IVectorScalable.VectorScale), newVectorScale, duration, easing); - } } From 4a7635e488169bf09dbcdfc7bf4da489a82d2b1c Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 3 Mar 2024 23:04:06 +0300 Subject: [PATCH 04/38] Fix broken tests --- osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs index dadf3ca65f..dae3119ea4 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs @@ -73,9 +73,9 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); // these should be ignored as we have an alpha visibility blocker proceeding this command. - sprite.TimelineGroup.Scale.Add(Easing.None, loop_start_time, -18000, 0, 1); + sprite.TimelineGroup.Scale.Add(Easing.None, loop_start_time, -18000, Vector2.Zero, Vector2.One); var loopGroup = sprite.AddLoop(loop_start_time, 50); - loopGroup.Scale.Add(Easing.None, loop_start_time, -18000, 0, 1); + loopGroup.Scale.Add(Easing.None, loop_start_time, -18000, Vector2.Zero, Vector2.One); var target = addEventToLoop ? loopGroup : sprite.TimelineGroup; double loopRelativeOffset = addEventToLoop ? -loop_start_time : 0; From 8b03acd27bdbdd6a997dbd70a00a7b4568e6b8bc Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 6 Mar 2024 00:05:56 +0300 Subject: [PATCH 05/38] Implement StoryboardElementWithDuration --- .../Formats/LegacyStoryboardDecoder.cs | 2 +- osu.Game/Storyboards/CommandLoop.cs | 1 + osu.Game/Storyboards/CommandTimeline.cs | 4 +- osu.Game/Storyboards/CommandTimelineGroup.cs | 9 +- .../Drawables/DrawableStoryboardAnimation.cs | 2 +- .../Drawables/DrawableStoryboardSprite.cs | 2 +- ...pable.cs => IDrawableStoryboardElement.cs} | 6 +- .../Storyboards/Drawables/IVectorScalable.cs | 13 - osu.Game/Storyboards/StoryboardAnimation.cs | 5 +- .../StoryboardElementWithDuration.cs | 261 +++++++++++++++ osu.Game/Storyboards/StoryboardSprite.cs | 297 +----------------- 11 files changed, 284 insertions(+), 318 deletions(-) rename osu.Game/Storyboards/Drawables/{IFlippable.cs => IDrawableStoryboardElement.cs} (54%) delete mode 100644 osu.Game/Storyboards/Drawables/IVectorScalable.cs create mode 100644 osu.Game/Storyboards/StoryboardElementWithDuration.cs diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index a9a4d9cc49..ba328b2dbd 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps.Formats { public class LegacyStoryboardDecoder : LegacyDecoder { - private StoryboardSprite? storyboardSprite; + private StoryboardElementWithDuration? storyboardSprite; private CommandTimelineGroup? timelineGroup; private Storyboard storyboard = null!; diff --git a/osu.Game/Storyboards/CommandLoop.cs b/osu.Game/Storyboards/CommandLoop.cs index a912daea44..6dd782cb7f 100644 --- a/osu.Game/Storyboards/CommandLoop.cs +++ b/osu.Game/Storyboards/CommandLoop.cs @@ -50,6 +50,7 @@ namespace osu.Game.Storyboards StartValue = command.StartValue, EndValue = command.EndValue, PropertyName = command.PropertyName, + IsParameterCommand = command.IsParameterCommand, LoopCount = TotalIterations, Delay = fullLoopDuration - command.EndTime + command.StartTime }; diff --git a/osu.Game/Storyboards/CommandTimeline.cs b/osu.Game/Storyboards/CommandTimeline.cs index ce25bfe25b..4ad31d88c2 100644 --- a/osu.Game/Storyboards/CommandTimeline.cs +++ b/osu.Game/Storyboards/CommandTimeline.cs @@ -25,6 +25,7 @@ namespace osu.Game.Storyboards public T EndValue { get; private set; } public string PropertyName { get; } + public bool IsParameterTimeline { get; set; } public CommandTimeline(string propertyName) { @@ -38,7 +39,7 @@ namespace osu.Game.Storyboards endTime = startTime; } - commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName }); + commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName, IsParameterCommand = IsParameterTimeline }); if (startTime < StartTime) { @@ -65,6 +66,7 @@ namespace osu.Game.Storyboards public string PropertyName { get; set; } public int LoopCount { get; set; } public double Delay { get; set; } + public bool IsParameterCommand { get; set; } public T StartValue; public T EndValue; diff --git a/osu.Game/Storyboards/CommandTimelineGroup.cs b/osu.Game/Storyboards/CommandTimelineGroup.cs index cb795e0ffe..0362925619 100644 --- a/osu.Game/Storyboards/CommandTimelineGroup.cs +++ b/osu.Game/Storyboards/CommandTimelineGroup.cs @@ -22,9 +22,9 @@ namespace osu.Game.Storyboards public CommandTimeline Rotation = new CommandTimeline("Rotation"); public CommandTimeline Colour = new CommandTimeline("Colour"); public CommandTimeline Alpha = new CommandTimeline("Alpha"); - public CommandTimeline BlendingParameters = new CommandTimeline("Blending"); - public CommandTimeline FlipH = new CommandTimeline("FlipH"); - public CommandTimeline FlipV = new CommandTimeline("FlipV"); + public CommandTimeline BlendingParameters = new CommandTimeline("Blending") { IsParameterTimeline = true }; + public CommandTimeline FlipH = new CommandTimeline("FlipH") { IsParameterTimeline = true }; + public CommandTimeline FlipV = new CommandTimeline("FlipV") { IsParameterTimeline = true }; private readonly ICommandTimeline[] timelines; @@ -109,7 +109,8 @@ namespace osu.Game.Storyboards EndTime = offset + command.EndTime, StartValue = command.StartValue, EndValue = command.EndValue, - PropertyName = command.PropertyName + PropertyName = command.PropertyName, + IsParameterCommand = command.IsParameterCommand }); } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs index fae9ec7f2e..8e1a8ce949 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs @@ -16,7 +16,7 @@ using osuTK; namespace osu.Game.Storyboards.Drawables { - public partial class DrawableStoryboardAnimation : TextureAnimation, IFlippable, IVectorScalable + public partial class DrawableStoryboardAnimation : TextureAnimation, IDrawableStoryboardElement { public StoryboardAnimation Animation { get; } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs index ec875219b6..6772178e85 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs @@ -13,7 +13,7 @@ using osuTK; namespace osu.Game.Storyboards.Drawables { - public partial class DrawableStoryboardSprite : Sprite, IFlippable, IVectorScalable + public partial class DrawableStoryboardSprite : Sprite, IDrawableStoryboardElement { public StoryboardSprite Sprite { get; } diff --git a/osu.Game/Storyboards/Drawables/IFlippable.cs b/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs similarity index 54% rename from osu.Game/Storyboards/Drawables/IFlippable.cs rename to osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs index 2a931875ea..6652b5509c 100644 --- a/osu.Game/Storyboards/Drawables/IFlippable.cs +++ b/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs @@ -1,13 +1,15 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics.Transforms; +using osuTK; namespace osu.Game.Storyboards.Drawables { - internal interface IFlippable : ITransformable + public interface IDrawableStoryboardElement : ITransformable { bool FlipH { get; set; } bool FlipV { get; set; } + Vector2 VectorScale { get; set; } } } diff --git a/osu.Game/Storyboards/Drawables/IVectorScalable.cs b/osu.Game/Storyboards/Drawables/IVectorScalable.cs deleted file mode 100644 index ab0452df80..0000000000 --- a/osu.Game/Storyboards/Drawables/IVectorScalable.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Graphics.Transforms; -using osuTK; - -namespace osu.Game.Storyboards.Drawables -{ - internal interface IVectorScalable : ITransformable - { - Vector2 VectorScale { get; set; } - } -} diff --git a/osu.Game/Storyboards/StoryboardAnimation.cs b/osu.Game/Storyboards/StoryboardAnimation.cs index 1a4b6bb923..173acf7ff1 100644 --- a/osu.Game/Storyboards/StoryboardAnimation.cs +++ b/osu.Game/Storyboards/StoryboardAnimation.cs @@ -7,7 +7,7 @@ using osu.Game.Storyboards.Drawables; namespace osu.Game.Storyboards { - public class StoryboardAnimation : StoryboardSprite + public class StoryboardAnimation : StoryboardElementWithDuration { public int FrameCount; public double FrameDelay; @@ -21,8 +21,7 @@ namespace osu.Game.Storyboards LoopType = loopType; } - public override Drawable CreateDrawable() - => new DrawableStoryboardAnimation(this); + public override DrawableStoryboardAnimation CreateStoryboardDrawable() => new DrawableStoryboardAnimation(this); } public enum AnimationLoopType diff --git a/osu.Game/Storyboards/StoryboardElementWithDuration.cs b/osu.Game/Storyboards/StoryboardElementWithDuration.cs new file mode 100644 index 0000000000..0c89b40c36 --- /dev/null +++ b/osu.Game/Storyboards/StoryboardElementWithDuration.cs @@ -0,0 +1,261 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Graphics; +using osu.Game.Storyboards.Drawables; +using osuTK; + +namespace osu.Game.Storyboards +{ + public abstract class StoryboardElementWithDuration : IStoryboardElementWithDuration + { + protected readonly List Loops = new List(); + private readonly List triggers = new List(); + + public string Path { get; } + public bool IsDrawable => HasCommands; + + public Anchor Origin; + public Vector2 InitialPosition; + + public readonly CommandTimelineGroup TimelineGroup = new CommandTimelineGroup(); + + public double StartTime + { + get + { + // To get the initial start time, we need to check whether the first alpha command to exist (across all loops) has a StartValue of zero. + // A StartValue of zero governs, above all else, the first valid display time of a sprite. + // + // You can imagine that the first command of each type decides that type's start value, so if the initial alpha is zero, + // anything before that point can be ignored (the sprite is not visible after all). + var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); + + var command = TimelineGroup.Alpha.Commands.FirstOrDefault(); + if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); + + foreach (var loop in Loops) + { + command = loop.Alpha.Commands.FirstOrDefault(); + if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); + } + + if (alphaCommands.Count > 0) + { + var firstAlpha = alphaCommands.MinBy(t => t.startTime); + + if (firstAlpha.isZeroStartValue) + return firstAlpha.startTime; + } + + return EarliestTransformTime; + } + } + + public double EarliestTransformTime + { + get + { + // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. + // The sprite's StartTime will be determined by the earliest command, regardless of type. + double earliestStartTime = TimelineGroup.StartTime; + foreach (var l in Loops) + earliestStartTime = Math.Min(earliestStartTime, l.StartTime); + return earliestStartTime; + } + } + + public double EndTime + { + get + { + double latestEndTime = TimelineGroup.EndTime; + + foreach (var l in Loops) + latestEndTime = Math.Max(latestEndTime, l.EndTime); + + return latestEndTime; + } + } + + public double EndTimeForDisplay + { + get + { + double latestEndTime = TimelineGroup.EndTime; + + foreach (var l in Loops) + latestEndTime = Math.Max(latestEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations); + + return latestEndTime; + } + } + + public bool HasCommands => TimelineGroup.HasCommands || Loops.Any(l => l.HasCommands); + + protected StoryboardElementWithDuration(string path, Anchor origin, Vector2 initialPosition) + { + Path = path; + Origin = origin; + InitialPosition = initialPosition; + } + + public abstract Drawable CreateDrawable(); + + public CommandLoop AddLoop(double startTime, int repeatCount) + { + var loop = new CommandLoop(startTime, repeatCount); + Loops.Add(loop); + return loop; + } + + public CommandTrigger AddTrigger(string triggerName, double startTime, double endTime, int groupNumber) + { + var trigger = new CommandTrigger(triggerName, startTime, endTime, groupNumber); + triggers.Add(trigger); + return trigger; + } + + protected IEnumerable.TypedCommand> GetCommands(CommandTimelineSelector timelineSelector, IEnumerable>? triggeredGroups) + { + var commands = TimelineGroup.GetCommands(timelineSelector); + foreach (var loop in Loops) + commands = commands.Concat(loop.GetCommands(timelineSelector)); + + if (triggeredGroups != null) + { + foreach (var pair in triggeredGroups) + commands = commands.Concat(pair.Item1.GetCommands(timelineSelector, pair.Item2)); + } + + return commands; + } + + public override string ToString() + => $"{Path}, {Origin}, {InitialPosition}"; + } + + public abstract class StoryboardElementWithDuration : StoryboardElementWithDuration + where U : Drawable, IDrawableStoryboardElement + { + private delegate void DrawablePropertyInitializer(U drawable, T value); + + protected StoryboardElementWithDuration(string path, Anchor origin, Vector2 initialPosition) + : base(path, origin, initialPosition) + { + } + + public override Drawable CreateDrawable() => CreateStoryboardDrawable(); + + public abstract U CreateStoryboardDrawable(); + + public void ApplyTransforms(U drawable, IEnumerable>? triggeredGroups = null) + { + // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. + // To achieve this, commands are "generated" as pairs of (command, initFunc, transformFunc) and batched into a contiguous list + // The list is then stably-sorted (to preserve command order), and applied to the drawable sequentially. + + List> generated = new List>(); + + generateCommands(generated, GetCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); + generateCommands(generated, GetCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); + generateCommands(generated, GetCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); + generateCommands(generated, GetCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); + generateCommands(generated, GetCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); + generateCommands(generated, GetCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); + generateCommands(generated, GetCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); + generateCommands(generated, GetCommands(g => g.VectorScale, triggeredGroups), (d, value) => d.VectorScale = value); + generateCommands(generated, GetCommands(g => g.FlipH, triggeredGroups), (d, value) => d.FlipH = value, false); + generateCommands(generated, GetCommands(g => g.FlipV, triggeredGroups), (d, value) => d.FlipV = value, false); + + foreach (var command in generated.OrderBy(g => g.StartTime)) + command.ApplyTo(drawable); + } + + private void generateCommands(List> resultList, IEnumerable.TypedCommand> commands, + DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) + { + bool initialized = false; + + foreach (var command in commands) + { + DrawablePropertyInitializer? initFunc = null; + + if (!initialized) + { + if (alwaysInitialize || command.StartTime == command.EndTime) + initFunc = initializeProperty; + initialized = true; + } + + resultList.Add(new GeneratedCommand(command, initFunc)); + } + } + + private interface IGeneratedCommand + where TDrawable : U + { + double StartTime { get; } + + void ApplyTo(TDrawable drawable); + } + + private readonly struct GeneratedCommand : IGeneratedCommand + where TDrawable : U + { + public double StartTime => command.StartTime; + + private readonly DrawablePropertyInitializer? initializeProperty; + private readonly CommandTimeline.TypedCommand command; + + public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) + { + this.command = command; + this.initializeProperty = initializeProperty; + } + + public void ApplyTo(TDrawable drawable) + { + initializeProperty?.Invoke(drawable, command.StartValue); + + using (drawable.BeginAbsoluteSequence(command.StartTime)) + transform(drawable); + } + + private void transform(TDrawable drawable) + { + if (command.IsParameterCommand) + { + if (command.LoopCount == 0) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue); + } + else + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue) + .Loop(command.Delay, command.LoopCount); + } + } + else + { + if (command.LoopCount == 0) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + else + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) + .Loop(command.Delay, command.LoopCount); + } + } + } + } + } +} diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 2c04e4c983..69994f77a4 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -1,308 +1,21 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; -using System.Collections.Generic; -using System.Linq; using osu.Framework.Graphics; using osu.Game.Storyboards.Drawables; using osuTK; namespace osu.Game.Storyboards { - public class StoryboardSprite : IStoryboardElementWithDuration + public class StoryboardSprite : StoryboardElementWithDuration { - private readonly List loops = new List(); - private readonly List triggers = new List(); - - public string Path { get; } - public bool IsDrawable => HasCommands; - - public Anchor Origin; - public Vector2 InitialPosition; - - public readonly CommandTimelineGroup TimelineGroup = new CommandTimelineGroup(); - - public double StartTime - { - get - { - // To get the initial start time, we need to check whether the first alpha command to exist (across all loops) has a StartValue of zero. - // A StartValue of zero governs, above all else, the first valid display time of a sprite. - // - // You can imagine that the first command of each type decides that type's start value, so if the initial alpha is zero, - // anything before that point can be ignored (the sprite is not visible after all). - var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); - - var command = TimelineGroup.Alpha.Commands.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); - - foreach (var loop in loops) - { - command = loop.Alpha.Commands.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); - } - - if (alphaCommands.Count > 0) - { - var firstAlpha = alphaCommands.MinBy(t => t.startTime); - - if (firstAlpha.isZeroStartValue) - return firstAlpha.startTime; - } - - return EarliestTransformTime; - } - } - - public double EarliestTransformTime - { - get - { - // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. - // The sprite's StartTime will be determined by the earliest command, regardless of type. - double earliestStartTime = TimelineGroup.StartTime; - foreach (var l in loops) - earliestStartTime = Math.Min(earliestStartTime, l.StartTime); - return earliestStartTime; - } - } - - public double EndTime - { - get - { - double latestEndTime = TimelineGroup.EndTime; - - foreach (var l in loops) - latestEndTime = Math.Max(latestEndTime, l.EndTime); - - return latestEndTime; - } - } - - public double EndTimeForDisplay - { - get - { - double latestEndTime = TimelineGroup.EndTime; - - foreach (var l in loops) - latestEndTime = Math.Max(latestEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations); - - return latestEndTime; - } - } - - public bool HasCommands => TimelineGroup.HasCommands || loops.Any(l => l.HasCommands); - - private delegate void DrawablePropertyInitializer(Drawable drawable, T value); - public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) + : base(path, origin, initialPosition) { - Path = path; - Origin = origin; - InitialPosition = initialPosition; } - public CommandLoop AddLoop(double startTime, int repeatCount) - { - var loop = new CommandLoop(startTime, repeatCount); - loops.Add(loop); - return loop; - } - - public CommandTrigger AddTrigger(string triggerName, double startTime, double endTime, int groupNumber) - { - var trigger = new CommandTrigger(triggerName, startTime, endTime, groupNumber); - triggers.Add(trigger); - return trigger; - } - - public virtual Drawable CreateDrawable() - => new DrawableStoryboardSprite(this); - - public void ApplyTransforms(Drawable drawable, IEnumerable>? triggeredGroups = null) - { - // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. - // To achieve this, commands are "generated" as pairs of (command, initFunc, transformFunc) and batched into a contiguous list - // The list is then stably-sorted (to preserve command order), and applied to the drawable sequentially. - - List generated = new List(); - - generateCommands(generated, getCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); - generateCommands(generated, getCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); - generateCommands(generated, getCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); - generateCommands(generated, getCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); - generateCommands(generated, getCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); - generateCommands(generated, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); - generateCommands(generated, getCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); - - if (drawable is IVectorScalable vectorScalable) - { - generateCommands(generated, getCommands(g => g.VectorScale, triggeredGroups), (_, value) => vectorScalable.VectorScale = value); - } - - if (drawable is IFlippable flippable) - { - generateCommands(generated, getCommands(g => g.FlipH, triggeredGroups), (_, value) => flippable.FlipH = value, false); - generateCommands(generated, getCommands(g => g.FlipV, triggeredGroups), (_, value) => flippable.FlipV = value, false); - } - - foreach (var command in generated.OrderBy(g => g.StartTime)) - command.ApplyTo(drawable); - } - - private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, - DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) - { - bool initialized = false; - - foreach (var command in commands) - { - DrawablePropertyInitializer? initFunc = null; - - if (!initialized) - { - if (alwaysInitialize || command.StartTime == command.EndTime) - initFunc = initializeProperty; - initialized = true; - } - - resultList.Add(new GeneratedCommand(command, initFunc)); - } - } - - private IEnumerable.TypedCommand> getCommands(CommandTimelineSelector timelineSelector, IEnumerable>? triggeredGroups) - { - var commands = TimelineGroup.GetCommands(timelineSelector); - foreach (var loop in loops) - commands = commands.Concat(loop.GetCommands(timelineSelector)); - - if (triggeredGroups != null) - { - foreach (var pair in triggeredGroups) - commands = commands.Concat(pair.Item1.GetCommands(timelineSelector, pair.Item2)); - } - - return commands; - } - - public override string ToString() - => $"{Path}, {Origin}, {InitialPosition}"; - - private interface IGeneratedCommand - { - double StartTime { get; } - - void ApplyTo(Drawable drawable); - } - - private readonly struct GeneratedCommand : IGeneratedCommand - { - public double StartTime => command.StartTime; - - private readonly DrawablePropertyInitializer? initializeProperty; - private readonly CommandTimeline.TypedCommand command; - - public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) - { - this.command = command; - this.initializeProperty = initializeProperty; - } - - public void ApplyTo(Drawable drawable) - { - initializeProperty?.Invoke(drawable, command.StartValue); - - switch (command.PropertyName) - { - case "VectorScale": - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - - case "FlipH": - case "FlipV": - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - - case "Blending": - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - - default: - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - } - } - } + public override DrawableStoryboardSprite CreateStoryboardDrawable() => new DrawableStoryboardSprite(this); } } + + From 1c8ede854d5ba97deafeea83abee96c61cb367bb Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 6 Mar 2024 00:17:56 +0300 Subject: [PATCH 06/38] Remove blank lines --- osu.Game/Storyboards/StoryboardSprite.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 69994f77a4..8eaab9428d 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -17,5 +17,3 @@ namespace osu.Game.Storyboards public override DrawableStoryboardSprite CreateStoryboardDrawable() => new DrawableStoryboardSprite(this); } } - - From 07392a4d3eb7ff9c08c863d0aaf27cb33161dac7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 6 Mar 2024 01:10:22 +0300 Subject: [PATCH 07/38] Further simplify transform application --- .../StoryboardElementWithDuration.cs | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/osu.Game/Storyboards/StoryboardElementWithDuration.cs b/osu.Game/Storyboards/StoryboardElementWithDuration.cs index 0c89b40c36..06924a26ef 100644 --- a/osu.Game/Storyboards/StoryboardElementWithDuration.cs +++ b/osu.Game/Storyboards/StoryboardElementWithDuration.cs @@ -222,38 +222,13 @@ namespace osu.Game.Storyboards initializeProperty?.Invoke(drawable, command.StartValue); using (drawable.BeginAbsoluteSequence(command.StartTime)) - transform(drawable); - } + { + var sequence = command.IsParameterCommand + ? drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue) + : drawable.TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - private void transform(TDrawable drawable) - { - if (command.IsParameterCommand) - { - if (command.LoopCount == 0) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue); - } - else - { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue) - .Loop(command.Delay, command.LoopCount); - } - } - else - { - if (command.LoopCount == 0) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - } - else - { - drawable.TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) - .Loop(command.Delay, command.LoopCount); - } + if (command.LoopCount > 0) + sequence.Loop(command.Delay, command.LoopCount); } } } From 585ab5976877281be70cb6f52721382c5a86a861 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 6 Mar 2024 19:39:28 +0300 Subject: [PATCH 08/38] Apply major refactor to the storyboard commands flow structrure --- .../TestSceneDrawableStoryboardSprite.cs | 3 +- .../Visual/Gameplay/TestSceneLeadIn.cs | 16 +- .../Gameplay/TestSceneStoryboardWithOutro.cs | 2 +- .../TestSceneMultiSpectatorScreen.cs | 2 +- .../Formats/LegacyStoryboardDecoder.cs | 39 +-- osu.Game/Storyboards/CommandLoop.cs | 63 ----- osu.Game/Storyboards/CommandTimeline.cs | 101 -------- osu.Game/Storyboards/CommandTimelineGroup.cs | 120 --------- .../Commands/IStoryboardCommand.cs | 28 +++ .../Commands/StoryboardAlphaCommand.cs | 19 ++ .../StoryboardBlendingParametersCommand.cs | 21 ++ .../Commands/StoryboardColourCommand.cs | 20 ++ .../Storyboards/Commands/StoryboardCommand.cs | 54 ++++ .../Commands/StoryboardCommandGroup.cs | 115 +++++++++ .../Commands/StoryboardCommandList.cs | 41 +++ .../Commands/StoryboardFlipHCommand.cs | 23 ++ .../Commands/StoryboardFlipVCommand.cs | 23 ++ .../Commands/StoryboardLoopingGroup.cs | 71 ++++++ .../Commands/StoryboardRotationCommand.cs | 21 ++ .../Commands/StoryboardScaleCommand.cs | 22 ++ .../StoryboardTriggerGroup.cs} | 7 +- .../Commands/StoryboardVectorScaleCommand.cs | 24 ++ .../Commands/StoryboardXCommand.cs | 21 ++ .../Commands/StoryboardYCommand.cs | 21 ++ .../Drawables/IDrawableStoryboardElement.cs | 4 +- osu.Game/Storyboards/StoryboardAnimation.cs | 4 +- .../StoryboardElementWithDuration.cs | 236 ------------------ osu.Game/Storyboards/StoryboardSprite.cs | 153 +++++++++++- 28 files changed, 713 insertions(+), 561 deletions(-) delete mode 100644 osu.Game/Storyboards/CommandLoop.cs delete mode 100644 osu.Game/Storyboards/CommandTimeline.cs delete mode 100644 osu.Game/Storyboards/CommandTimelineGroup.cs create mode 100644 osu.Game/Storyboards/Commands/IStoryboardCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardColourCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardCommandList.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs rename osu.Game/Storyboards/{CommandTrigger.cs => Commands/StoryboardTriggerGroup.cs} (68%) create mode 100644 osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardXCommand.cs create mode 100644 osu.Game/Storyboards/Commands/StoryboardYCommand.cs delete mode 100644 osu.Game/Storyboards/StoryboardElementWithDuration.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs index 32693c2bb2..6209b42cbb 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs @@ -175,7 +175,8 @@ namespace osu.Game.Tests.Visual.Gameplay var layer = storyboard.GetLayer("Background"); var sprite = new StoryboardSprite(lookupName, origin, initialPosition); - sprite.AddLoop(Time.Current, 100).Alpha.Add(Easing.None, 0, 10000, 1, 1); + var loop = sprite.AddLoopingGroup(Time.Current, 100); + loop.AddAlpha(0, 10000, 1, 1, Easing.None); layer.Elements.Clear(); layer.Add(sprite); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs index dae3119ea4..c3eef4da9b 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs @@ -47,7 +47,7 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.TimelineGroup.Alpha.Add(Easing.None, firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1); + sprite.Group.AddAlpha(firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1, Easing.None); storyboard.GetLayer("Background").Add(sprite); @@ -73,17 +73,17 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); // these should be ignored as we have an alpha visibility blocker proceeding this command. - sprite.TimelineGroup.Scale.Add(Easing.None, loop_start_time, -18000, Vector2.Zero, Vector2.One); - var loopGroup = sprite.AddLoop(loop_start_time, 50); - loopGroup.Scale.Add(Easing.None, loop_start_time, -18000, Vector2.Zero, Vector2.One); + sprite.Group.AddScale(loop_start_time, -18000, 0, 1, Easing.None); + var loopGroup = sprite.AddLoopingGroup(loop_start_time, 50); + loopGroup.AddScale(loop_start_time, -18000, 0, 1, Easing.None); - var target = addEventToLoop ? loopGroup : sprite.TimelineGroup; + var target = addEventToLoop ? loopGroup : sprite.Group; double loopRelativeOffset = addEventToLoop ? -loop_start_time : 0; - target.Alpha.Add(Easing.None, loopRelativeOffset + firstStoryboardEvent, loopRelativeOffset + firstStoryboardEvent + 500, 0, 1); + target.AddAlpha(loopRelativeOffset + firstStoryboardEvent, loopRelativeOffset + firstStoryboardEvent + 500, 0, 1, Easing.None); // these should be ignored due to being in the future. - sprite.TimelineGroup.Alpha.Add(Easing.None, 18000, 20000, 0, 1); - loopGroup.Alpha.Add(Easing.None, 38000, 40000, 0, 1); + sprite.Group.AddAlpha(18000, 20000, 0, 1, Easing.None); + loopGroup.AddAlpha(38000, 40000, 0, 1, Easing.None); storyboard.GetLayer("Background").Add(sprite); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs index f532921d63..9269c3f4ae 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs @@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.Gameplay { var storyboard = new Storyboard(); var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.TimelineGroup.Alpha.Add(Easing.None, 0, duration, 1, 0); + sprite.Group.AddAlpha(0, duration, 1, 0, Easing.None); storyboard.GetLayer("Background").Add(sprite); return storyboard; } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs index cebc75f90c..62a2bfeaab 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs @@ -424,7 +424,7 @@ namespace osu.Game.Tests.Visual.Multiplayer public void TestIntroStoryboardElement() => testLeadIn(b => { var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.TimelineGroup.Alpha.Add(Easing.None, -2000, 0, 0, 1); + sprite.Group.AddAlpha(-2000, 0, 0, 1, Easing.None); b.Storyboard.GetLayer("Background").Add(sprite); }); diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index ba328b2dbd..33cdaa085e 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -10,6 +10,7 @@ using osu.Framework.Utils; using osu.Game.Beatmaps.Legacy; using osu.Game.IO; using osu.Game.Storyboards; +using osu.Game.Storyboards.Commands; using osuTK; using osuTK.Graphics; @@ -17,8 +18,8 @@ namespace osu.Game.Beatmaps.Formats { public class LegacyStoryboardDecoder : LegacyDecoder { - private StoryboardElementWithDuration? storyboardSprite; - private CommandTimelineGroup? timelineGroup; + private StoryboardSprite? storyboardSprite; + private StoryboardCommandGroup? currentGroup; private Storyboard storyboard = null!; @@ -165,7 +166,7 @@ namespace osu.Game.Beatmaps.Formats else { if (depth < 2) - timelineGroup = storyboardSprite?.TimelineGroup; + currentGroup = storyboardSprite?.Group; string commandType = split[0]; @@ -177,7 +178,7 @@ namespace osu.Game.Beatmaps.Formats double startTime = split.Length > 2 ? Parsing.ParseDouble(split[2]) : double.MinValue; double endTime = split.Length > 3 ? Parsing.ParseDouble(split[3]) : double.MaxValue; int groupNumber = split.Length > 4 ? Parsing.ParseInt(split[4]) : 0; - timelineGroup = storyboardSprite?.AddTrigger(triggerName, startTime, endTime, groupNumber); + currentGroup = storyboardSprite?.AddTriggerGroup(triggerName, startTime, endTime, groupNumber); break; } @@ -185,7 +186,7 @@ namespace osu.Game.Beatmaps.Formats { double startTime = Parsing.ParseDouble(split[1]); int repeatCount = Parsing.ParseInt(split[2]); - timelineGroup = storyboardSprite?.AddLoop(startTime, Math.Max(0, repeatCount - 1)); + currentGroup = storyboardSprite?.AddLoopingGroup(startTime, Math.Max(0, repeatCount - 1)); break; } @@ -204,7 +205,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.Alpha.Add(easing, startTime, endTime, startValue, endValue); + currentGroup?.AddAlpha(startTime, endTime, startValue, endValue, easing); break; } @@ -212,7 +213,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.Scale.Add(easing, startTime, endTime, new Vector2(startValue), new Vector2(endValue)); + currentGroup?.AddScale(startTime, endTime, startValue, endValue, easing); break; } @@ -222,7 +223,7 @@ namespace osu.Game.Beatmaps.Formats float startY = Parsing.ParseFloat(split[5]); float endX = split.Length > 6 ? Parsing.ParseFloat(split[6]) : startX; float endY = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startY; - timelineGroup?.VectorScale.Add(easing, startTime, endTime, new Vector2(startX, startY), new Vector2(endX, endY)); + currentGroup?.AddVectorScale(startTime, endTime, new Vector2(startX, startY), new Vector2(endX, endY), easing); break; } @@ -230,7 +231,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.Rotation.Add(easing, startTime, endTime, MathUtils.RadiansToDegrees(startValue), MathUtils.RadiansToDegrees(endValue)); + currentGroup?.AddRotation(startTime, endTime, MathUtils.RadiansToDegrees(startValue), MathUtils.RadiansToDegrees(endValue), easing); break; } @@ -240,8 +241,8 @@ namespace osu.Game.Beatmaps.Formats float startY = Parsing.ParseFloat(split[5]); float endX = split.Length > 6 ? Parsing.ParseFloat(split[6]) : startX; float endY = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startY; - timelineGroup?.X.Add(easing, startTime, endTime, startX, endX); - timelineGroup?.Y.Add(easing, startTime, endTime, startY, endY); + currentGroup?.AddX(startTime, endTime, startX, endX, easing); + currentGroup?.AddY(startTime, endTime, startY, endY, easing); break; } @@ -249,7 +250,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.X.Add(easing, startTime, endTime, startValue, endValue); + currentGroup?.AddX(startTime, endTime, startValue, endValue, easing); break; } @@ -257,7 +258,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - timelineGroup?.Y.Add(easing, startTime, endTime, startValue, endValue); + currentGroup?.AddY(startTime, endTime, startValue, endValue, easing); break; } @@ -269,9 +270,9 @@ namespace osu.Game.Beatmaps.Formats float endRed = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startRed; float endGreen = split.Length > 8 ? Parsing.ParseFloat(split[8]) : startGreen; float endBlue = split.Length > 9 ? Parsing.ParseFloat(split[9]) : startBlue; - timelineGroup?.Colour.Add(easing, startTime, endTime, + currentGroup?.AddColour(startTime, endTime, new Color4(startRed / 255f, startGreen / 255f, startBlue / 255f, 1), - new Color4(endRed / 255f, endGreen / 255f, endBlue / 255f, 1)); + new Color4(endRed / 255f, endGreen / 255f, endBlue / 255f, 1), easing); break; } @@ -282,16 +283,16 @@ namespace osu.Game.Beatmaps.Formats switch (type) { case "A": - timelineGroup?.BlendingParameters.Add(easing, startTime, endTime, BlendingParameters.Additive, - startTime == endTime ? BlendingParameters.Additive : BlendingParameters.Inherit); + currentGroup?.AddBlendingParameters(startTime, endTime, BlendingParameters.Additive, + startTime == endTime ? BlendingParameters.Additive : BlendingParameters.Inherit, easing); break; case "H": - timelineGroup?.FlipH.Add(easing, startTime, endTime, true, startTime == endTime); + currentGroup?.AddFlipH(startTime, endTime, true, startTime == endTime, easing); break; case "V": - timelineGroup?.FlipV.Add(easing, startTime, endTime, true, startTime == endTime); + currentGroup?.AddFlipV(startTime, endTime, true, startTime == endTime, easing); break; } diff --git a/osu.Game/Storyboards/CommandLoop.cs b/osu.Game/Storyboards/CommandLoop.cs deleted file mode 100644 index 6dd782cb7f..0000000000 --- a/osu.Game/Storyboards/CommandLoop.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; - -namespace osu.Game.Storyboards -{ - public class CommandLoop : CommandTimelineGroup - { - public double LoopStartTime; - - /// - /// The total number of times this loop is played back. Always greater than zero. - /// - public readonly int TotalIterations; - - public override double StartTime => LoopStartTime + CommandsStartTime; - - public override double EndTime => - // In an ideal world, we would multiply the command duration by TotalIterations here. - // Unfortunately this would clash with how stable handled end times, and results in some storyboards playing outro - // sequences for minutes or hours. - StartTime + CommandsDuration; - - /// - /// Construct a new command loop. - /// - /// The start time of the loop. - /// The number of times the loop should repeat. Should be greater than zero. Zero means a single playback. - public CommandLoop(double startTime, int repeatCount) - { - if (repeatCount < 0) throw new ArgumentException("Repeat count must be zero or above.", nameof(repeatCount)); - - LoopStartTime = startTime; - TotalIterations = repeatCount + 1; - } - - public override IEnumerable.TypedCommand> GetCommands(CommandTimelineSelector timelineSelector, double offset = 0) - { - double fullLoopDuration = CommandsEndTime - CommandsStartTime; - - foreach (var command in timelineSelector(this).Commands) - { - yield return new CommandTimeline.TypedCommand - { - Easing = command.Easing, - StartTime = offset + LoopStartTime + command.StartTime, - EndTime = offset + LoopStartTime + command.EndTime, - StartValue = command.StartValue, - EndValue = command.EndValue, - PropertyName = command.PropertyName, - IsParameterCommand = command.IsParameterCommand, - LoopCount = TotalIterations, - Delay = fullLoopDuration - command.EndTime + command.StartTime - }; - } - } - - public override string ToString() - => $"{LoopStartTime} x{TotalIterations}"; - } -} diff --git a/osu.Game/Storyboards/CommandTimeline.cs b/osu.Game/Storyboards/CommandTimeline.cs deleted file mode 100644 index 4ad31d88c2..0000000000 --- a/osu.Game/Storyboards/CommandTimeline.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -#nullable disable - -using osu.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace osu.Game.Storyboards -{ - public class CommandTimeline : ICommandTimeline - { - private readonly List commands = new List(); - - public IEnumerable Commands => commands.OrderBy(c => c.StartTime); - - public bool HasCommands => commands.Count > 0; - - public double StartTime { get; private set; } = double.MaxValue; - public double EndTime { get; private set; } = double.MinValue; - - public T StartValue { get; private set; } - public T EndValue { get; private set; } - - public string PropertyName { get; } - public bool IsParameterTimeline { get; set; } - - public CommandTimeline(string propertyName) - { - PropertyName = propertyName; - } - - public void Add(Easing easing, double startTime, double endTime, T startValue, T endValue) - { - if (endTime < startTime) - { - endTime = startTime; - } - - commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName, IsParameterCommand = IsParameterTimeline }); - - if (startTime < StartTime) - { - StartValue = startValue; - StartTime = startTime; - } - - if (endTime > EndTime) - { - EndValue = endValue; - EndTime = endTime; - } - } - - public override string ToString() - => $"{commands.Count} command(s)"; - - public class TypedCommand : ICommand - { - public Easing Easing { get; set; } - public double StartTime { get; set; } - public double EndTime { get; set; } - public double Duration => EndTime - StartTime; - public string PropertyName { get; set; } - public int LoopCount { get; set; } - public double Delay { get; set; } - public bool IsParameterCommand { get; set; } - - public T StartValue; - public T EndValue; - - public int CompareTo(ICommand other) - { - int result = StartTime.CompareTo(other.StartTime); - if (result != 0) return result; - - return EndTime.CompareTo(other.EndTime); - } - - public override string ToString() - => $"{StartTime} -> {EndTime}, {StartValue} -> {EndValue} {Easing}"; - } - } - - public interface ICommandTimeline - { - double StartTime { get; } - double EndTime { get; } - bool HasCommands { get; } - } - - public interface ICommand : IComparable - { - Easing Easing { get; set; } - double StartTime { get; set; } - double EndTime { get; set; } - double Duration { get; } - } -} diff --git a/osu.Game/Storyboards/CommandTimelineGroup.cs b/osu.Game/Storyboards/CommandTimelineGroup.cs deleted file mode 100644 index 0362925619..0000000000 --- a/osu.Game/Storyboards/CommandTimelineGroup.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using osuTK; -using osu.Framework.Graphics; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using osu.Framework.Graphics.Colour; - -namespace osu.Game.Storyboards -{ - public delegate CommandTimeline CommandTimelineSelector(CommandTimelineGroup commandTimelineGroup); - - public class CommandTimelineGroup - { - public CommandTimeline X = new CommandTimeline("X"); - public CommandTimeline Y = new CommandTimeline("Y"); - public CommandTimeline Scale = new CommandTimeline("Scale"); - public CommandTimeline VectorScale = new CommandTimeline("VectorScale"); - public CommandTimeline Rotation = new CommandTimeline("Rotation"); - public CommandTimeline Colour = new CommandTimeline("Colour"); - public CommandTimeline Alpha = new CommandTimeline("Alpha"); - public CommandTimeline BlendingParameters = new CommandTimeline("Blending") { IsParameterTimeline = true }; - public CommandTimeline FlipH = new CommandTimeline("FlipH") { IsParameterTimeline = true }; - public CommandTimeline FlipV = new CommandTimeline("FlipV") { IsParameterTimeline = true }; - - private readonly ICommandTimeline[] timelines; - - public CommandTimelineGroup() - { - timelines = new ICommandTimeline[] - { - X, - Y, - Scale, - VectorScale, - Rotation, - Colour, - Alpha, - BlendingParameters, - FlipH, - FlipV - }; - } - - [JsonIgnore] - public double CommandsStartTime - { - get - { - double min = double.MaxValue; - - for (int i = 0; i < timelines.Length; i++) - min = Math.Min(min, timelines[i].StartTime); - - return min; - } - } - - [JsonIgnore] - public double CommandsEndTime - { - get - { - double max = double.MinValue; - - for (int i = 0; i < timelines.Length; i++) - max = Math.Max(max, timelines[i].EndTime); - - return max; - } - } - - [JsonIgnore] - public double CommandsDuration => CommandsEndTime - CommandsStartTime; - - [JsonIgnore] - public virtual double StartTime => CommandsStartTime; - - [JsonIgnore] - public virtual double EndTime => CommandsEndTime; - - [JsonIgnore] - public bool HasCommands - { - get - { - for (int i = 0; i < timelines.Length; i++) - { - if (timelines[i].HasCommands) - return true; - } - - return false; - } - } - - public virtual IEnumerable.TypedCommand> GetCommands(CommandTimelineSelector timelineSelector, double offset = 0) - { - if (offset != 0) - { - return timelineSelector(this).Commands.Select(command => - new CommandTimeline.TypedCommand - { - Easing = command.Easing, - StartTime = offset + command.StartTime, - EndTime = offset + command.EndTime, - StartValue = command.StartValue, - EndValue = command.EndValue, - PropertyName = command.PropertyName, - IsParameterCommand = command.IsParameterCommand - }); - } - - return timelineSelector(this).Commands; - } - } -} diff --git a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs new file mode 100644 index 0000000000..848dcab575 --- /dev/null +++ b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs @@ -0,0 +1,28 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public interface IStoryboardCommand + { + /// + /// The start time of the storyboard command. + /// + double StartTime { get; } + + /// + /// The end time of the storyboard command. + /// + double EndTime { get; } + + /// + /// Applies the transforms described by this storyboard command to the target drawable. + /// + /// The target drawable. + /// The sequence of transforms applied to the target drawable. + TransformSequence ApplyTransform(Drawable d); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs new file mode 100644 index 0000000000..729ecd72a7 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs @@ -0,0 +1,19 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardAlphaCommand : StoryboardCommand + { + public StoryboardAlphaCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.Alpha = StartValue; + public override TransformSequence ApplyTransform(Drawable d) => d.FadeTo(StartValue).Then().FadeTo(EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs new file mode 100644 index 0000000000..cc54909837 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs @@ -0,0 +1,21 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardBlendingParametersCommand : StoryboardCommand + { + public StoryboardBlendingParametersCommand(double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.Blending = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration).TransformTo(nameof(d.Blending), EndValue); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs new file mode 100644 index 0000000000..be56a1d71b --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; +using osuTK.Graphics; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardColourCommand : StoryboardCommand + { + public StoryboardColourCommand(double startTime, double endTime, Color4 startValue, Color4 endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.Colour = StartValue; + public override TransformSequence ApplyTransform(Drawable d) => d.FadeColour(StartValue).Then().FadeColour(EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardCommand.cs b/osu.Game/Storyboards/Commands/StoryboardCommand.cs new file mode 100644 index 0000000000..883b9f57c1 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardCommand.cs @@ -0,0 +1,54 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public abstract class StoryboardCommand : IStoryboardCommand + { + public double StartTime { get; } + public double EndTime { get; } + public double Duration => EndTime - StartTime; + + protected StoryboardCommand(double startTime, double endTime, T startValue, T endValue, Easing easing) + { + if (endTime < startTime) + endTime = startTime; + + StartTime = startTime; + StartValue = startValue; + EndTime = endTime; + EndValue = endValue; + Easing = easing; + } + + public Easing Easing { get; set; } + public int LoopCount { get; set; } + public double Delay { get; set; } + + public T StartValue; + public T EndValue; + + /// + /// Sets the value of the corresponding property in to the start value of this command. + /// + public abstract void SetInitialValue(Drawable d); + + /// + /// Transforms a corresponding property in that corresponds to this command group with the specified parameters. + /// + public abstract TransformSequence ApplyTransform(Drawable d); + + public int CompareTo(IStoryboardCommand other) + { + int result = StartTime.CompareTo(other.StartTime); + if (result != 0) return result; + + return EndTime.CompareTo(other.EndTime); + } + + public override string ToString() => $"{StartTime} -> {EndTime}, {StartValue} -> {EndValue} {Easing}"; + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs new file mode 100644 index 0000000000..02c43c9f60 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs @@ -0,0 +1,115 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using osu.Framework.Graphics; +using osu.Framework.Lists; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardCommandGroup + { + public SortedList> X; + public SortedList> Y; + public SortedList> Scale; + public SortedList> VectorScale; + public SortedList> Rotation; + public SortedList> Colour; + public SortedList> Alpha; + public SortedList> BlendingParameters; + public SortedList> FlipH; + public SortedList> FlipV; + + private readonly IReadOnlyList[] lists; + + /// + /// Returns the earliest start time of the commands added to this group. + /// + [JsonIgnore] + public double StartTime { get; private set; } + + /// + /// Returns the latest end time of the commands added to this group. + /// + [JsonIgnore] + public double EndTime { get; private set; } + + [JsonIgnore] + public double Duration => EndTime - StartTime; + + [JsonIgnore] + public bool HasCommands { get; private set; } + + public StoryboardCommandGroup() + { + lists = new IReadOnlyList[] + { + X = new SortedList>(), + Y = new SortedList>(), + Scale = new SortedList>(), + VectorScale = new SortedList>(), + Rotation = new SortedList>(), + Colour = new SortedList>(), + Alpha = new SortedList>(), + BlendingParameters = new SortedList>(), + FlipH = new SortedList>(), + FlipV = new SortedList>() + }; + } + + /// + /// Returns all commands contained by this group unsorted. + /// + public virtual IEnumerable GetAllCommands() => lists.SelectMany(l => l); + + public void AddX(double startTime, double endTime, float startValue, float endValue, Easing easing) + => AddCommand(X, new StoryboardXCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddY(double startTime, double endTime, float startValue, float endValue, Easing easing) + => AddCommand(Y, new StoryboardYCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddScale(double startTime, double endTime, float startValue, float endValue, Easing easing) + => AddCommand(Scale, new StoryboardScaleCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddVectorScale(double startTime, double endTime, Vector2 startValue, Vector2 endValue, Easing easing) + => AddCommand(VectorScale, new StoryboardVectorScaleCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddRotation(double startTime, double endTime, float startValue, float endValue, Easing easing) + => AddCommand(Rotation, new StoryboardRotationCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddColour(double startTime, double endTime, Color4 startValue, Color4 endValue, Easing easing) + => AddCommand(Colour, new StoryboardColourCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddAlpha(double startTime, double endTime, float startValue, float endValue, Easing easing) + => AddCommand(Alpha, new StoryboardAlphaCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddBlendingParameters(double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue, Easing easing) + => AddCommand(BlendingParameters, new StoryboardBlendingParametersCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddFlipH(double startTime, double endTime, bool startValue, bool endValue, Easing easing) + => AddCommand(FlipH, new StoryboardFlipHCommand(startTime, endTime, startValue, endValue, easing)); + + public void AddFlipV(double startTime, double endTime, bool startValue, bool endValue, Easing easing) + => AddCommand(FlipV, new StoryboardFlipVCommand(startTime, endTime, startValue, endValue, easing)); + + /// + /// Adds the given storyboard to the target . + /// Can be overriden to apply custom effects to the given command before adding it to the list (e.g. looping or time offsets). + /// + /// The value type of the target property affected by this storyboard command. + protected virtual void AddCommand(ICollection> list, StoryboardCommand command) + { + list.Add(command); + + if (command.StartTime < StartTime) + StartTime = command.StartTime; + + if (command.EndTime > EndTime) + EndTime = command.EndTime; + } + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandList.cs b/osu.Game/Storyboards/Commands/StoryboardCommandList.cs new file mode 100644 index 0000000000..67012e9d49 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardCommandList.cs @@ -0,0 +1,41 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Storyboards.Commands +{ + // public class StoryboardCommandList : IStoryboardCommandList + // { + // // todo: change to sorted list and avoid enumerable type on exposed properties? + // private readonly List> commands = new List>(); + // + // public IEnumerable> Commands => commands.OrderBy(c => c.StartTime); + // + // IEnumerable IStoryboardCommandList.Commands => Commands; + // public bool HasCommands => commands.Count > 0; + // + // public double StartTime { get; private set; } = double.MaxValue; + // public double EndTime { get; private set; } = double.MinValue; + // + // public T? StartValue { get; private set; } + // public T? EndValue { get; private set; } + // + // public void Add(StoryboardCommand command) + // { + // commands.Add(command); + // + // if (command.StartTime < StartTime) + // { + // StartValue = command.StartValue; + // StartTime = command.StartTime; + // } + // + // if (command.EndTime > EndTime) + // { + // EndValue = command.EndValue; + // EndTime = command.EndTime; + // } + // } + // + // public override string ToString() => $"{commands.Count} command(s)"; + // } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs new file mode 100644 index 0000000000..9bcb687d3c --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs @@ -0,0 +1,23 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; +using osu.Game.Storyboards.Drawables; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardFlipHCommand : StoryboardCommand + { + public StoryboardFlipHCommand(double startTime, double endTime, bool startValue, bool endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipH = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.TransformTo(nameof(IDrawableStoryboardElement.FlipH), StartValue).Delay(Duration) + .TransformTo(nameof(IDrawableStoryboardElement.FlipH), EndValue); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs new file mode 100644 index 0000000000..9f1f5faa33 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs @@ -0,0 +1,23 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; +using osu.Game.Storyboards.Drawables; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardFlipVCommand : StoryboardCommand + { + public StoryboardFlipVCommand(double startTime, double endTime, bool startValue, bool endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipV = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.TransformTo(nameof(IDrawableStoryboardElement.FlipV), StartValue).Delay(Duration) + .TransformTo(nameof(IDrawableStoryboardElement.FlipV), EndValue); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs new file mode 100644 index 0000000000..e520353bd6 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs @@ -0,0 +1,71 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardLoopingGroup : StoryboardCommandGroup + { + public double LoopStartTime; + + /// + /// The total number of times this loop is played back. Always greater than zero. + /// + public readonly int TotalIterations; + + /// + /// Construct a new command loop. + /// + /// The start time of the loop. + /// The number of times the loop should repeat. Should be greater than zero. Zero means a single playback. + public StoryboardLoopingGroup(double startTime, int repeatCount) + { + if (repeatCount < 0) throw new ArgumentException("Repeat count must be zero or above.", nameof(repeatCount)); + + LoopStartTime = startTime; + TotalIterations = repeatCount + 1; + } + + protected override void AddCommand(ICollection> list, StoryboardCommand command) + { + // todo: this is broke! + double fullLoopDuration = EndTime - StartTime; + double loopDelay = fullLoopDuration - command.EndTime + command.StartTime; + base.AddCommand(list, new StoryboardLoopingCommand(command, LoopStartTime, TotalIterations, loopDelay)); + } + + public override string ToString() => $"{LoopStartTime} x{TotalIterations}"; + + private class StoryboardLoopingCommand : StoryboardCommand + { + private readonly StoryboardCommand command; + private readonly int loopCount; + private readonly double loopDelay; + + public StoryboardLoopingCommand(StoryboardCommand command, double loopStartTime, int loopCount, double loopDelay) + // In an ideal world, we would multiply the command duration by TotalIterations in command end time. + // Unfortunately this would clash with how stable handled end times, and results in some storyboards playing outro + // sequences for minutes or hours. + : base(loopStartTime + command.StartTime, loopStartTime + command.EndTime, command.StartValue, command.EndValue, command.Easing) + { + this.command = command; + this.loopCount = loopCount; + this.loopDelay = loopDelay; + } + + public override void SetInitialValue(Drawable d) => command.SetInitialValue(d); + + public override TransformSequence ApplyTransform(Drawable d) + { + if (loopCount == 0) + return command.ApplyTransform(d); + + return command.ApplyTransform(d).Loop(loopDelay, loopCount); + } + } + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs new file mode 100644 index 0000000000..c56dcd130f --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs @@ -0,0 +1,21 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardRotationCommand : StoryboardCommand + { + public StoryboardRotationCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.Rotation = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.RotateTo(StartValue).Then().RotateTo(EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs new file mode 100644 index 0000000000..9dbdd6ebd8 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs @@ -0,0 +1,22 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; +using osuTK; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardScaleCommand : StoryboardCommand + { + public StoryboardScaleCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.Scale = new Vector2(StartValue); + + public override TransformSequence ApplyTransform(Drawable d) + => d.ScaleTo(StartValue).Then().ScaleTo(EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/CommandTrigger.cs b/osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs similarity index 68% rename from osu.Game/Storyboards/CommandTrigger.cs rename to osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs index 011f345df2..dfb6f8cb1b 100644 --- a/osu.Game/Storyboards/CommandTrigger.cs +++ b/osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs @@ -1,16 +1,17 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -namespace osu.Game.Storyboards +namespace osu.Game.Storyboards.Commands { - public class CommandTrigger : CommandTimelineGroup + // todo: this is not implemented and has never been, keep that in mind. + public class StoryboardTriggerGroup : StoryboardCommandGroup { public string TriggerName; public double TriggerStartTime; public double TriggerEndTime; public int GroupNumber; - public CommandTrigger(string triggerName, double startTime, double endTime, int groupNumber) + public StoryboardTriggerGroup(string triggerName, double startTime, double endTime, int groupNumber) { TriggerName = triggerName; TriggerStartTime = startTime; diff --git a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs new file mode 100644 index 0000000000..fefb21b257 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; +using osu.Game.Storyboards.Drawables; +using osuTK; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardVectorScaleCommand : StoryboardCommand + { + public StoryboardVectorScaleCommand(double startTime, double endTime, Vector2 startValue, Vector2 endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).VectorScale = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.TransformTo(nameof(IDrawableStoryboardElement.VectorScale), StartValue).Then() + .TransformTo(nameof(IDrawableStoryboardElement.VectorScale), EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs new file mode 100644 index 0000000000..a9f9cd4f8f --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs @@ -0,0 +1,21 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardXCommand : StoryboardCommand + { + public StoryboardXCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.X = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.MoveToX(StartValue).Then().MoveToX(EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs new file mode 100644 index 0000000000..eb30b36720 --- /dev/null +++ b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs @@ -0,0 +1,21 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; + +namespace osu.Game.Storyboards.Commands +{ + public class StoryboardYCommand : StoryboardCommand + { + public StoryboardYCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) + : base(startTime, endTime, startValue, endValue, easing) + { + } + + public override void SetInitialValue(Drawable d) => d.Y = StartValue; + + public override TransformSequence ApplyTransform(Drawable d) + => d.MoveToY(StartValue).Then().MoveToY(EndValue, Duration, Easing); + } +} diff --git a/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs b/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs index 6652b5509c..04bae88c76 100644 --- a/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs +++ b/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs @@ -1,12 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics.Transforms; +using osu.Framework.Graphics; using osuTK; namespace osu.Game.Storyboards.Drawables { - public interface IDrawableStoryboardElement : ITransformable + public interface IDrawableStoryboardElement : IDrawable { bool FlipH { get; set; } bool FlipV { get; set; } diff --git a/osu.Game/Storyboards/StoryboardAnimation.cs b/osu.Game/Storyboards/StoryboardAnimation.cs index 173acf7ff1..0b714633c9 100644 --- a/osu.Game/Storyboards/StoryboardAnimation.cs +++ b/osu.Game/Storyboards/StoryboardAnimation.cs @@ -7,7 +7,7 @@ using osu.Game.Storyboards.Drawables; namespace osu.Game.Storyboards { - public class StoryboardAnimation : StoryboardElementWithDuration + public class StoryboardAnimation : StoryboardSprite { public int FrameCount; public double FrameDelay; @@ -21,7 +21,7 @@ namespace osu.Game.Storyboards LoopType = loopType; } - public override DrawableStoryboardAnimation CreateStoryboardDrawable() => new DrawableStoryboardAnimation(this); + public override Drawable CreateDrawable() => new DrawableStoryboardAnimation(this); } public enum AnimationLoopType diff --git a/osu.Game/Storyboards/StoryboardElementWithDuration.cs b/osu.Game/Storyboards/StoryboardElementWithDuration.cs deleted file mode 100644 index 06924a26ef..0000000000 --- a/osu.Game/Storyboards/StoryboardElementWithDuration.cs +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using System.Linq; -using osu.Framework.Graphics; -using osu.Game.Storyboards.Drawables; -using osuTK; - -namespace osu.Game.Storyboards -{ - public abstract class StoryboardElementWithDuration : IStoryboardElementWithDuration - { - protected readonly List Loops = new List(); - private readonly List triggers = new List(); - - public string Path { get; } - public bool IsDrawable => HasCommands; - - public Anchor Origin; - public Vector2 InitialPosition; - - public readonly CommandTimelineGroup TimelineGroup = new CommandTimelineGroup(); - - public double StartTime - { - get - { - // To get the initial start time, we need to check whether the first alpha command to exist (across all loops) has a StartValue of zero. - // A StartValue of zero governs, above all else, the first valid display time of a sprite. - // - // You can imagine that the first command of each type decides that type's start value, so if the initial alpha is zero, - // anything before that point can be ignored (the sprite is not visible after all). - var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); - - var command = TimelineGroup.Alpha.Commands.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); - - foreach (var loop in Loops) - { - command = loop.Alpha.Commands.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); - } - - if (alphaCommands.Count > 0) - { - var firstAlpha = alphaCommands.MinBy(t => t.startTime); - - if (firstAlpha.isZeroStartValue) - return firstAlpha.startTime; - } - - return EarliestTransformTime; - } - } - - public double EarliestTransformTime - { - get - { - // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. - // The sprite's StartTime will be determined by the earliest command, regardless of type. - double earliestStartTime = TimelineGroup.StartTime; - foreach (var l in Loops) - earliestStartTime = Math.Min(earliestStartTime, l.StartTime); - return earliestStartTime; - } - } - - public double EndTime - { - get - { - double latestEndTime = TimelineGroup.EndTime; - - foreach (var l in Loops) - latestEndTime = Math.Max(latestEndTime, l.EndTime); - - return latestEndTime; - } - } - - public double EndTimeForDisplay - { - get - { - double latestEndTime = TimelineGroup.EndTime; - - foreach (var l in Loops) - latestEndTime = Math.Max(latestEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations); - - return latestEndTime; - } - } - - public bool HasCommands => TimelineGroup.HasCommands || Loops.Any(l => l.HasCommands); - - protected StoryboardElementWithDuration(string path, Anchor origin, Vector2 initialPosition) - { - Path = path; - Origin = origin; - InitialPosition = initialPosition; - } - - public abstract Drawable CreateDrawable(); - - public CommandLoop AddLoop(double startTime, int repeatCount) - { - var loop = new CommandLoop(startTime, repeatCount); - Loops.Add(loop); - return loop; - } - - public CommandTrigger AddTrigger(string triggerName, double startTime, double endTime, int groupNumber) - { - var trigger = new CommandTrigger(triggerName, startTime, endTime, groupNumber); - triggers.Add(trigger); - return trigger; - } - - protected IEnumerable.TypedCommand> GetCommands(CommandTimelineSelector timelineSelector, IEnumerable>? triggeredGroups) - { - var commands = TimelineGroup.GetCommands(timelineSelector); - foreach (var loop in Loops) - commands = commands.Concat(loop.GetCommands(timelineSelector)); - - if (triggeredGroups != null) - { - foreach (var pair in triggeredGroups) - commands = commands.Concat(pair.Item1.GetCommands(timelineSelector, pair.Item2)); - } - - return commands; - } - - public override string ToString() - => $"{Path}, {Origin}, {InitialPosition}"; - } - - public abstract class StoryboardElementWithDuration : StoryboardElementWithDuration - where U : Drawable, IDrawableStoryboardElement - { - private delegate void DrawablePropertyInitializer(U drawable, T value); - - protected StoryboardElementWithDuration(string path, Anchor origin, Vector2 initialPosition) - : base(path, origin, initialPosition) - { - } - - public override Drawable CreateDrawable() => CreateStoryboardDrawable(); - - public abstract U CreateStoryboardDrawable(); - - public void ApplyTransforms(U drawable, IEnumerable>? triggeredGroups = null) - { - // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. - // To achieve this, commands are "generated" as pairs of (command, initFunc, transformFunc) and batched into a contiguous list - // The list is then stably-sorted (to preserve command order), and applied to the drawable sequentially. - - List> generated = new List>(); - - generateCommands(generated, GetCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); - generateCommands(generated, GetCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); - generateCommands(generated, GetCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); - generateCommands(generated, GetCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); - generateCommands(generated, GetCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); - generateCommands(generated, GetCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); - generateCommands(generated, GetCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); - generateCommands(generated, GetCommands(g => g.VectorScale, triggeredGroups), (d, value) => d.VectorScale = value); - generateCommands(generated, GetCommands(g => g.FlipH, triggeredGroups), (d, value) => d.FlipH = value, false); - generateCommands(generated, GetCommands(g => g.FlipV, triggeredGroups), (d, value) => d.FlipV = value, false); - - foreach (var command in generated.OrderBy(g => g.StartTime)) - command.ApplyTo(drawable); - } - - private void generateCommands(List> resultList, IEnumerable.TypedCommand> commands, - DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) - { - bool initialized = false; - - foreach (var command in commands) - { - DrawablePropertyInitializer? initFunc = null; - - if (!initialized) - { - if (alwaysInitialize || command.StartTime == command.EndTime) - initFunc = initializeProperty; - initialized = true; - } - - resultList.Add(new GeneratedCommand(command, initFunc)); - } - } - - private interface IGeneratedCommand - where TDrawable : U - { - double StartTime { get; } - - void ApplyTo(TDrawable drawable); - } - - private readonly struct GeneratedCommand : IGeneratedCommand - where TDrawable : U - { - public double StartTime => command.StartTime; - - private readonly DrawablePropertyInitializer? initializeProperty; - private readonly CommandTimeline.TypedCommand command; - - public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) - { - this.command = command; - this.initializeProperty = initializeProperty; - } - - public void ApplyTo(TDrawable drawable) - { - initializeProperty?.Invoke(drawable, command.StartValue); - - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - var sequence = command.IsParameterCommand - ? drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration).TransformTo(command.PropertyName, command.EndValue) - : drawable.TransformTo(command.PropertyName, command.StartValue).Then().TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - - if (command.LoopCount > 0) - sequence.Loop(command.Delay, command.LoopCount); - } - } - } - } -} diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 8eaab9428d..dfd184a909 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -1,19 +1,164 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.Collections.Generic; +using System.Linq; using osu.Framework.Graphics; +using osu.Game.Storyboards.Commands; using osu.Game.Storyboards.Drawables; using osuTK; namespace osu.Game.Storyboards { - public class StoryboardSprite : StoryboardElementWithDuration + public class StoryboardSprite : IStoryboardElementWithDuration { - public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) - : base(path, origin, initialPosition) + private readonly List loopGroups = new List(); + private readonly List triggerGroups = new List(); + + public string Path { get; } + public bool IsDrawable => HasCommands; + + public Anchor Origin; + public Vector2 InitialPosition; + + public readonly StoryboardCommandGroup Group = new StoryboardCommandGroup(); + + public double StartTime { + get + { + // To get the initial start time, we need to check whether the first alpha command to exist (across all loops) has a StartValue of zero. + // A StartValue of zero governs, above all else, the first valid display time of a sprite. + // + // You can imagine that the first command of each type decides that type's start value, so if the initial alpha is zero, + // anything before that point can be ignored (the sprite is not visible after all). + var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); + + var command = Group.Alpha.FirstOrDefault(); + if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); + + foreach (var loop in loopGroups) + { + command = loop.Alpha.FirstOrDefault(); + if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); + } + + if (alphaCommands.Count > 0) + { + var firstAlpha = alphaCommands.MinBy(t => t.startTime); + + if (firstAlpha.isZeroStartValue) + return firstAlpha.startTime; + } + + return EarliestTransformTime; + } } - public override DrawableStoryboardSprite CreateStoryboardDrawable() => new DrawableStoryboardSprite(this); + public double EarliestTransformTime + { + get + { + // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. + // The sprite's StartTime will be determined by the earliest command, regardless of type. + double earliestStartTime = Group.StartTime; + foreach (var l in loopGroups) + earliestStartTime = Math.Min(earliestStartTime, l.StartTime); + return earliestStartTime; + } + } + + public double EndTime + { + get + { + double latestEndTime = Group.EndTime; + + foreach (var l in loopGroups) + latestEndTime = Math.Max(latestEndTime, l.EndTime); + + return latestEndTime; + } + } + + public double EndTimeForDisplay + { + get + { + double latestEndTime = Group.StartTime; + + foreach (var l in loopGroups) + latestEndTime = Math.Max(latestEndTime, l.StartTime + l.Duration * l.TotalIterations); + + return latestEndTime; + } + } + + public bool HasCommands => Group.HasCommands || loopGroups.Any(l => l.HasCommands); + + public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) + { + Path = path; + Origin = origin; + InitialPosition = initialPosition; + } + + public virtual Drawable CreateDrawable() => new DrawableStoryboardSprite(this); + + public StoryboardLoopingGroup AddLoopingGroup(double loopStartTime, int repeatCount) + { + var loop = new StoryboardLoopingGroup(loopStartTime, repeatCount); + loopGroups.Add(loop); + return loop; + } + + public StoryboardTriggerGroup AddTriggerGroup(string triggerName, double startTime, double endTime, int groupNumber) + { + var trigger = new StoryboardTriggerGroup(triggerName, startTime, endTime, groupNumber); + triggerGroups.Add(trigger); + return trigger; + } + + public override string ToString() => $"{Path}, {Origin}, {InitialPosition}"; + + public void ApplyTransforms(Drawable drawable, IEnumerable>? triggeredGroups = null) + { + // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. + + var commands = Group.GetAllCommands(); + commands = commands.Concat(loopGroups.SelectMany(l => l.GetAllCommands())); + + // todo: triggers are not implemented yet. + // if (triggeredGroups != null) + // commands = commands.Concat(triggeredGroups.SelectMany(tuple => tuple.Item1.GetAllCommands(tuple.Item2))); + + foreach (var command in commands.OrderBy(c => c.StartTime)) + { + using (drawable.BeginAbsoluteSequence(command.StartTime)) + command.ApplyTransform(drawable); + } + } + + // todo: need to revisit property initialisation. apparently it has to be done per first command of every affected property (transforms are supposed to do that already?). + // private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, + // DrawablePropertyInitializer initializeProperty, DrawableTransform transform, bool alwaysInitialize = true) + // { + // bool initialized = false; + // + // foreach (var command in commands) + // { + // DrawablePropertyInitializer? initFunc = null; + // + // if (!initialized) + // { + // if (alwaysInitialize || command.StartTime == command.EndTime) + // initFunc = initializeProperty; + // initialized = true; + // } + // + // resultList.Add(new GeneratedCommand(command, initFunc, transform)); + // } + // } } } From 9b77d8c972abefe0e7e0d524e26a90b457f41abf Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 01:59:26 +0300 Subject: [PATCH 09/38] Fix group start/end time not calculating correctly --- osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs index 02c43c9f60..5bb7ee6acf 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs @@ -30,13 +30,13 @@ namespace osu.Game.Storyboards.Commands /// Returns the earliest start time of the commands added to this group. /// [JsonIgnore] - public double StartTime { get; private set; } + public double StartTime { get; private set; } = double.MaxValue; /// /// Returns the latest end time of the commands added to this group. /// [JsonIgnore] - public double EndTime { get; private set; } + public double EndTime { get; private set; } = double.MinValue; [JsonIgnore] public double Duration => EndTime - StartTime; From 6c257e515996d04a7e31c35ac9bf7219442e2f2e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 01:59:42 +0300 Subject: [PATCH 10/38] Fix `HasCommands` property not set at all --- osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs index 5bb7ee6acf..0d4a79079b 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs @@ -104,6 +104,7 @@ namespace osu.Game.Storyboards.Commands protected virtual void AddCommand(ICollection> list, StoryboardCommand command) { list.Add(command); + HasCommands = true; if (command.StartTime < StartTime) StartTime = command.StartTime; From 87b065b8c3c82a365be4a2b9274042480e417a36 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 02:00:23 +0300 Subject: [PATCH 11/38] Fix incorrect start time calculations `LoopStartTime` is now baked into each `IStoryboardCommand`. --- osu.Game/Storyboards/StoryboardSprite.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index dfd184a909..fc3c5d343c 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -41,7 +41,7 @@ namespace osu.Game.Storyboards foreach (var loop in loopGroups) { command = loop.Alpha.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); + if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); } if (alphaCommands.Count > 0) @@ -120,8 +120,6 @@ namespace osu.Game.Storyboards return trigger; } - public override string ToString() => $"{Path}, {Origin}, {InitialPosition}"; - public void ApplyTransforms(Drawable drawable, IEnumerable>? triggeredGroups = null) { // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. @@ -140,6 +138,8 @@ namespace osu.Game.Storyboards } } + public override string ToString() => $"{Path}, {Origin}, {InitialPosition}"; + // todo: need to revisit property initialisation. apparently it has to be done per first command of every affected property (transforms are supposed to do that already?). // private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, // DrawablePropertyInitializer initializeProperty, DrawableTransform transform, bool alwaysInitialize = true) From 3755dd059af7855219a1867d894aee803e722fa2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 01:58:58 +0300 Subject: [PATCH 12/38] Calculate loop delays at point of transform application --- .../Commands/StoryboardLoopingGroup.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs index e520353bd6..39b81ead28 100644 --- a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs @@ -10,7 +10,7 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardLoopingGroup : StoryboardCommandGroup { - public double LoopStartTime; + private readonly double loopStartTime; /// /// The total number of times this loop is played back. Always greater than zero. @@ -26,45 +26,41 @@ namespace osu.Game.Storyboards.Commands { if (repeatCount < 0) throw new ArgumentException("Repeat count must be zero or above.", nameof(repeatCount)); - LoopStartTime = startTime; + loopStartTime = startTime; TotalIterations = repeatCount + 1; } protected override void AddCommand(ICollection> list, StoryboardCommand command) - { - // todo: this is broke! - double fullLoopDuration = EndTime - StartTime; - double loopDelay = fullLoopDuration - command.EndTime + command.StartTime; - base.AddCommand(list, new StoryboardLoopingCommand(command, LoopStartTime, TotalIterations, loopDelay)); - } + => base.AddCommand(list, new StoryboardLoopingCommand(command, this)); - public override string ToString() => $"{LoopStartTime} x{TotalIterations}"; + public override string ToString() => $"{loopStartTime} x{TotalIterations}"; private class StoryboardLoopingCommand : StoryboardCommand { private readonly StoryboardCommand command; - private readonly int loopCount; - private readonly double loopDelay; + private readonly StoryboardLoopingGroup loopingGroup; - public StoryboardLoopingCommand(StoryboardCommand command, double loopStartTime, int loopCount, double loopDelay) + public StoryboardLoopingCommand(StoryboardCommand command, StoryboardLoopingGroup loopingGroup) // In an ideal world, we would multiply the command duration by TotalIterations in command end time. // Unfortunately this would clash with how stable handled end times, and results in some storyboards playing outro // sequences for minutes or hours. - : base(loopStartTime + command.StartTime, loopStartTime + command.EndTime, command.StartValue, command.EndValue, command.Easing) + : base(loopingGroup.loopStartTime + command.StartTime, loopingGroup.loopStartTime + command.EndTime, command.StartValue, command.EndValue, command.Easing) { this.command = command; - this.loopCount = loopCount; - this.loopDelay = loopDelay; + this.loopingGroup = loopingGroup; } - public override void SetInitialValue(Drawable d) => command.SetInitialValue(d); + public override string PropertyName => command.PropertyName; - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => command.ApplyInitialValue(d); + + public override TransformSequence ApplyTransforms(Drawable d) { - if (loopCount == 0) - return command.ApplyTransform(d); + if (loopingGroup.TotalIterations == 0) + return command.ApplyTransforms(d); - return command.ApplyTransform(d).Loop(loopDelay, loopCount); + double loopingGroupDuration = loopingGroup.Duration; + return command.ApplyTransforms(d).Loop(loopingGroupDuration - Duration, loopingGroup.TotalIterations); } } } From 2ca36254f46c3501d97a8782bcc7a699104557d1 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 02:02:22 +0300 Subject: [PATCH 13/38] Fix comparison interface not implemented on storyboard command classes --- osu.Game/Storyboards/Commands/StoryboardCommand.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/osu.Game/Storyboards/Commands/StoryboardCommand.cs b/osu.Game/Storyboards/Commands/StoryboardCommand.cs index 883b9f57c1..1647faf243 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommand.cs @@ -1,12 +1,13 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; namespace osu.Game.Storyboards.Commands { - public abstract class StoryboardCommand : IStoryboardCommand + public abstract class StoryboardCommand : IStoryboardCommand, IComparable> { public double StartTime { get; } public double EndTime { get; } @@ -41,10 +42,14 @@ namespace osu.Game.Storyboards.Commands /// public abstract TransformSequence ApplyTransform(Drawable d); - public int CompareTo(IStoryboardCommand other) + public int CompareTo(StoryboardCommand? other) { + if (other == null) + return 1; + int result = StartTime.CompareTo(other.StartTime); - if (result != 0) return result; + if (result != 0) + return result; return EndTime.CompareTo(other.EndTime); } From b450abb687823132c9bb3c6b1041bb70bb05d8ea Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 02:02:45 +0300 Subject: [PATCH 14/38] Support applying initial values of storyboard commands --- .../Storyboards/Commands/IStoryboardCommand.cs | 14 +++++++++++++- .../Storyboards/Commands/StoryboardAlphaCommand.cs | 8 ++++++-- .../StoryboardBlendingParametersCommand.cs | 9 ++++++--- .../Commands/StoryboardColourCommand.cs | 8 ++++++-- osu.Game/Storyboards/Commands/StoryboardCommand.cs | 12 ++++-------- .../Storyboards/Commands/StoryboardFlipHCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardFlipVCommand.cs | 6 ++++-- .../Commands/StoryboardRotationCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardScaleCommand.cs | 6 ++++-- .../Commands/StoryboardVectorScaleCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardXCommand.cs | 6 ++++-- .../Storyboards/Commands/StoryboardYCommand.cs | 6 ++++-- osu.Game/Storyboards/StoryboardSprite.cs | 10 +++++++++- 13 files changed, 72 insertions(+), 31 deletions(-) diff --git a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs index 848dcab575..05613a987d 100644 --- a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs @@ -18,11 +18,23 @@ namespace osu.Game.Storyboards.Commands /// double EndTime { get; } + /// + /// The name of the property affected by this storyboard command. + /// Used to apply initial property values based on the list of commands given in . + /// + string PropertyName { get; } + + /// + /// Sets the value of the corresponding property in to the start value of this command. + /// + /// The target drawable. + void ApplyInitialValue(Drawable d); + /// /// Applies the transforms described by this storyboard command to the target drawable. /// /// The target drawable. /// The sequence of transforms applied to the target drawable. - TransformSequence ApplyTransform(Drawable d); + TransformSequence ApplyTransforms(Drawable d); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs index 729ecd72a7..1d91d6ccc1 100644 --- a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs @@ -13,7 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Alpha = StartValue; - public override TransformSequence ApplyTransform(Drawable d) => d.FadeTo(StartValue).Then().FadeTo(EndValue, Duration, Easing); + public override string PropertyName => nameof(Drawable.Alpha); + + public override void ApplyInitialValue(Drawable d) => d.Alpha = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) + => d.FadeTo(StartValue).Then().FadeTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs index cc54909837..3a2d372a66 100644 --- a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs @@ -13,9 +13,12 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Blending = StartValue; + public override string PropertyName => nameof(Drawable.Blending); - public override TransformSequence ApplyTransform(Drawable d) - => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration).TransformTo(nameof(d.Blending), EndValue); + public override void ApplyInitialValue(Drawable d) => d.Blending = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) + => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration) + .TransformTo(nameof(d.Blending), EndValue); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs index be56a1d71b..fbde7e1af7 100644 --- a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs @@ -14,7 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Colour = StartValue; - public override TransformSequence ApplyTransform(Drawable d) => d.FadeColour(StartValue).Then().FadeColour(EndValue, Duration, Easing); + public override string PropertyName => nameof(Drawable.Colour); + + public override void ApplyInitialValue(Drawable d) => d.Colour = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) + => d.FadeColour(StartValue).Then().FadeColour(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardCommand.cs b/osu.Game/Storyboards/Commands/StoryboardCommand.cs index 1647faf243..58fcb148ff 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommand.cs @@ -32,15 +32,11 @@ namespace osu.Game.Storyboards.Commands public T StartValue; public T EndValue; - /// - /// Sets the value of the corresponding property in to the start value of this command. - /// - public abstract void SetInitialValue(Drawable d); + public abstract string PropertyName { get; } - /// - /// Transforms a corresponding property in that corresponds to this command group with the specified parameters. - /// - public abstract TransformSequence ApplyTransform(Drawable d); + public abstract void ApplyInitialValue(Drawable d); + + public abstract TransformSequence ApplyTransforms(Drawable d); public int CompareTo(StoryboardCommand? other) { diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs index 9bcb687d3c..c381b0bb64 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs @@ -14,9 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipH = StartValue; + public override string PropertyName => nameof(IDrawableStoryboardElement.FlipH); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipH = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.TransformTo(nameof(IDrawableStoryboardElement.FlipH), StartValue).Delay(Duration) .TransformTo(nameof(IDrawableStoryboardElement.FlipH), EndValue); } diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs index 9f1f5faa33..e43e5e9205 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs @@ -14,9 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipV = StartValue; + public override string PropertyName => nameof(IDrawableStoryboardElement.FlipV); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipV = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.TransformTo(nameof(IDrawableStoryboardElement.FlipV), StartValue).Delay(Duration) .TransformTo(nameof(IDrawableStoryboardElement.FlipV), EndValue); } diff --git a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs index c56dcd130f..2a449af843 100644 --- a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs @@ -13,9 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Rotation = StartValue; + public override string PropertyName => nameof(Drawable.Rotation); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.Rotation = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.RotateTo(StartValue).Then().RotateTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs index 9dbdd6ebd8..bf9796148c 100644 --- a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs @@ -14,9 +14,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Scale = new Vector2(StartValue); + public override string PropertyName => nameof(Drawable.Scale); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.Scale = new Vector2(StartValue); + + public override TransformSequence ApplyTransforms(Drawable d) => d.ScaleTo(StartValue).Then().ScaleTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs index fefb21b257..638dc6a5ee 100644 --- a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs @@ -15,9 +15,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).VectorScale = StartValue; + public override string PropertyName => nameof(IDrawableStoryboardElement.VectorScale); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).VectorScale = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.TransformTo(nameof(IDrawableStoryboardElement.VectorScale), StartValue).Then() .TransformTo(nameof(IDrawableStoryboardElement.VectorScale), EndValue, Duration, Easing); } diff --git a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs index a9f9cd4f8f..809a77256c 100644 --- a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs @@ -13,9 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.X = StartValue; + public override string PropertyName => nameof(Drawable.X); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.X = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.MoveToX(StartValue).Then().MoveToX(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs index eb30b36720..d054135878 100644 --- a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs @@ -13,9 +13,11 @@ namespace osu.Game.Storyboards.Commands { } - public override void SetInitialValue(Drawable d) => d.Y = StartValue; + public override string PropertyName => nameof(Drawable.Y); - public override TransformSequence ApplyTransform(Drawable d) + public override void ApplyInitialValue(Drawable d) => d.Y = StartValue; + + public override TransformSequence ApplyTransforms(Drawable d) => d.MoveToY(StartValue).Then().MoveToY(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index fc3c5d343c..9d7ab66692 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -131,10 +131,18 @@ namespace osu.Game.Storyboards // if (triggeredGroups != null) // commands = commands.Concat(triggeredGroups.SelectMany(tuple => tuple.Item1.GetAllCommands(tuple.Item2))); + HashSet appliedProperties = new HashSet(); + foreach (var command in commands.OrderBy(c => c.StartTime)) { + if (!appliedProperties.Contains(command.PropertyName)) + { + command.ApplyInitialValue(drawable); + appliedProperties.Add(command.PropertyName); + } + using (drawable.BeginAbsoluteSequence(command.StartTime)) - command.ApplyTransform(drawable); + command.ApplyTransforms(drawable); } } From fa9b2f0cd541bb4c80c895a0bbeced418ccd85e1 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 03:06:49 +0300 Subject: [PATCH 15/38] Add generics to `ApplyInitialValue`/`ApplyTransforms` for ability to return custom transform sequences *sigh* --- .../Visual/Gameplay/TestSceneLeadIn.cs | 8 +-- .../Gameplay/TestSceneStoryboardWithOutro.cs | 2 +- .../TestSceneMultiSpectatorScreen.cs | 2 +- .../Formats/LegacyStoryboardDecoder.cs | 32 ++++----- .../Commands/IStoryboardCommand.cs | 7 +- .../Commands/StoryboardAlphaCommand.cs | 4 +- .../StoryboardBlendingParametersCommand.cs | 4 +- .../Commands/StoryboardColourCommand.cs | 4 +- .../Storyboards/Commands/StoryboardCommand.cs | 19 +++--- .../Commands/StoryboardCommandGroup.cs | 48 ++++--------- .../Commands/StoryboardCommandList.cs | 41 ------------ .../Commands/StoryboardFlipHCommand.cs | 10 +-- .../Commands/StoryboardFlipVCommand.cs | 10 +-- .../Commands/StoryboardLoopingGroup.cs | 5 +- .../Commands/StoryboardRotationCommand.cs | 4 +- .../Commands/StoryboardScaleCommand.cs | 4 +- .../Commands/StoryboardTriggerGroup.cs | 1 - .../Commands/StoryboardVectorScaleCommand.cs | 10 +-- .../Commands/StoryboardXCommand.cs | 4 +- .../Commands/StoryboardYCommand.cs | 4 +- .../Drawables/DrawableStoryboardAnimation.cs | 2 +- .../Drawables/DrawableStoryboardSprite.cs | 6 +- ...ableStoryboardElement.cs => IFlippable.cs} | 4 +- .../Storyboards/Drawables/IVectorScalable.cs | 13 ++++ osu.Game/Storyboards/StoryboardSprite.cs | 67 ++++++------------- 25 files changed, 122 insertions(+), 193 deletions(-) delete mode 100644 osu.Game/Storyboards/Commands/StoryboardCommandList.cs rename osu.Game/Storyboards/Drawables/{IDrawableStoryboardElement.cs => IFlippable.cs} (72%) create mode 100644 osu.Game/Storyboards/Drawables/IVectorScalable.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs index c3eef4da9b..b2196e77b4 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs @@ -47,7 +47,7 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.Group.AddAlpha(firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1, Easing.None); + sprite.Commands.AddAlpha(firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1, Easing.None); storyboard.GetLayer("Background").Add(sprite); @@ -73,16 +73,16 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); // these should be ignored as we have an alpha visibility blocker proceeding this command. - sprite.Group.AddScale(loop_start_time, -18000, 0, 1, Easing.None); + sprite.Commands.AddScale(loop_start_time, -18000, 0, 1, Easing.None); var loopGroup = sprite.AddLoopingGroup(loop_start_time, 50); loopGroup.AddScale(loop_start_time, -18000, 0, 1, Easing.None); - var target = addEventToLoop ? loopGroup : sprite.Group; + var target = addEventToLoop ? loopGroup : sprite.Commands; double loopRelativeOffset = addEventToLoop ? -loop_start_time : 0; target.AddAlpha(loopRelativeOffset + firstStoryboardEvent, loopRelativeOffset + firstStoryboardEvent + 500, 0, 1, Easing.None); // these should be ignored due to being in the future. - sprite.Group.AddAlpha(18000, 20000, 0, 1, Easing.None); + sprite.Commands.AddAlpha(18000, 20000, 0, 1, Easing.None); loopGroup.AddAlpha(38000, 40000, 0, 1, Easing.None); storyboard.GetLayer("Background").Add(sprite); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs index 9269c3f4ae..8bdb7297fe 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs @@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.Gameplay { var storyboard = new Storyboard(); var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.Group.AddAlpha(0, duration, 1, 0, Easing.None); + sprite.Commands.AddAlpha(0, duration, 1, 0, Easing.None); storyboard.GetLayer("Background").Add(sprite); return storyboard; } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs index 62a2bfeaab..7cd2e2fdaa 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs @@ -424,7 +424,7 @@ namespace osu.Game.Tests.Visual.Multiplayer public void TestIntroStoryboardElement() => testLeadIn(b => { var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.Group.AddAlpha(-2000, 0, 0, 1, Easing.None); + sprite.Commands.AddAlpha(-2000, 0, 0, 1, Easing.None); b.Storyboard.GetLayer("Background").Add(sprite); }); diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index 33cdaa085e..83277b71c8 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -19,7 +19,7 @@ namespace osu.Game.Beatmaps.Formats public class LegacyStoryboardDecoder : LegacyDecoder { private StoryboardSprite? storyboardSprite; - private StoryboardCommandGroup? currentGroup; + private StoryboardCommandGroup? currentCommandsGroup; private Storyboard storyboard = null!; @@ -166,7 +166,7 @@ namespace osu.Game.Beatmaps.Formats else { if (depth < 2) - currentGroup = storyboardSprite?.Group; + currentCommandsGroup = storyboardSprite?.Commands; string commandType = split[0]; @@ -178,7 +178,7 @@ namespace osu.Game.Beatmaps.Formats double startTime = split.Length > 2 ? Parsing.ParseDouble(split[2]) : double.MinValue; double endTime = split.Length > 3 ? Parsing.ParseDouble(split[3]) : double.MaxValue; int groupNumber = split.Length > 4 ? Parsing.ParseInt(split[4]) : 0; - currentGroup = storyboardSprite?.AddTriggerGroup(triggerName, startTime, endTime, groupNumber); + currentCommandsGroup = storyboardSprite?.AddTriggerGroup(triggerName, startTime, endTime, groupNumber); break; } @@ -186,7 +186,7 @@ namespace osu.Game.Beatmaps.Formats { double startTime = Parsing.ParseDouble(split[1]); int repeatCount = Parsing.ParseInt(split[2]); - currentGroup = storyboardSprite?.AddLoopingGroup(startTime, Math.Max(0, repeatCount - 1)); + currentCommandsGroup = storyboardSprite?.AddLoopingGroup(startTime, Math.Max(0, repeatCount - 1)); break; } @@ -205,7 +205,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentGroup?.AddAlpha(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddAlpha(startTime, endTime, startValue, endValue, easing); break; } @@ -213,7 +213,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentGroup?.AddScale(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddScale(startTime, endTime, startValue, endValue, easing); break; } @@ -223,7 +223,7 @@ namespace osu.Game.Beatmaps.Formats float startY = Parsing.ParseFloat(split[5]); float endX = split.Length > 6 ? Parsing.ParseFloat(split[6]) : startX; float endY = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startY; - currentGroup?.AddVectorScale(startTime, endTime, new Vector2(startX, startY), new Vector2(endX, endY), easing); + currentCommandsGroup?.AddVectorScale(startTime, endTime, new Vector2(startX, startY), new Vector2(endX, endY), easing); break; } @@ -231,7 +231,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentGroup?.AddRotation(startTime, endTime, MathUtils.RadiansToDegrees(startValue), MathUtils.RadiansToDegrees(endValue), easing); + currentCommandsGroup?.AddRotation(startTime, endTime, MathUtils.RadiansToDegrees(startValue), MathUtils.RadiansToDegrees(endValue), easing); break; } @@ -241,8 +241,8 @@ namespace osu.Game.Beatmaps.Formats float startY = Parsing.ParseFloat(split[5]); float endX = split.Length > 6 ? Parsing.ParseFloat(split[6]) : startX; float endY = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startY; - currentGroup?.AddX(startTime, endTime, startX, endX, easing); - currentGroup?.AddY(startTime, endTime, startY, endY, easing); + currentCommandsGroup?.AddX(startTime, endTime, startX, endX, easing); + currentCommandsGroup?.AddY(startTime, endTime, startY, endY, easing); break; } @@ -250,7 +250,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentGroup?.AddX(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddX(startTime, endTime, startValue, endValue, easing); break; } @@ -258,7 +258,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentGroup?.AddY(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddY(startTime, endTime, startValue, endValue, easing); break; } @@ -270,7 +270,7 @@ namespace osu.Game.Beatmaps.Formats float endRed = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startRed; float endGreen = split.Length > 8 ? Parsing.ParseFloat(split[8]) : startGreen; float endBlue = split.Length > 9 ? Parsing.ParseFloat(split[9]) : startBlue; - currentGroup?.AddColour(startTime, endTime, + currentCommandsGroup?.AddColour(startTime, endTime, new Color4(startRed / 255f, startGreen / 255f, startBlue / 255f, 1), new Color4(endRed / 255f, endGreen / 255f, endBlue / 255f, 1), easing); break; @@ -283,16 +283,16 @@ namespace osu.Game.Beatmaps.Formats switch (type) { case "A": - currentGroup?.AddBlendingParameters(startTime, endTime, BlendingParameters.Additive, + currentCommandsGroup?.AddBlendingParameters(startTime, endTime, BlendingParameters.Additive, startTime == endTime ? BlendingParameters.Additive : BlendingParameters.Inherit, easing); break; case "H": - currentGroup?.AddFlipH(startTime, endTime, true, startTime == endTime, easing); + currentCommandsGroup?.AddFlipH(startTime, endTime, true, startTime == endTime, easing); break; case "V": - currentGroup?.AddFlipV(startTime, endTime, true, startTime == endTime, easing); + currentCommandsGroup?.AddFlipV(startTime, endTime, true, startTime == endTime, easing); break; } diff --git a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs index 05613a987d..6efb19afe4 100644 --- a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs @@ -3,6 +3,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; +using osu.Game.Storyboards.Drawables; namespace osu.Game.Storyboards.Commands { @@ -28,13 +29,15 @@ namespace osu.Game.Storyboards.Commands /// Sets the value of the corresponding property in to the start value of this command. /// /// The target drawable. - void ApplyInitialValue(Drawable d); + void ApplyInitialValue(TDrawable d) + where TDrawable : Drawable, IFlippable, IVectorScalable; /// /// Applies the transforms described by this storyboard command to the target drawable. /// /// The target drawable. /// The sequence of transforms applied to the target drawable. - TransformSequence ApplyTransforms(Drawable d); + TransformSequence ApplyTransforms(TDrawable d) + where TDrawable : Drawable, IFlippable, IVectorScalable; } } diff --git a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs index 1d91d6ccc1..f4a90b372a 100644 --- a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs @@ -15,9 +15,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Alpha); - public override void ApplyInitialValue(Drawable d) => d.Alpha = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.Alpha = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.FadeTo(StartValue).Then().FadeTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs index 3a2d372a66..3e2e8bb0e8 100644 --- a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs @@ -15,9 +15,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Blending); - public override void ApplyInitialValue(Drawable d) => d.Blending = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.Blending = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration) .TransformTo(nameof(d.Blending), EndValue); } diff --git a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs index fbde7e1af7..66390eb305 100644 --- a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs @@ -16,9 +16,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Colour); - public override void ApplyInitialValue(Drawable d) => d.Colour = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.Colour = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.FadeColour(StartValue).Then().FadeColour(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardCommand.cs b/osu.Game/Storyboards/Commands/StoryboardCommand.cs index 58fcb148ff..4f2f0f04a2 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommand.cs @@ -4,6 +4,7 @@ using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; +using osu.Game.Storyboards.Drawables; namespace osu.Game.Storyboards.Commands { @@ -11,6 +12,11 @@ namespace osu.Game.Storyboards.Commands { public double StartTime { get; } public double EndTime { get; } + + public T StartValue { get; } + public T EndValue { get; } + public Easing Easing { get; } + public double Duration => EndTime - StartTime; protected StoryboardCommand(double startTime, double endTime, T startValue, T endValue, Easing easing) @@ -25,18 +31,13 @@ namespace osu.Game.Storyboards.Commands Easing = easing; } - public Easing Easing { get; set; } - public int LoopCount { get; set; } - public double Delay { get; set; } - - public T StartValue; - public T EndValue; - public abstract string PropertyName { get; } - public abstract void ApplyInitialValue(Drawable d); + public abstract void ApplyInitialValue(TDrawable d) + where TDrawable : Drawable, IFlippable, IVectorScalable; - public abstract TransformSequence ApplyTransforms(Drawable d); + public abstract TransformSequence ApplyTransforms(TDrawable d) + where TDrawable : Drawable, IFlippable, IVectorScalable; public int CompareTo(StoryboardCommand? other) { diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs index 0d4a79079b..fb847d2e44 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using System.Linq; using Newtonsoft.Json; using osu.Framework.Graphics; using osu.Framework.Lists; @@ -13,18 +12,20 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardCommandGroup { - public SortedList> X; - public SortedList> Y; - public SortedList> Scale; - public SortedList> VectorScale; - public SortedList> Rotation; - public SortedList> Colour; - public SortedList> Alpha; - public SortedList> BlendingParameters; - public SortedList> FlipH; - public SortedList> FlipV; + public SortedList> X = new SortedList>(); + public SortedList> Y = new SortedList>(); + public SortedList> Scale = new SortedList>(); + public SortedList> VectorScale = new SortedList>(); + public SortedList> Rotation = new SortedList>(); + public SortedList> Colour = new SortedList>(); + public SortedList> Alpha = new SortedList>(); + public SortedList> BlendingParameters = new SortedList>(); + public SortedList> FlipH = new SortedList>(); + public SortedList> FlipV = new SortedList>(); - private readonly IReadOnlyList[] lists; + public IReadOnlyList AllCommands => allCommands; + + private readonly List allCommands = new List(); /// /// Returns the earliest start time of the commands added to this group. @@ -44,28 +45,6 @@ namespace osu.Game.Storyboards.Commands [JsonIgnore] public bool HasCommands { get; private set; } - public StoryboardCommandGroup() - { - lists = new IReadOnlyList[] - { - X = new SortedList>(), - Y = new SortedList>(), - Scale = new SortedList>(), - VectorScale = new SortedList>(), - Rotation = new SortedList>(), - Colour = new SortedList>(), - Alpha = new SortedList>(), - BlendingParameters = new SortedList>(), - FlipH = new SortedList>(), - FlipV = new SortedList>() - }; - } - - /// - /// Returns all commands contained by this group unsorted. - /// - public virtual IEnumerable GetAllCommands() => lists.SelectMany(l => l); - public void AddX(double startTime, double endTime, float startValue, float endValue, Easing easing) => AddCommand(X, new StoryboardXCommand(startTime, endTime, startValue, endValue, easing)); @@ -104,6 +83,7 @@ namespace osu.Game.Storyboards.Commands protected virtual void AddCommand(ICollection> list, StoryboardCommand command) { list.Add(command); + allCommands.Add(command); HasCommands = true; if (command.StartTime < StartTime) diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandList.cs b/osu.Game/Storyboards/Commands/StoryboardCommandList.cs deleted file mode 100644 index 67012e9d49..0000000000 --- a/osu.Game/Storyboards/Commands/StoryboardCommandList.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -namespace osu.Game.Storyboards.Commands -{ - // public class StoryboardCommandList : IStoryboardCommandList - // { - // // todo: change to sorted list and avoid enumerable type on exposed properties? - // private readonly List> commands = new List>(); - // - // public IEnumerable> Commands => commands.OrderBy(c => c.StartTime); - // - // IEnumerable IStoryboardCommandList.Commands => Commands; - // public bool HasCommands => commands.Count > 0; - // - // public double StartTime { get; private set; } = double.MaxValue; - // public double EndTime { get; private set; } = double.MinValue; - // - // public T? StartValue { get; private set; } - // public T? EndValue { get; private set; } - // - // public void Add(StoryboardCommand command) - // { - // commands.Add(command); - // - // if (command.StartTime < StartTime) - // { - // StartValue = command.StartValue; - // StartTime = command.StartTime; - // } - // - // if (command.EndTime > EndTime) - // { - // EndValue = command.EndValue; - // EndTime = command.EndTime; - // } - // } - // - // public override string ToString() => $"{commands.Count} command(s)"; - // } -} diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs index c381b0bb64..26aef23226 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs @@ -14,12 +14,12 @@ namespace osu.Game.Storyboards.Commands { } - public override string PropertyName => nameof(IDrawableStoryboardElement.FlipH); + public override string PropertyName => nameof(IFlippable.FlipH); - public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipH = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.FlipH = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) - => d.TransformTo(nameof(IDrawableStoryboardElement.FlipH), StartValue).Delay(Duration) - .TransformTo(nameof(IDrawableStoryboardElement.FlipH), EndValue); + public override TransformSequence ApplyTransforms(TDrawable d) + => d.TransformTo(nameof(IFlippable.FlipH), StartValue).Delay(Duration) + .TransformTo(nameof(IFlippable.FlipH), EndValue); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs index e43e5e9205..88423da2af 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs @@ -14,12 +14,12 @@ namespace osu.Game.Storyboards.Commands { } - public override string PropertyName => nameof(IDrawableStoryboardElement.FlipV); + public override string PropertyName => nameof(IFlippable.FlipV); - public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).FlipV = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.FlipV = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) - => d.TransformTo(nameof(IDrawableStoryboardElement.FlipV), StartValue).Delay(Duration) - .TransformTo(nameof(IDrawableStoryboardElement.FlipV), EndValue); + public override TransformSequence ApplyTransforms(TDrawable d) + => d.TransformTo(nameof(IFlippable.FlipV), StartValue).Delay(Duration) + .TransformTo(nameof(IFlippable.FlipV), EndValue); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs index 39b81ead28..e97de84ab7 100644 --- a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; namespace osu.Game.Storyboards.Commands @@ -52,9 +51,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => command.PropertyName; - public override void ApplyInitialValue(Drawable d) => command.ApplyInitialValue(d); + public override void ApplyInitialValue(TDrawable d) => command.ApplyInitialValue(d); - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) { if (loopingGroup.TotalIterations == 0) return command.ApplyTransforms(d); diff --git a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs index 2a449af843..4347dc9d77 100644 --- a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs @@ -15,9 +15,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Rotation); - public override void ApplyInitialValue(Drawable d) => d.Rotation = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.Rotation = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.RotateTo(StartValue).Then().RotateTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs index bf9796148c..b0f33fd6b8 100644 --- a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs @@ -16,9 +16,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Scale); - public override void ApplyInitialValue(Drawable d) => d.Scale = new Vector2(StartValue); + public override void ApplyInitialValue(TDrawable d) => d.Scale = new Vector2(StartValue); - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.ScaleTo(StartValue).Then().ScaleTo(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs b/osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs index dfb6f8cb1b..89a68e9ec0 100644 --- a/osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardTriggerGroup.cs @@ -3,7 +3,6 @@ namespace osu.Game.Storyboards.Commands { - // todo: this is not implemented and has never been, keep that in mind. public class StoryboardTriggerGroup : StoryboardCommandGroup { public string TriggerName; diff --git a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs index 638dc6a5ee..5d3fef5948 100644 --- a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs @@ -15,12 +15,12 @@ namespace osu.Game.Storyboards.Commands { } - public override string PropertyName => nameof(IDrawableStoryboardElement.VectorScale); + public override string PropertyName => nameof(IVectorScalable.VectorScale); - public override void ApplyInitialValue(Drawable d) => ((IDrawableStoryboardElement)d).VectorScale = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.VectorScale = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) - => d.TransformTo(nameof(IDrawableStoryboardElement.VectorScale), StartValue).Then() - .TransformTo(nameof(IDrawableStoryboardElement.VectorScale), EndValue, Duration, Easing); + public override TransformSequence ApplyTransforms(TDrawable d) + => d.TransformTo(nameof(d.VectorScale), StartValue).Then() + .TransformTo(nameof(d.VectorScale), EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs index 809a77256c..7df9a75768 100644 --- a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs @@ -15,9 +15,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.X); - public override void ApplyInitialValue(Drawable d) => d.X = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.X = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.MoveToX(StartValue).Then().MoveToX(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs index d054135878..d7dc32a0f3 100644 --- a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs @@ -15,9 +15,9 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Y); - public override void ApplyInitialValue(Drawable d) => d.Y = StartValue; + public override void ApplyInitialValue(TDrawable d) => d.Y = StartValue; - public override TransformSequence ApplyTransforms(Drawable d) + public override TransformSequence ApplyTransforms(TDrawable d) => d.MoveToY(StartValue).Then().MoveToY(EndValue, Duration, Easing); } } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs index 8e1a8ce949..fae9ec7f2e 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs @@ -16,7 +16,7 @@ using osuTK; namespace osu.Game.Storyboards.Drawables { - public partial class DrawableStoryboardAnimation : TextureAnimation, IDrawableStoryboardElement + public partial class DrawableStoryboardAnimation : TextureAnimation, IFlippable, IVectorScalable { public StoryboardAnimation Animation { get; } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs index 6772178e85..507a51aca4 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; @@ -13,7 +14,7 @@ using osuTK; namespace osu.Game.Storyboards.Drawables { - public partial class DrawableStoryboardSprite : Sprite, IDrawableStoryboardElement + public partial class DrawableStoryboardSprite : Sprite, IFlippable, IVectorScalable { public StoryboardSprite Sprite { get; } @@ -101,6 +102,9 @@ namespace osu.Game.Storyboards.Drawables else Texture = textureStore.Get(Sprite.Path); + if (Sprite.Path == "SB/textbox.png") + Debugger.Break(); + Sprite.ApplyTransforms(this); } diff --git a/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs b/osu.Game/Storyboards/Drawables/IFlippable.cs similarity index 72% rename from osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs rename to osu.Game/Storyboards/Drawables/IFlippable.cs index 04bae88c76..79f98ea6ef 100644 --- a/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs +++ b/osu.Game/Storyboards/Drawables/IFlippable.cs @@ -2,14 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics; -using osuTK; namespace osu.Game.Storyboards.Drawables { - public interface IDrawableStoryboardElement : IDrawable + public interface IFlippable : IDrawable { bool FlipH { get; set; } bool FlipV { get; set; } - Vector2 VectorScale { get; set; } } } diff --git a/osu.Game/Storyboards/Drawables/IVectorScalable.cs b/osu.Game/Storyboards/Drawables/IVectorScalable.cs new file mode 100644 index 0000000000..ce6047c8f6 --- /dev/null +++ b/osu.Game/Storyboards/Drawables/IVectorScalable.cs @@ -0,0 +1,13 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osuTK; + +namespace osu.Game.Storyboards.Drawables +{ + public interface IVectorScalable : IDrawable + { + Vector2 VectorScale { get; set; } + } +} diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 9d7ab66692..f2c011bfca 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -13,7 +13,7 @@ namespace osu.Game.Storyboards { public class StoryboardSprite : IStoryboardElementWithDuration { - private readonly List loopGroups = new List(); + private readonly List loopingGroups = new List(); private readonly List triggerGroups = new List(); public string Path { get; } @@ -22,7 +22,7 @@ namespace osu.Game.Storyboards public Anchor Origin; public Vector2 InitialPosition; - public readonly StoryboardCommandGroup Group = new StoryboardCommandGroup(); + public readonly StoryboardCommandGroup Commands = new StoryboardCommandGroup(); public double StartTime { @@ -35,10 +35,10 @@ namespace osu.Game.Storyboards // anything before that point can be ignored (the sprite is not visible after all). var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); - var command = Group.Alpha.FirstOrDefault(); + var command = Commands.Alpha.FirstOrDefault(); if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); - foreach (var loop in loopGroups) + foreach (var loop in loopingGroups) { command = loop.Alpha.FirstOrDefault(); if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); @@ -62,8 +62,8 @@ namespace osu.Game.Storyboards { // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. // The sprite's StartTime will be determined by the earliest command, regardless of type. - double earliestStartTime = Group.StartTime; - foreach (var l in loopGroups) + double earliestStartTime = Commands.StartTime; + foreach (var l in loopingGroups) earliestStartTime = Math.Min(earliestStartTime, l.StartTime); return earliestStartTime; } @@ -73,9 +73,9 @@ namespace osu.Game.Storyboards { get { - double latestEndTime = Group.EndTime; + double latestEndTime = Commands.EndTime; - foreach (var l in loopGroups) + foreach (var l in loopingGroups) latestEndTime = Math.Max(latestEndTime, l.EndTime); return latestEndTime; @@ -86,16 +86,16 @@ namespace osu.Game.Storyboards { get { - double latestEndTime = Group.StartTime; + double latestEndTime = Commands.StartTime; - foreach (var l in loopGroups) + foreach (var l in loopingGroups) latestEndTime = Math.Max(latestEndTime, l.StartTime + l.Duration * l.TotalIterations); return latestEndTime; } } - public bool HasCommands => Group.HasCommands || loopGroups.Any(l => l.HasCommands); + public bool HasCommands => Commands.HasCommands || loopingGroups.Any(l => l.HasCommands); public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) { @@ -109,7 +109,7 @@ namespace osu.Game.Storyboards public StoryboardLoopingGroup AddLoopingGroup(double loopStartTime, int repeatCount) { var loop = new StoryboardLoopingGroup(loopStartTime, repeatCount); - loopGroups.Add(loop); + loopingGroups.Add(loop); return loop; } @@ -120,26 +120,20 @@ namespace osu.Game.Storyboards return trigger; } - public void ApplyTransforms(Drawable drawable, IEnumerable>? triggeredGroups = null) + public void ApplyTransforms(TDrawable drawable) + where TDrawable : Drawable, IFlippable, IVectorScalable { - // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. - - var commands = Group.GetAllCommands(); - commands = commands.Concat(loopGroups.SelectMany(l => l.GetAllCommands())); - - // todo: triggers are not implemented yet. - // if (triggeredGroups != null) - // commands = commands.Concat(triggeredGroups.SelectMany(tuple => tuple.Item1.GetAllCommands(tuple.Item2))); - HashSet appliedProperties = new HashSet(); + // For performance reasons, we need to apply the commands in chronological order. + // Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. + IEnumerable commands = Commands.AllCommands; + commands = commands.Concat(loopingGroups.SelectMany(l => l.AllCommands)); + foreach (var command in commands.OrderBy(c => c.StartTime)) { - if (!appliedProperties.Contains(command.PropertyName)) - { + if (appliedProperties.Add(command.PropertyName)) command.ApplyInitialValue(drawable); - appliedProperties.Add(command.PropertyName); - } using (drawable.BeginAbsoluteSequence(command.StartTime)) command.ApplyTransforms(drawable); @@ -147,26 +141,5 @@ namespace osu.Game.Storyboards } public override string ToString() => $"{Path}, {Origin}, {InitialPosition}"; - - // todo: need to revisit property initialisation. apparently it has to be done per first command of every affected property (transforms are supposed to do that already?). - // private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, - // DrawablePropertyInitializer initializeProperty, DrawableTransform transform, bool alwaysInitialize = true) - // { - // bool initialized = false; - // - // foreach (var command in commands) - // { - // DrawablePropertyInitializer? initFunc = null; - // - // if (!initialized) - // { - // if (alwaysInitialize || command.StartTime == command.EndTime) - // initFunc = initializeProperty; - // initialized = true; - // } - // - // resultList.Add(new GeneratedCommand(command, initFunc, transform)); - // } - // } } } From 79da6d861326ca9d6d897d7a0059471a4548d8bf Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 03:07:59 +0300 Subject: [PATCH 16/38] Fix refactor error on `EndTimeForDisplay` Not sure when this happened >.> --- osu.Game/Storyboards/StoryboardSprite.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index f2c011bfca..f961019883 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -86,7 +86,7 @@ namespace osu.Game.Storyboards { get { - double latestEndTime = Commands.StartTime; + double latestEndTime = Commands.EndTime; foreach (var l in loopingGroups) latestEndTime = Math.Max(latestEndTime, l.StartTime + l.Duration * l.TotalIterations); From a85be2a46d574fe62416e7313afa3bfdd3873dd0 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 20:22:26 +0300 Subject: [PATCH 17/38] Fix merge conflicts --- osu.Game/Storyboards/StoryboardSprite.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index a6312ccb79..944d77e745 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -97,10 +97,10 @@ namespace osu.Game.Storyboards // If the logic above fails to find anything or discarded by the fact that there are loops present, latestEndTime will be double.MaxValue // and thus conservativeEndTime will be used. - double conservativeEndTime = TimelineGroup.EndTime; + double conservativeEndTime = Commands.EndTime; - foreach (var l in loops) - conservativeEndTime = Math.Max(conservativeEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations); + foreach (var l in loopingGroups) + conservativeEndTime = Math.Max(conservativeEndTime, l.StartTime + l.Duration * l.TotalIterations); return Math.Min(latestEndTime, conservativeEndTime); } From c1649b76d638dbe0f32217be7027e7a98b5b6026 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 21:33:46 +0300 Subject: [PATCH 18/38] Reorder command properties to match general format I had them shuffled around in the middle of the refactor. --- .../TestSceneDrawableStoryboardSprite.cs | 2 +- .../Visual/Gameplay/TestSceneLeadIn.cs | 12 +++--- .../Gameplay/TestSceneStoryboardWithOutro.cs | 2 +- .../TestSceneMultiSpectatorScreen.cs | 2 +- .../Formats/LegacyStoryboardDecoder.cs | 28 ++++++------- .../Commands/StoryboardAlphaCommand.cs | 4 +- .../StoryboardBlendingParametersCommand.cs | 4 +- .../Commands/StoryboardColourCommand.cs | 4 +- .../Storyboards/Commands/StoryboardCommand.cs | 2 +- .../Commands/StoryboardCommandGroup.cs | 40 +++++++++---------- .../Commands/StoryboardFlipHCommand.cs | 4 +- .../Commands/StoryboardFlipVCommand.cs | 4 +- .../Commands/StoryboardLoopingGroup.cs | 2 +- .../Commands/StoryboardRotationCommand.cs | 4 +- .../Commands/StoryboardScaleCommand.cs | 4 +- .../Commands/StoryboardVectorScaleCommand.cs | 4 +- .../Commands/StoryboardXCommand.cs | 4 +- .../Commands/StoryboardYCommand.cs | 4 +- 18 files changed, 65 insertions(+), 65 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs index 6209b42cbb..6bfa141d85 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs @@ -176,7 +176,7 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite(lookupName, origin, initialPosition); var loop = sprite.AddLoopingGroup(Time.Current, 100); - loop.AddAlpha(0, 10000, 1, 1, Easing.None); + loop.AddAlpha(Easing.None, 0, 10000, 1, 1); layer.Elements.Clear(); layer.Add(sprite); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs index b2196e77b4..5a71369976 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs @@ -47,7 +47,7 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.Commands.AddAlpha(firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1, Easing.None); + sprite.Commands.AddAlpha(Easing.None, firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1); storyboard.GetLayer("Background").Add(sprite); @@ -73,17 +73,17 @@ namespace osu.Game.Tests.Visual.Gameplay var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); // these should be ignored as we have an alpha visibility blocker proceeding this command. - sprite.Commands.AddScale(loop_start_time, -18000, 0, 1, Easing.None); + sprite.Commands.AddScale(Easing.None, loop_start_time, -18000, 0, 1); var loopGroup = sprite.AddLoopingGroup(loop_start_time, 50); - loopGroup.AddScale(loop_start_time, -18000, 0, 1, Easing.None); + loopGroup.AddScale(Easing.None, loop_start_time, -18000, 0, 1); var target = addEventToLoop ? loopGroup : sprite.Commands; double loopRelativeOffset = addEventToLoop ? -loop_start_time : 0; - target.AddAlpha(loopRelativeOffset + firstStoryboardEvent, loopRelativeOffset + firstStoryboardEvent + 500, 0, 1, Easing.None); + target.AddAlpha(Easing.None, loopRelativeOffset + firstStoryboardEvent, loopRelativeOffset + firstStoryboardEvent + 500, 0, 1); // these should be ignored due to being in the future. - sprite.Commands.AddAlpha(18000, 20000, 0, 1, Easing.None); - loopGroup.AddAlpha(38000, 40000, 0, 1, Easing.None); + sprite.Commands.AddAlpha(Easing.None, 18000, 20000, 0, 1); + loopGroup.AddAlpha(Easing.None, 38000, 40000, 0, 1); storyboard.GetLayer("Background").Add(sprite); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs index 8bdb7297fe..aff6139c08 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs @@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.Gameplay { var storyboard = new Storyboard(); var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.Commands.AddAlpha(0, duration, 1, 0, Easing.None); + sprite.Commands.AddAlpha(Easing.None, 0, duration, 1, 0); storyboard.GetLayer("Background").Add(sprite); return storyboard; } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs index 7cd2e2fdaa..2b17f91e68 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs @@ -424,7 +424,7 @@ namespace osu.Game.Tests.Visual.Multiplayer public void TestIntroStoryboardElement() => testLeadIn(b => { var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.Commands.AddAlpha(-2000, 0, 0, 1, Easing.None); + sprite.Commands.AddAlpha(Easing.None, -2000, 0, 0, 1); b.Storyboard.GetLayer("Background").Add(sprite); }); diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index 739e81a2fe..195d59d0eb 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -204,7 +204,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentCommandsGroup?.AddAlpha(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddAlpha(easing, startTime, endTime, startValue, endValue); break; } @@ -212,7 +212,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentCommandsGroup?.AddScale(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddScale(easing, startTime, endTime, startValue, endValue); break; } @@ -222,7 +222,7 @@ namespace osu.Game.Beatmaps.Formats float startY = Parsing.ParseFloat(split[5]); float endX = split.Length > 6 ? Parsing.ParseFloat(split[6]) : startX; float endY = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startY; - currentCommandsGroup?.AddVectorScale(startTime, endTime, new Vector2(startX, startY), new Vector2(endX, endY), easing); + currentCommandsGroup?.AddVectorScale(easing, startTime, endTime, new Vector2(startX, startY), new Vector2(endX, endY)); break; } @@ -230,7 +230,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentCommandsGroup?.AddRotation(startTime, endTime, float.RadiansToDegrees(startValue), float.RadiansToDegrees(endValue), easing); + currentCommandsGroup?.AddRotation(easing, startTime, endTime, float.RadiansToDegrees(startValue), float.RadiansToDegrees(endValue)); break; } @@ -240,8 +240,8 @@ namespace osu.Game.Beatmaps.Formats float startY = Parsing.ParseFloat(split[5]); float endX = split.Length > 6 ? Parsing.ParseFloat(split[6]) : startX; float endY = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startY; - currentCommandsGroup?.AddX(startTime, endTime, startX, endX, easing); - currentCommandsGroup?.AddY(startTime, endTime, startY, endY, easing); + currentCommandsGroup?.AddX(easing, startTime, endTime, startX, endX); + currentCommandsGroup?.AddY(easing, startTime, endTime, startY, endY); break; } @@ -249,7 +249,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentCommandsGroup?.AddX(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddX(easing, startTime, endTime, startValue, endValue); break; } @@ -257,7 +257,7 @@ namespace osu.Game.Beatmaps.Formats { float startValue = Parsing.ParseFloat(split[4]); float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue; - currentCommandsGroup?.AddY(startTime, endTime, startValue, endValue, easing); + currentCommandsGroup?.AddY(easing, startTime, endTime, startValue, endValue); break; } @@ -269,9 +269,9 @@ namespace osu.Game.Beatmaps.Formats float endRed = split.Length > 7 ? Parsing.ParseFloat(split[7]) : startRed; float endGreen = split.Length > 8 ? Parsing.ParseFloat(split[8]) : startGreen; float endBlue = split.Length > 9 ? Parsing.ParseFloat(split[9]) : startBlue; - currentCommandsGroup?.AddColour(startTime, endTime, + currentCommandsGroup?.AddColour(easing, startTime, endTime, new Color4(startRed / 255f, startGreen / 255f, startBlue / 255f, 1), - new Color4(endRed / 255f, endGreen / 255f, endBlue / 255f, 1), easing); + new Color4(endRed / 255f, endGreen / 255f, endBlue / 255f, 1)); break; } @@ -282,16 +282,16 @@ namespace osu.Game.Beatmaps.Formats switch (type) { case "A": - currentCommandsGroup?.AddBlendingParameters(startTime, endTime, BlendingParameters.Additive, - startTime == endTime ? BlendingParameters.Additive : BlendingParameters.Inherit, easing); + currentCommandsGroup?.AddBlendingParameters(easing, startTime, endTime, BlendingParameters.Additive, + startTime == endTime ? BlendingParameters.Additive : BlendingParameters.Inherit); break; case "H": - currentCommandsGroup?.AddFlipH(startTime, endTime, true, startTime == endTime, easing); + currentCommandsGroup?.AddFlipH(easing, startTime, endTime, true, startTime == endTime); break; case "V": - currentCommandsGroup?.AddFlipV(startTime, endTime, true, startTime == endTime, easing); + currentCommandsGroup?.AddFlipV(easing, startTime, endTime, true, startTime == endTime); break; } diff --git a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs index f4a90b372a..1c17da7592 100644 --- a/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardAlphaCommand.cs @@ -8,8 +8,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardAlphaCommand : StoryboardCommand { - public StoryboardAlphaCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardAlphaCommand(Easing easing, double startTime, double endTime, float startValue, float endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs index 3e2e8bb0e8..9ac6613708 100644 --- a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs @@ -8,8 +8,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardBlendingParametersCommand : StoryboardCommand { - public StoryboardBlendingParametersCommand(double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardBlendingParametersCommand(Easing easing, double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs index 66390eb305..da8a20647c 100644 --- a/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardColourCommand.cs @@ -9,8 +9,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardColourCommand : StoryboardCommand { - public StoryboardColourCommand(double startTime, double endTime, Color4 startValue, Color4 endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardColourCommand(Easing easing, double startTime, double endTime, Color4 startValue, Color4 endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardCommand.cs b/osu.Game/Storyboards/Commands/StoryboardCommand.cs index 4f2f0f04a2..60c28e7833 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommand.cs @@ -19,7 +19,7 @@ namespace osu.Game.Storyboards.Commands public double Duration => EndTime - StartTime; - protected StoryboardCommand(double startTime, double endTime, T startValue, T endValue, Easing easing) + protected StoryboardCommand(Easing easing, double startTime, double endTime, T startValue, T endValue) { if (endTime < startTime) endTime = startTime; diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs index fb847d2e44..40dd8f78e6 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs @@ -45,35 +45,35 @@ namespace osu.Game.Storyboards.Commands [JsonIgnore] public bool HasCommands { get; private set; } - public void AddX(double startTime, double endTime, float startValue, float endValue, Easing easing) - => AddCommand(X, new StoryboardXCommand(startTime, endTime, startValue, endValue, easing)); + public void AddX(Easing easing, double startTime, double endTime, float startValue, float endValue) + => AddCommand(X, new StoryboardXCommand(easing, startTime, endTime, startValue, endValue)); - public void AddY(double startTime, double endTime, float startValue, float endValue, Easing easing) - => AddCommand(Y, new StoryboardYCommand(startTime, endTime, startValue, endValue, easing)); + public void AddY(Easing easing, double startTime, double endTime, float startValue, float endValue) + => AddCommand(Y, new StoryboardYCommand(easing, startTime, endTime, startValue, endValue)); - public void AddScale(double startTime, double endTime, float startValue, float endValue, Easing easing) - => AddCommand(Scale, new StoryboardScaleCommand(startTime, endTime, startValue, endValue, easing)); + public void AddScale(Easing easing, double startTime, double endTime, float startValue, float endValue) + => AddCommand(Scale, new StoryboardScaleCommand(easing, startTime, endTime, startValue, endValue)); - public void AddVectorScale(double startTime, double endTime, Vector2 startValue, Vector2 endValue, Easing easing) - => AddCommand(VectorScale, new StoryboardVectorScaleCommand(startTime, endTime, startValue, endValue, easing)); + public void AddVectorScale(Easing easing, double startTime, double endTime, Vector2 startValue, Vector2 endValue) + => AddCommand(VectorScale, new StoryboardVectorScaleCommand(easing, startTime, endTime, startValue, endValue)); - public void AddRotation(double startTime, double endTime, float startValue, float endValue, Easing easing) - => AddCommand(Rotation, new StoryboardRotationCommand(startTime, endTime, startValue, endValue, easing)); + public void AddRotation(Easing easing, double startTime, double endTime, float startValue, float endValue) + => AddCommand(Rotation, new StoryboardRotationCommand(easing, startTime, endTime, startValue, endValue)); - public void AddColour(double startTime, double endTime, Color4 startValue, Color4 endValue, Easing easing) - => AddCommand(Colour, new StoryboardColourCommand(startTime, endTime, startValue, endValue, easing)); + public void AddColour(Easing easing, double startTime, double endTime, Color4 startValue, Color4 endValue) + => AddCommand(Colour, new StoryboardColourCommand(easing, startTime, endTime, startValue, endValue)); - public void AddAlpha(double startTime, double endTime, float startValue, float endValue, Easing easing) - => AddCommand(Alpha, new StoryboardAlphaCommand(startTime, endTime, startValue, endValue, easing)); + public void AddAlpha(Easing easing, double startTime, double endTime, float startValue, float endValue) + => AddCommand(Alpha, new StoryboardAlphaCommand(easing, startTime, endTime, startValue, endValue)); - public void AddBlendingParameters(double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue, Easing easing) - => AddCommand(BlendingParameters, new StoryboardBlendingParametersCommand(startTime, endTime, startValue, endValue, easing)); + public void AddBlendingParameters(Easing easing, double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue) + => AddCommand(BlendingParameters, new StoryboardBlendingParametersCommand(easing, startTime, endTime, startValue, endValue)); - public void AddFlipH(double startTime, double endTime, bool startValue, bool endValue, Easing easing) - => AddCommand(FlipH, new StoryboardFlipHCommand(startTime, endTime, startValue, endValue, easing)); + public void AddFlipH(Easing easing, double startTime, double endTime, bool startValue, bool endValue) + => AddCommand(FlipH, new StoryboardFlipHCommand(easing, startTime, endTime, startValue, endValue)); - public void AddFlipV(double startTime, double endTime, bool startValue, bool endValue, Easing easing) - => AddCommand(FlipV, new StoryboardFlipVCommand(startTime, endTime, startValue, endValue, easing)); + public void AddFlipV(Easing easing, double startTime, double endTime, bool startValue, bool endValue) + => AddCommand(FlipV, new StoryboardFlipVCommand(easing, startTime, endTime, startValue, endValue)); /// /// Adds the given storyboard to the target . diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs index 26aef23226..fa07ff6645 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs @@ -9,8 +9,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardFlipHCommand : StoryboardCommand { - public StoryboardFlipHCommand(double startTime, double endTime, bool startValue, bool endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardFlipHCommand(Easing easing, double startTime, double endTime, bool startValue, bool endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs index 88423da2af..fa6a170c25 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs @@ -9,8 +9,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardFlipVCommand : StoryboardCommand { - public StoryboardFlipVCommand(double startTime, double endTime, bool startValue, bool endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardFlipVCommand(Easing easing, double startTime, double endTime, bool startValue, bool endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs index e97de84ab7..a886998679 100644 --- a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs @@ -43,7 +43,7 @@ namespace osu.Game.Storyboards.Commands // In an ideal world, we would multiply the command duration by TotalIterations in command end time. // Unfortunately this would clash with how stable handled end times, and results in some storyboards playing outro // sequences for minutes or hours. - : base(loopingGroup.loopStartTime + command.StartTime, loopingGroup.loopStartTime + command.EndTime, command.StartValue, command.EndValue, command.Easing) + : base(command.Easing, loopingGroup.loopStartTime + command.StartTime, loopingGroup.loopStartTime + command.EndTime, command.StartValue, command.EndValue) { this.command = command; this.loopingGroup = loopingGroup; diff --git a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs index 4347dc9d77..7e097fce25 100644 --- a/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardRotationCommand.cs @@ -8,8 +8,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardRotationCommand : StoryboardCommand { - public StoryboardRotationCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardRotationCommand(Easing easing, double startTime, double endTime, float startValue, float endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs index b0f33fd6b8..832533af5e 100644 --- a/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardScaleCommand.cs @@ -9,8 +9,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardScaleCommand : StoryboardCommand { - public StoryboardScaleCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardScaleCommand(Easing easing, double startTime, double endTime, float startValue, float endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs index 5d3fef5948..06983a1590 100644 --- a/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardVectorScaleCommand.cs @@ -10,8 +10,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardVectorScaleCommand : StoryboardCommand { - public StoryboardVectorScaleCommand(double startTime, double endTime, Vector2 startValue, Vector2 endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardVectorScaleCommand(Easing easing, double startTime, double endTime, Vector2 startValue, Vector2 endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs index 7df9a75768..d52e9c8a05 100644 --- a/osu.Game/Storyboards/Commands/StoryboardXCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardXCommand.cs @@ -8,8 +8,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardXCommand : StoryboardCommand { - public StoryboardXCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardXCommand(Easing easing, double startTime, double endTime, float startValue, float endValue) + : base(easing, startTime, endTime, startValue, endValue) { } diff --git a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs index d7dc32a0f3..90dfe4d995 100644 --- a/osu.Game/Storyboards/Commands/StoryboardYCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardYCommand.cs @@ -8,8 +8,8 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardYCommand : StoryboardCommand { - public StoryboardYCommand(double startTime, double endTime, float startValue, float endValue, Easing easing) - : base(startTime, endTime, startValue, endValue, easing) + public StoryboardYCommand(Easing easing, double startTime, double endTime, float startValue, float endValue) + : base(easing, startTime, endTime, startValue, endValue) { } From 0efa12a86a5b3f19251e90b65f80f523a9ded5bc Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 21:52:56 +0300 Subject: [PATCH 19/38] Fix parameter commands applying initial value before start time --- osu.Game/Storyboards/Commands/IStoryboardCommand.cs | 3 +++ .../Commands/StoryboardBlendingParametersCommand.cs | 6 +++++- osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs | 6 +++++- osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs | 6 +++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs index 6efb19afe4..ea14f5fa40 100644 --- a/osu.Game/Storyboards/Commands/IStoryboardCommand.cs +++ b/osu.Game/Storyboards/Commands/IStoryboardCommand.cs @@ -28,6 +28,9 @@ namespace osu.Game.Storyboards.Commands /// /// Sets the value of the corresponding property in to the start value of this command. /// + /// + /// Parameter commands (e.g. / / ) only apply the start value if they have zero duration, i.e. take "permanent" effect regardless of time. + /// /// The target drawable. void ApplyInitialValue(TDrawable d) where TDrawable : Drawable, IFlippable, IVectorScalable; diff --git a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs index 9ac6613708..cf9cadf1a7 100644 --- a/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardBlendingParametersCommand.cs @@ -15,7 +15,11 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(Drawable.Blending); - public override void ApplyInitialValue(TDrawable d) => d.Blending = StartValue; + public override void ApplyInitialValue(TDrawable d) + { + if (StartTime == EndTime) + d.Blending = StartValue; + } public override TransformSequence ApplyTransforms(TDrawable d) => d.TransformTo(nameof(d.Blending), StartValue).Delay(Duration) diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs index fa07ff6645..fbf7295f15 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipHCommand.cs @@ -16,7 +16,11 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(IFlippable.FlipH); - public override void ApplyInitialValue(TDrawable d) => d.FlipH = StartValue; + public override void ApplyInitialValue(TDrawable d) + { + if (StartTime == EndTime) + d.FlipH = StartValue; + } public override TransformSequence ApplyTransforms(TDrawable d) => d.TransformTo(nameof(IFlippable.FlipH), StartValue).Delay(Duration) diff --git a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs index fa6a170c25..136bd52f1f 100644 --- a/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs +++ b/osu.Game/Storyboards/Commands/StoryboardFlipVCommand.cs @@ -16,7 +16,11 @@ namespace osu.Game.Storyboards.Commands public override string PropertyName => nameof(IFlippable.FlipV); - public override void ApplyInitialValue(TDrawable d) => d.FlipV = StartValue; + public override void ApplyInitialValue(TDrawable d) + { + if (StartTime == EndTime) + d.FlipV = StartValue; + } public override TransformSequence ApplyTransforms(TDrawable d) => d.TransformTo(nameof(IFlippable.FlipV), StartValue).Delay(Duration) From 6861d9a302f2995ac05ff717e8911d9eabe3e25b Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 22:28:13 +0300 Subject: [PATCH 20/38] Expose storyboard command lists as read-only and remove unnecessary memory footprint Mutation should be done only with the methods exposed by `StoryboardCommandGroup`. --- .../Commands/StoryboardCommandGroup.cs | 80 +++++++++++++------ 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs index 40dd8f78e6..0925231412 100644 --- a/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardCommandGroup.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; using osu.Framework.Graphics; using osu.Framework.Lists; @@ -12,20 +13,45 @@ namespace osu.Game.Storyboards.Commands { public class StoryboardCommandGroup { - public SortedList> X = new SortedList>(); - public SortedList> Y = new SortedList>(); - public SortedList> Scale = new SortedList>(); - public SortedList> VectorScale = new SortedList>(); - public SortedList> Rotation = new SortedList>(); - public SortedList> Colour = new SortedList>(); - public SortedList> Alpha = new SortedList>(); - public SortedList> BlendingParameters = new SortedList>(); - public SortedList> FlipH = new SortedList>(); - public SortedList> FlipV = new SortedList>(); + private readonly SortedList> x = new SortedList>(); - public IReadOnlyList AllCommands => allCommands; + public IReadOnlyList> X => x; - private readonly List allCommands = new List(); + private readonly SortedList> y = new SortedList>(); + + public IReadOnlyList> Y => y; + + private readonly SortedList> scale = new SortedList>(); + + public IReadOnlyList> Scale => scale; + + private readonly SortedList> vectorScale = new SortedList>(); + + public IReadOnlyList> VectorScale => vectorScale; + + private readonly SortedList> rotation = new SortedList>(); + + public IReadOnlyList> Rotation => rotation; + + private readonly SortedList> colour = new SortedList>(); + + public IReadOnlyList> Colour => colour; + + private readonly SortedList> alpha = new SortedList>(); + + public IReadOnlyList> Alpha => alpha; + + private readonly SortedList> blendingParameters = new SortedList>(); + + public IReadOnlyList> BlendingParameters => blendingParameters; + + private readonly SortedList> flipH = new SortedList>(); + + public IReadOnlyList> FlipH => flipH; + + private readonly SortedList> flipV = new SortedList>(); + + public IReadOnlyList> FlipV => flipV; /// /// Returns the earliest start time of the commands added to this group. @@ -45,35 +71,44 @@ namespace osu.Game.Storyboards.Commands [JsonIgnore] public bool HasCommands { get; private set; } + private readonly IReadOnlyList[] lists; + + public IEnumerable AllCommands => lists.SelectMany(g => g); + + public StoryboardCommandGroup() + { + lists = new IReadOnlyList[] { X, Y, Scale, VectorScale, Rotation, Colour, Alpha, BlendingParameters, FlipH, FlipV }; + } + public void AddX(Easing easing, double startTime, double endTime, float startValue, float endValue) - => AddCommand(X, new StoryboardXCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(x, new StoryboardXCommand(easing, startTime, endTime, startValue, endValue)); public void AddY(Easing easing, double startTime, double endTime, float startValue, float endValue) - => AddCommand(Y, new StoryboardYCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(y, new StoryboardYCommand(easing, startTime, endTime, startValue, endValue)); public void AddScale(Easing easing, double startTime, double endTime, float startValue, float endValue) - => AddCommand(Scale, new StoryboardScaleCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(scale, new StoryboardScaleCommand(easing, startTime, endTime, startValue, endValue)); public void AddVectorScale(Easing easing, double startTime, double endTime, Vector2 startValue, Vector2 endValue) - => AddCommand(VectorScale, new StoryboardVectorScaleCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(vectorScale, new StoryboardVectorScaleCommand(easing, startTime, endTime, startValue, endValue)); public void AddRotation(Easing easing, double startTime, double endTime, float startValue, float endValue) - => AddCommand(Rotation, new StoryboardRotationCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(rotation, new StoryboardRotationCommand(easing, startTime, endTime, startValue, endValue)); public void AddColour(Easing easing, double startTime, double endTime, Color4 startValue, Color4 endValue) - => AddCommand(Colour, new StoryboardColourCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(colour, new StoryboardColourCommand(easing, startTime, endTime, startValue, endValue)); public void AddAlpha(Easing easing, double startTime, double endTime, float startValue, float endValue) - => AddCommand(Alpha, new StoryboardAlphaCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(alpha, new StoryboardAlphaCommand(easing, startTime, endTime, startValue, endValue)); public void AddBlendingParameters(Easing easing, double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue) - => AddCommand(BlendingParameters, new StoryboardBlendingParametersCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(blendingParameters, new StoryboardBlendingParametersCommand(easing, startTime, endTime, startValue, endValue)); public void AddFlipH(Easing easing, double startTime, double endTime, bool startValue, bool endValue) - => AddCommand(FlipH, new StoryboardFlipHCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(flipH, new StoryboardFlipHCommand(easing, startTime, endTime, startValue, endValue)); public void AddFlipV(Easing easing, double startTime, double endTime, bool startValue, bool endValue) - => AddCommand(FlipV, new StoryboardFlipVCommand(easing, startTime, endTime, startValue, endValue)); + => AddCommand(flipV, new StoryboardFlipVCommand(easing, startTime, endTime, startValue, endValue)); /// /// Adds the given storyboard to the target . @@ -83,7 +118,6 @@ namespace osu.Game.Storyboards.Commands protected virtual void AddCommand(ICollection> list, StoryboardCommand command) { list.Add(command); - allCommands.Add(command); HasCommands = true; if (command.StartTime < StartTime) From 1942d46a38fac400e28dbe95a3d5a2d6c0a95cc2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 22:37:27 +0300 Subject: [PATCH 21/38] Remove leftover debugging code --- osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs index 507a51aca4..da4b5c641d 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs @@ -102,9 +102,6 @@ namespace osu.Game.Storyboards.Drawables else Texture = textureStore.Get(Sprite.Path); - if (Sprite.Path == "SB/textbox.png") - Debugger.Break(); - Sprite.ApplyTransforms(this); } From 8c92bb0595f6528c86c39a0851fd7e6edd8be5f6 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 23:09:16 +0300 Subject: [PATCH 22/38] Remove unused using directive --- osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs index da4b5c641d..ec875219b6 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; From 9f71eac1dbe26df48cdcdaff181a0ca6be71f219 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 8 Mar 2024 23:09:50 +0300 Subject: [PATCH 23/38] Remove extra end line --- osu.Game/Storyboards/StoryboardSprite.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 944d77e745..80a76cd831 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -195,4 +195,3 @@ namespace osu.Game.Storyboards public override string ToString() => $"{Path}, {Origin}, {InitialPosition}"; } } - From 82048df9f16607c8b9887ddf91cf880fdb5927c3 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 9 Mar 2024 04:42:17 +0300 Subject: [PATCH 24/38] Add basic test scene for asserting storyboard commands behaviour Pending actual test coverage. --- .../Gameplay/TestSceneStoryboardCommands.cs | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs new file mode 100644 index 0000000000..1893182b32 --- /dev/null +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs @@ -0,0 +1,166 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.IO.Stores; +using osu.Framework.Timing; +using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Mods; +using osu.Game.Storyboards; +using osu.Game.Storyboards.Drawables; +using osu.Game.Tests.Resources; +using osuTK; + +namespace osu.Game.Tests.Visual.Gameplay +{ + public partial class TestSceneStoryboardCommands : OsuTestScene + { + [Cached(typeof(Storyboard))] + private TestStoryboard storyboard { get; set; } = new TestStoryboard + { + UseSkinSprites = false, + AlwaysProvideTexture = true, + }; + + private readonly ManualClock manualClock = new ManualClock { Rate = 1, IsRunning = true }; + private bool forward; + + private const string lookup_name = "hitcircleoverlay"; + private const double clock_limit = 2500; + + protected override Container Content => content; + + private Container content = null!; + private SpriteText timelineText = null!; + private Box timelineMarker = null!; + + [BackgroundDependencyLoader] + private void load() + { + base.Content.Children = new Drawable[] + { + content = new Container + { + RelativeSizeAxes = Axes.Both, + }, + timelineText = new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Bottom = 60 }, + }, + timelineMarker = new Box + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomCentre, + RelativePositionAxes = Axes.X, + Size = new Vector2(2, 50), + }, + }; + } + + [SetUp] + public void SetUp() + { + manualClock.CurrentTime = 0; + forward = true; + } + + [Test] + public void TestLoop() + { + AddStep("create sprite", () => Child = createSprite(s => + { + var loop = s.AddLoopingGroup(600, 10); + loop.AddY(Easing.OutBounce, 0, 500, 100, 240); + loop.AddY(Easing.OutQuint, 700, 1000, 240, 100); + })); + } + + protected override void Update() + { + base.Update(); + + if (manualClock.CurrentTime > clock_limit || manualClock.CurrentTime < 0) + forward = !forward; + + manualClock.CurrentTime += Time.Elapsed * (forward ? 1 : -1); + timelineText.Text = $"Time: {manualClock.CurrentTime:0}ms"; + timelineMarker.X = (float)(manualClock.CurrentTime / clock_limit); + } + + private DrawableStoryboard createSprite(Action? addCommands = null) + { + var layer = storyboard.GetLayer("Background"); + + var sprite = new StoryboardSprite(lookup_name, Anchor.Centre, new Vector2(320, 240)); + sprite.Commands.AddScale(Easing.None, 0, clock_limit, 0.5f, 0.5f); + sprite.Commands.AddAlpha(Easing.None, 0, clock_limit, 1, 1); + addCommands?.Invoke(sprite); + + layer.Elements.Clear(); + layer.Add(sprite); + + return storyboard.CreateDrawable().With(c => c.Clock = new FramedClock(manualClock)); + } + + private partial class TestStoryboard : Storyboard + { + public override DrawableStoryboard CreateDrawable(IReadOnlyList? mods = null) + { + return new TestDrawableStoryboard(this, mods); + } + + public bool AlwaysProvideTexture { get; set; } + + public override string GetStoragePathFromStoryboardPath(string path) => AlwaysProvideTexture ? path : string.Empty; + + private partial class TestDrawableStoryboard : DrawableStoryboard + { + private readonly bool alwaysProvideTexture; + + public TestDrawableStoryboard(TestStoryboard storyboard, IReadOnlyList? mods) + : base(storyboard, mods) + { + alwaysProvideTexture = storyboard.AlwaysProvideTexture; + } + + protected override IResourceStore CreateResourceLookupStore() => alwaysProvideTexture + ? new AlwaysReturnsTextureStore() + : new ResourceStore(); + + internal class AlwaysReturnsTextureStore : IResourceStore + { + private const string test_image = "Resources/Textures/test-image.png"; + + private readonly DllResourceStore store; + + public AlwaysReturnsTextureStore() + { + store = TestResources.GetStore(); + } + + public void Dispose() => store.Dispose(); + + public byte[] Get(string name) => store.Get(test_image); + + public Task GetAsync(string name, CancellationToken cancellationToken = new CancellationToken()) => store.GetAsync(test_image, cancellationToken); + + public Stream GetStream(string name) => store.GetStream(test_image); + + public IEnumerable GetAvailableResources() => store.GetAvailableResources(); + } + } + } + } +} From 8a1c5a754763cb8cc25963ab0e5b3439683a357a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 10 Mar 2024 07:23:22 +0300 Subject: [PATCH 25/38] Adjust time values --- .../Visual/Gameplay/TestSceneStoryboardCommands.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs index 1893182b32..11c07824d3 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs @@ -81,9 +81,9 @@ namespace osu.Game.Tests.Visual.Gameplay { AddStep("create sprite", () => Child = createSprite(s => { - var loop = s.AddLoopingGroup(600, 10); - loop.AddY(Easing.OutBounce, 0, 500, 100, 240); - loop.AddY(Easing.OutQuint, 700, 1000, 240, 100); + var loop = s.AddLoopingGroup(500, 10); + loop.AddY(Easing.OutBounce, 0, 600, 100, 240); + loop.AddY(Easing.OutQuint, 800, 1200, 240, 100); })); } From d039b565621790c8df3b5eaf0243deaa0cd9d5bb Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 10 Mar 2024 07:26:27 +0300 Subject: [PATCH 26/38] Add test case for running with high number of loops --- .../Visual/Gameplay/TestSceneStoryboardCommands.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs index 11c07824d3..1392cc3a21 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs @@ -87,6 +87,17 @@ namespace osu.Game.Tests.Visual.Gameplay })); } + [Test] + public void TestLoopManyTimes() + { + AddStep("create sprite", () => Child = createSprite(s => + { + var loop = s.AddLoopingGroup(500, 10000); + loop.AddY(Easing.OutBounce, 0, 60, 100, 240); + loop.AddY(Easing.OutQuint, 80, 120, 240, 100); + })); + } + protected override void Update() { base.Update(); From 99b06102b1bb67cd13c2e582c9796212d31c65d1 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 10 Mar 2024 09:01:31 +0300 Subject: [PATCH 27/38] Add enough test coverage --- .../Gameplay/TestSceneStoryboardCommands.cs | 115 +++++++++++++++--- 1 file changed, 101 insertions(+), 14 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs index 1392cc3a21..4af3d23463 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardCommands.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using NUnit.Framework; @@ -13,6 +14,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.IO.Stores; +using osu.Framework.Testing; using osu.Framework.Timing; using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Mods; @@ -33,7 +35,7 @@ namespace osu.Game.Tests.Visual.Gameplay }; private readonly ManualClock manualClock = new ManualClock { Rate = 1, IsRunning = true }; - private bool forward; + private int clockDirection; private const string lookup_name = "hitcircleoverlay"; private const double clock_limit = 2500; @@ -69,28 +71,75 @@ namespace osu.Game.Tests.Visual.Gameplay }; } - [SetUp] - public void SetUp() + [SetUpSteps] + public void SetUpSteps() { - manualClock.CurrentTime = 0; - forward = true; + AddStep("start clock", () => clockDirection = 1); + AddStep("pause clock", () => clockDirection = 0); + AddStep("set clock = 0", () => manualClock.CurrentTime = 0); } [Test] - public void TestLoop() + public void TestNormalCommandPlayback() { - AddStep("create sprite", () => Child = createSprite(s => + AddStep("create storyboard", () => Child = createStoryboard(s => { - var loop = s.AddLoopingGroup(500, 10); - loop.AddY(Easing.OutBounce, 0, 600, 100, 240); - loop.AddY(Easing.OutQuint, 800, 1200, 240, 100); + s.Commands.AddY(Easing.OutBounce, 500, 900, 100, 240); + s.Commands.AddY(Easing.OutQuint, 1100, 1500, 240, 100); })); + + assert(0, 100); + assert(500, 100); + assert(1000, 240); + assert(1500, 100); + assert(clock_limit, 100); + assert(1500, 100); + assert(1000, 240); + assert(500, 100); + assert(0, 100); + + void assert(double time, double y) + { + AddStep($"set clock = {time}", () => manualClock.CurrentTime = time); + AddAssert($"sprite y = {y} at t = {time}", () => this.ChildrenOfType().Single().Y == y); + } + } + + [Test] + public void TestLoopingCommandsPlayback() + { + AddStep("create storyboard", () => Child = createStoryboard(s => + { + var loop = s.AddLoopingGroup(250, 1); + loop.AddY(Easing.OutBounce, 0, 400, 100, 240); + loop.AddY(Easing.OutQuint, 600, 1000, 240, 100); + })); + + assert(0, 100); + assert(250, 100); + assert(850, 240); + assert(1250, 100); + assert(1850, 240); + assert(2250, 100); + assert(clock_limit, 100); + assert(2250, 100); + assert(1850, 240); + assert(1250, 100); + assert(850, 240); + assert(250, 100); + assert(0, 100); + + void assert(double time, double y) + { + AddStep($"set clock = {time}", () => manualClock.CurrentTime = time); + AddAssert($"sprite y = {y} at t = {time}", () => this.ChildrenOfType().Single().Y == y); + } } [Test] public void TestLoopManyTimes() { - AddStep("create sprite", () => Child = createSprite(s => + AddStep("create storyboard", () => Child = createStoryboard(s => { var loop = s.AddLoopingGroup(500, 10000); loop.AddY(Easing.OutBounce, 0, 60, 100, 240); @@ -98,19 +147,57 @@ namespace osu.Game.Tests.Visual.Gameplay })); } + [Test] + public void TestParameterTemporaryEffect() + { + AddStep("create storyboard", () => Child = createStoryboard(s => + { + s.Commands.AddFlipV(Easing.None, 1000, 1500, true, false); + })); + + AddAssert("sprite not flipped at t = 0", () => !this.ChildrenOfType().Single().FlipV); + + AddStep("set clock = 1250", () => manualClock.CurrentTime = 1250); + AddAssert("sprite flipped at t = 1250", () => this.ChildrenOfType().Single().FlipV); + + AddStep("set clock = 2000", () => manualClock.CurrentTime = 2000); + AddAssert("sprite not flipped at t = 2000", () => !this.ChildrenOfType().Single().FlipV); + + AddStep("resume clock", () => clockDirection = 1); + } + + [Test] + public void TestParameterPermanentEffect() + { + AddStep("create storyboard", () => Child = createStoryboard(s => + { + s.Commands.AddFlipV(Easing.None, 1000, 1000, true, true); + })); + + AddAssert("sprite flipped at t = 0", () => this.ChildrenOfType().Single().FlipV); + + AddStep("set clock = 1250", () => manualClock.CurrentTime = 1250); + AddAssert("sprite flipped at t = 1250", () => this.ChildrenOfType().Single().FlipV); + + AddStep("set clock = 2000", () => manualClock.CurrentTime = 2000); + AddAssert("sprite flipped at t = 2000", () => this.ChildrenOfType().Single().FlipV); + + AddStep("resume clock", () => clockDirection = 1); + } + protected override void Update() { base.Update(); if (manualClock.CurrentTime > clock_limit || manualClock.CurrentTime < 0) - forward = !forward; + clockDirection = -clockDirection; - manualClock.CurrentTime += Time.Elapsed * (forward ? 1 : -1); + manualClock.CurrentTime += Time.Elapsed * clockDirection; timelineText.Text = $"Time: {manualClock.CurrentTime:0}ms"; timelineMarker.X = (float)(manualClock.CurrentTime / clock_limit); } - private DrawableStoryboard createSprite(Action? addCommands = null) + private DrawableStoryboard createStoryboard(Action? addCommands = null) { var layer = storyboard.GetLayer("Background"); From 4ffeb5b469b86bdfbf80dde018fc3c9d32ec4e4b Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 1 May 2024 23:57:21 +0300 Subject: [PATCH 28/38] Resolve post-merge-conflict issues --- .../Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs | 4 ++-- .../Visual/Gameplay/TestSceneStoryboardWithIntro.cs | 2 +- osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs | 2 +- osu.Game/Storyboards/StoryboardVideo.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs index dd6f833ec5..800857c973 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneDrawableStoryboardSprite.cs @@ -85,8 +85,8 @@ namespace osu.Game.Tests.Visual.Gameplay if (scaleTransformProvided) { - sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current, Time.Current + 1000, 1, 2); - sprite.TimelineGroup.Scale.Add(Easing.None, Time.Current + 1000, Time.Current + 2000, 2, 1); + sprite.Commands.AddScale(Easing.None, Time.Current, Time.Current + 1000, 1, 2); + sprite.Commands.AddScale(Easing.None, Time.Current + 1000, Time.Current + 2000, 2, 1); } layer.Elements.Clear(); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithIntro.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithIntro.cs index 502a0de616..ee6a6938a9 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithIntro.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithIntro.cs @@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay { var storyboard = new Storyboard(); var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero); - sprite.TimelineGroup.Alpha.Add(Easing.None, startTime, 0, 0, 1); + sprite.Commands.AddAlpha(Easing.None, startTime, 0, 0, 1); storyboard.GetLayer("Background").Add(sprite); return storyboard; } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs index f2454be190..08c9459042 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs @@ -25,7 +25,7 @@ namespace osu.Game.Storyboards.Drawables // This allows scaling based on the video's absolute size. // // If not specified we take up the full available space. - bool useRelative = !video.TimelineGroup.Scale.HasCommands; + bool useRelative = !video.Commands.Scale.Any(); RelativeSizeAxes = useRelative ? Axes.Both : Axes.None; AutoSizeAxes = useRelative ? Axes.None : Axes.Both; diff --git a/osu.Game/Storyboards/StoryboardVideo.cs b/osu.Game/Storyboards/StoryboardVideo.cs index 5573162d26..14189a1a6c 100644 --- a/osu.Game/Storyboards/StoryboardVideo.cs +++ b/osu.Game/Storyboards/StoryboardVideo.cs @@ -14,7 +14,7 @@ namespace osu.Game.Storyboards { // This is just required to get a valid StartTime based on the incoming offset. // Actual fades are handled inside DrawableStoryboardVideo for now. - TimelineGroup.Alpha.Add(Easing.None, offset, offset, 0, 0); + Commands.AddAlpha(Easing.None, offset, offset, 0, 0); } public override Drawable CreateDrawable() => new DrawableStoryboardVideo(this); From 6d6f165884ab31f4aec606bae0ce6ee3eba4f9fd Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 2 May 2024 00:00:56 +0300 Subject: [PATCH 29/38] Make video sprites flippable and vector-scalable to fix type constraint errors Stable supports these on videos already from a quick read on code (since videos are generally a subclass of sprites). --- .../Drawables/DrawableStoryboardVideo.cs | 69 ++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs index 08c9459042..329564a345 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs @@ -1,11 +1,16 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.IO; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Video; +using osu.Framework.Utils; +using osuTK; namespace osu.Game.Storyboards.Drawables { @@ -13,7 +18,7 @@ namespace osu.Game.Storyboards.Drawables { public readonly StoryboardVideo Video; - private Video? drawableVideo; + private DrawableVideo? drawableVideo; public override bool RemoveWhenNotAlive => false; @@ -42,7 +47,7 @@ namespace osu.Game.Storyboards.Drawables if (stream == null) return; - InternalChild = drawableVideo = new Video(stream, false) + InternalChild = drawableVideo = new DrawableVideo(stream, false) { RelativeSizeAxes = RelativeSizeAxes, FillMode = FillMode.Fill, @@ -70,5 +75,65 @@ namespace osu.Game.Storyboards.Drawables drawableVideo.FadeOut(500); } } + + private partial class DrawableVideo : Video, IFlippable, IVectorScalable + { + private bool flipH; + + public bool FlipH + { + get => flipH; + set + { + if (flipH == value) + return; + + flipH = value; + Invalidate(Invalidation.MiscGeometry); + } + } + + private bool flipV; + + public bool FlipV + { + get => flipV; + set + { + if (flipV == value) + return; + + flipV = value; + Invalidate(Invalidation.MiscGeometry); + } + } + + private Vector2 vectorScale = Vector2.One; + + public Vector2 VectorScale + { + get => vectorScale; + set + { + if (vectorScale == value) + return; + + if (!Validation.IsFinite(value)) throw new ArgumentException($@"{nameof(VectorScale)} must be finite, but is {value}."); + + vectorScale = value; + Invalidate(Invalidation.MiscGeometry); + } + } + + protected override Vector2 DrawScale + => new Vector2(FlipH ? -base.DrawScale.X : base.DrawScale.X, FlipV ? -base.DrawScale.Y : base.DrawScale.Y) * VectorScale; + + public override Anchor Origin => StoryboardExtensions.AdjustOrigin(base.Origin, VectorScale, FlipH, FlipV); + + public DrawableVideo(Stream stream, bool startAtCurrentTime = true) + : base(stream, startAtCurrentTime) + { + } + } } } From b1aff91bba0d9aefdfb09d0e40e0b79673a691f3 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 2 May 2024 00:31:48 +0300 Subject: [PATCH 30/38] Use throw helper methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs index a886998679..fe334ad608 100644 --- a/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs +++ b/osu.Game/Storyboards/Commands/StoryboardLoopingGroup.cs @@ -23,7 +23,7 @@ namespace osu.Game.Storyboards.Commands /// The number of times the loop should repeat. Should be greater than zero. Zero means a single playback. public StoryboardLoopingGroup(double startTime, int repeatCount) { - if (repeatCount < 0) throw new ArgumentException("Repeat count must be zero or above.", nameof(repeatCount)); + ArgumentOutOfRangeException.ThrowIfNegative(repeatCount); loopStartTime = startTime; TotalIterations = repeatCount + 1; From 1b7652e60d37d496c9c1f01a984e22b743904d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 3 May 2024 13:47:10 +0200 Subject: [PATCH 31/38] Add failing tests --- osu.Game.Tests/Scores/IO/ImportScoreTest.cs | 192 ++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/osu.Game.Tests/Scores/IO/ImportScoreTest.cs b/osu.Game.Tests/Scores/IO/ImportScoreTest.cs index ebbc329b9d..eb2c098ab8 100644 --- a/osu.Game.Tests/Scores/IO/ImportScoreTest.cs +++ b/osu.Game.Tests/Scores/IO/ImportScoreTest.cs @@ -15,6 +15,7 @@ using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.IO.Archives; using osu.Game.Online.API; +using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu; @@ -23,6 +24,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Tests.Beatmaps.IO; using osu.Game.Tests.Resources; +using osu.Game.Users; namespace osu.Game.Tests.Scores.IO { @@ -284,6 +286,196 @@ namespace osu.Game.Tests.Scores.IO } } + [Test] + public void TestUserLookedUpForOnlineScore() + { + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) + { + try + { + var osu = LoadOsuIntoHost(host, true); + + var api = (DummyAPIAccess)osu.API; + api.HandleRequest = req => + { + switch (req) + { + case GetUserRequest userRequest: + userRequest.TriggerSuccess(new APIUser + { + Username = "Test user", + CountryCode = CountryCode.JP, + Id = 1234 + }); + return true; + + default: + return false; + } + }; + + var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely(); + + var toImport = new ScoreInfo + { + Rank = ScoreRank.B, + TotalScore = 987654, + Accuracy = 0.8, + MaxCombo = 500, + Combo = 250, + User = new APIUser { Username = "Test user" }, + Date = DateTimeOffset.Now, + OnlineID = 12345, + Ruleset = new OsuRuleset().RulesetInfo, + BeatmapInfo = beatmap.Beatmaps.First() + }; + + var imported = LoadScoreIntoOsu(osu, toImport); + + Assert.AreEqual(toImport.Rank, imported.Rank); + Assert.AreEqual(toImport.TotalScore, imported.TotalScore); + Assert.AreEqual(toImport.Accuracy, imported.Accuracy); + Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo); + Assert.AreEqual(toImport.User.Username, imported.User.Username); + Assert.AreEqual(toImport.Date, imported.Date); + Assert.AreEqual(toImport.OnlineID, imported.OnlineID); + Assert.AreEqual(toImport.User.Username, imported.RealmUser.Username); + Assert.AreEqual(1234, imported.RealmUser.OnlineID); + } + finally + { + host.Exit(); + } + } + } + + [Test] + public void TestUserLookedUpForLegacyOnlineScore() + { + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) + { + try + { + var osu = LoadOsuIntoHost(host, true); + + var api = (DummyAPIAccess)osu.API; + api.HandleRequest = req => + { + switch (req) + { + case GetUserRequest userRequest: + userRequest.TriggerSuccess(new APIUser + { + Username = "Test user", + CountryCode = CountryCode.JP, + Id = 1234 + }); + return true; + + default: + return false; + } + }; + + var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely(); + + var toImport = new ScoreInfo + { + Rank = ScoreRank.B, + TotalScore = 987654, + Accuracy = 0.8, + MaxCombo = 500, + Combo = 250, + User = new APIUser { Username = "Test user" }, + Date = DateTimeOffset.Now, + LegacyOnlineID = 12345, + Ruleset = new OsuRuleset().RulesetInfo, + BeatmapInfo = beatmap.Beatmaps.First() + }; + + var imported = LoadScoreIntoOsu(osu, toImport); + + Assert.AreEqual(toImport.Rank, imported.Rank); + Assert.AreEqual(toImport.TotalScore, imported.TotalScore); + Assert.AreEqual(toImport.Accuracy, imported.Accuracy); + Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo); + Assert.AreEqual(toImport.User.Username, imported.User.Username); + Assert.AreEqual(toImport.Date, imported.Date); + Assert.AreEqual(toImport.OnlineID, imported.OnlineID); + Assert.AreEqual(toImport.User.Username, imported.RealmUser.Username); + Assert.AreEqual(1234, imported.RealmUser.OnlineID); + } + finally + { + host.Exit(); + } + } + } + + [Test] + public void TestUserNotLookedUpForOfflineScore() + { + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) + { + try + { + var osu = LoadOsuIntoHost(host, true); + + var api = (DummyAPIAccess)osu.API; + api.HandleRequest = req => + { + switch (req) + { + case GetUserRequest userRequest: + userRequest.TriggerSuccess(new APIUser + { + Username = "Test user", + CountryCode = CountryCode.JP, + Id = 1234 + }); + return true; + + default: + return false; + } + }; + + var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely(); + + var toImport = new ScoreInfo + { + Rank = ScoreRank.B, + TotalScore = 987654, + Accuracy = 0.8, + MaxCombo = 500, + Combo = 250, + User = new APIUser { Username = "Test user" }, + Date = DateTimeOffset.Now, + OnlineID = -1, + LegacyOnlineID = -1, + Ruleset = new OsuRuleset().RulesetInfo, + BeatmapInfo = beatmap.Beatmaps.First() + }; + + var imported = LoadScoreIntoOsu(osu, toImport); + + Assert.AreEqual(toImport.Rank, imported.Rank); + Assert.AreEqual(toImport.TotalScore, imported.TotalScore); + Assert.AreEqual(toImport.Accuracy, imported.Accuracy); + Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo); + Assert.AreEqual(toImport.User.Username, imported.User.Username); + Assert.AreEqual(toImport.Date, imported.Date); + Assert.AreEqual(toImport.OnlineID, imported.OnlineID); + Assert.AreEqual(toImport.User.Username, imported.RealmUser.Username); + Assert.That(imported.RealmUser.OnlineID, Is.LessThanOrEqualTo(1)); + } + finally + { + host.Exit(); + } + } + } + public static ScoreInfo LoadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null) { // clone to avoid attaching the input score to realm. From afb491dff064967f4ccc6fe18f26e94e9322c570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 3 May 2024 13:48:06 +0200 Subject: [PATCH 32/38] Do not perform username lookups for scores without an online ID --- osu.Game/Scoring/ScoreImporter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Scoring/ScoreImporter.cs b/osu.Game/Scoring/ScoreImporter.cs index 768c28cc38..4ae8e51f6d 100644 --- a/osu.Game/Scoring/ScoreImporter.cs +++ b/osu.Game/Scoring/ScoreImporter.cs @@ -127,6 +127,9 @@ namespace osu.Game.Scoring if (model.RealmUser.OnlineID == APIUser.SYSTEM_USER_ID) return; + if (model.OnlineID < 0 && model.LegacyOnlineID <= 0) + return; + string username = model.RealmUser.Username; if (usernameLookupCache.TryGetValue(username, out var existing)) From cf313cd67f3c1a89b77edd90c94a73a5794e31d7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sat, 4 May 2024 21:53:48 +0300 Subject: [PATCH 33/38] Use single path to display slider control point connections --- .../TestScenePathControlPointVisualiser.cs | 35 ---------------- ...Piece.cs => PathControlPointConnection.cs} | 42 +++++-------------- .../Components/PathControlPointVisualiser.cs | 29 +------------ 3 files changed, 11 insertions(+), 95 deletions(-) rename osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/{PathControlPointConnectionPiece.cs => PathControlPointConnection.cs} (51%) diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePathControlPointVisualiser.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePathControlPointVisualiser.cs index 0ca30e00bc..9af028fd8c 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePathControlPointVisualiser.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestScenePathControlPointVisualiser.cs @@ -30,23 +30,6 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); }); - [Test] - public void TestAddOverlappingControlPoints() - { - createVisualiser(true); - - addControlPointStep(new Vector2(200)); - addControlPointStep(new Vector2(300)); - addControlPointStep(new Vector2(300)); - addControlPointStep(new Vector2(500, 300)); - - AddAssert("last connection displayed", () => - { - var lastConnection = visualiser.Connections.Last(c => c.ControlPoint.Position == new Vector2(300)); - return lastConnection.DrawWidth > 50; - }); - } - [Test] public void TestPerfectCurveTooManyPoints() { @@ -194,24 +177,6 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor addAssertPointPositionChanged(points, i); } - [Test] - public void TestStackingUpdatesConnectionPosition() - { - createVisualiser(true); - - Vector2 connectionPosition; - addControlPointStep(connectionPosition = new Vector2(300)); - addControlPointStep(new Vector2(600)); - - // Apply a big number in stacking so the person running the test can clearly see if it fails - AddStep("apply stacking", () => slider.StackHeightBindable.Value += 10); - - AddAssert($"Connection at {connectionPosition} changed", - () => visualiser.Connections[0].Position, - () => !Is.EqualTo(connectionPosition) - ); - } - private void addAssertPointPositionChanged(Vector2[] points, int index) { AddAssert($"Point at {points.ElementAt(index)} changed", diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnection.cs similarity index 51% rename from osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs rename to osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnection.cs index 9b3d8fc7a7..5706ed4baf 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnection.cs @@ -4,10 +4,7 @@ #nullable disable using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Lines; -using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Osu.Objects; using osuTK; @@ -15,36 +12,21 @@ using osuTK; namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components { /// - /// A visualisation of the line between two s. + /// A visualisation of the lines between s. /// - /// The type of which this visualises. - public partial class PathControlPointConnectionPiece : CompositeDrawable where T : OsuHitObject, IHasPath + /// The type of which this visualises. + public partial class PathControlPointConnection : SmoothPath where T : OsuHitObject, IHasPath { - public readonly PathControlPoint ControlPoint; - - private readonly Path path; private readonly T hitObject; - public int ControlPointIndex { get; set; } private IBindable hitObjectPosition; private IBindable pathVersion; private IBindable stackHeight; - public PathControlPointConnectionPiece(T hitObject, int controlPointIndex) + public PathControlPointConnection(T hitObject) { this.hitObject = hitObject; - ControlPointIndex = controlPointIndex; - - Origin = Anchor.Centre; - AutoSizeAxes = Axes.Both; - - ControlPoint = hitObject.Path.ControlPoints[controlPointIndex]; - - InternalChild = path = new SmoothPath - { - Anchor = Anchor.Centre, - PathRadius = 1 - }; + PathRadius = 1; } protected override void LoadComplete() @@ -68,18 +50,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components /// private void updateConnectingPath() { - Position = hitObject.StackedPosition + ControlPoint.Position; + Position = hitObject.StackedPosition; - path.ClearVertices(); + ClearVertices(); - int nextIndex = ControlPointIndex + 1; - if (nextIndex == 0 || nextIndex >= hitObject.Path.ControlPoints.Count) - return; + foreach (var controlPoint in hitObject.Path.ControlPoints) + AddVertex(controlPoint.Position); - path.AddVertex(Vector2.Zero); - path.AddVertex(hitObject.Path.ControlPoints[nextIndex].Position - ControlPoint.Position); - - path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero); + OriginPosition = PositionInBoundingBox(Vector2.Zero); } } } diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs index b2d1709531..7212de322d 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs @@ -37,7 +37,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; // allow context menu to appear outside of the playfield. internal readonly Container> Pieces; - internal readonly Container> Connections; private readonly IBindableList controlPoints = new BindableList(); private readonly T hitObject; @@ -63,7 +62,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components InternalChildren = new Drawable[] { - Connections = new Container> { RelativeSizeAxes = Axes.Both }, + new PathControlPointConnection(hitObject), Pieces = new Container> { RelativeSizeAxes = Axes.Both } }; } @@ -185,17 +184,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components case NotifyCollectionChangedAction.Add: Debug.Assert(e.NewItems != null); - // If inserting in the path (not appending), - // update indices of existing connections after insert location - if (e.NewStartingIndex < Pieces.Count) - { - foreach (var connection in Connections) - { - if (connection.ControlPointIndex >= e.NewStartingIndex) - connection.ControlPointIndex += e.NewItems.Count; - } - } - for (int i = 0; i < e.NewItems.Count; i++) { var point = (PathControlPoint)e.NewItems[i]; @@ -209,8 +197,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components d.DragInProgress = DragInProgress; d.DragEnded = DragEnded; })); - - Connections.Add(new PathControlPointConnectionPiece(hitObject, e.NewStartingIndex + i)); } break; @@ -222,19 +208,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components { foreach (var piece in Pieces.Where(p => p.ControlPoint == point).ToArray()) piece.RemoveAndDisposeImmediately(); - foreach (var connection in Connections.Where(c => c.ControlPoint == point).ToArray()) - connection.RemoveAndDisposeImmediately(); - } - - // If removing before the end of the path, - // update indices of connections after remove location - if (e.OldStartingIndex < Pieces.Count) - { - foreach (var connection in Connections) - { - if (connection.ControlPointIndex >= e.OldStartingIndex) - connection.ControlPointIndex -= e.OldItems.Count; - } } break; From e319a3e885e9ae7d545c70a274ecad87220f62c7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sat, 4 May 2024 22:07:08 +0300 Subject: [PATCH 34/38] Don't perform masking updates in PathControlPointVisualiser --- .../Sliders/Components/PathControlPointVisualiser.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs index 7212de322d..836d348ff4 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs @@ -77,6 +77,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components controlPoints.BindTo(hitObject.Path.ControlPoints); } + // Generally all the control points are within the visible area all the time. + public override bool UpdateSubTreeMasking(Drawable source, RectangleF maskingBounds) => true; + /// /// Handles correction of invalid path types. /// From 848e497c94d1d0a440cc74b05dfa441f19dfb40b Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 5 May 2024 21:32:25 +0300 Subject: [PATCH 35/38] Add "HP" to the abbreviations list --- osu.sln.DotSettings | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.sln.DotSettings b/osu.sln.DotSettings index 51af281ac6..08eb264aab 100644 --- a/osu.sln.DotSettings +++ b/osu.sln.DotSettings @@ -347,6 +347,7 @@ GL GLSL HID + HP HSL HSPA HSV From 1665c5e0e1e3e3434cd98c0f0075362b0e7ea5a5 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Sun, 5 May 2024 14:41:48 -0700 Subject: [PATCH 36/38] Use existing `AutomaticallyDownloadMissingBeatmaps` localisation on solo spectator screen --- osu.Game/Screens/Play/SoloSpectatorScreen.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/SoloSpectatorScreen.cs b/osu.Game/Screens/Play/SoloSpectatorScreen.cs index 2db751402c..95eb2d4376 100644 --- a/osu.Game/Screens/Play/SoloSpectatorScreen.cs +++ b/osu.Game/Screens/Play/SoloSpectatorScreen.cs @@ -16,6 +16,7 @@ using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Localisation; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; @@ -138,7 +139,7 @@ namespace osu.Game.Screens.Play }, automaticDownload = new SettingsCheckbox { - LabelText = "Automatically download beatmaps", + LabelText = OnlineSettingsStrings.AutomaticallyDownloadMissingBeatmaps, Current = config.GetBindable(OsuSetting.AutomaticallyDownloadMissingBeatmaps), Anchor = Anchor.Centre, Origin = Anchor.Centre, From eb92e8de370d5fff1407c64527b3760d6b63ac82 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Sun, 5 May 2024 15:15:14 -0700 Subject: [PATCH 37/38] Edit title/artist unicode values and add unicode toggle in test --- .../UserInterface/TestSceneNowPlayingOverlay.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs index 1670741cbd..d84089fb6f 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Overlays; @@ -21,8 +22,10 @@ namespace osu.Game.Tests.Visual.UserInterface private NowPlayingOverlay nowPlayingOverlay; [BackgroundDependencyLoader] - private void load() + private void load(FrameworkConfigManager frameworkConfig) { + AddToggleStep("toggle unicode", v => frameworkConfig.SetValue(FrameworkSetting.ShowUnicode, v)); + nowPlayingOverlay = new NowPlayingOverlay { Origin = Anchor.Centre, @@ -50,9 +53,9 @@ namespace osu.Game.Tests.Visual.UserInterface Metadata = { Artist = "very very very very very very very very very very verry long artist", - ArtistUnicode = "very very very very very very very very very very verry long artist", + ArtistUnicode = "very very very very very very very very very very verry long artist unicode", Title = "very very very very very verry long title", - TitleUnicode = "very very very very very verry long title", + TitleUnicode = "very very very very very verry long title unicode", } })); @@ -61,9 +64,9 @@ namespace osu.Game.Tests.Visual.UserInterface Metadata = { Artist = "very very very very very very very very very very verrry long artist", - ArtistUnicode = "very very very very very very very very very very verrry long artist", + ArtistUnicode = "not very long artist unicode", Title = "very very very very very verrry long title", - TitleUnicode = "very very very very very verrry long title", + TitleUnicode = "not very long title unicode", } })); From 359238395f273686b611ac87f5ae1ceef1072a04 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Sun, 5 May 2024 15:17:03 -0700 Subject: [PATCH 38/38] Fix now playing overlay text scroll breaking when toggling metadata language setting --- osu.Game/Overlays/NowPlayingOverlay.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 29052ace8e..76c8c237d5 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; @@ -479,6 +480,11 @@ namespace osu.Game.Overlays private OsuSpriteText mainSpriteText = null!; private OsuSpriteText fillerSpriteText = null!; + private Bindable showUnicode = null!; + + [Resolved] + private FrameworkConfigManager frameworkConfig { get; set; } = null!; + private LocalisableString text; public LocalisableString Text @@ -531,6 +537,9 @@ namespace osu.Game.Overlays { base.LoadComplete(); + showUnicode = frameworkConfig.GetBindable(FrameworkSetting.ShowUnicode); + showUnicode.BindValueChanged(_ => updateText()); + updateFontAndText(); }