Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite TransformSequence<> into a struct #6382

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions osu.Framework/Audio/IAdjustableAudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static TransformSequence<T> TempoTo<T, TEasing>(this T component, double
public static TransformSequence<T> VolumeTo<T, TEasing>(this TransformSequence<T> sequence, double newVolume, double duration, TEasing easing)
where T : class, IAdjustableAudioComponent, IDrawable
where TEasing : IEasingFunction
=> sequence.Append(o => o.TransformBindableTo(o.Volume, newVolume, duration, easing));
=> sequence.Next(out T t).TransformBindableTo(t.Volume, newVolume, duration, easing);

/// <summary>
/// Smoothly adjusts <see cref="IAdjustableAudioComponent.Balance"/> over time.
Expand All @@ -187,7 +187,7 @@ public static TransformSequence<T> VolumeTo<T, TEasing>(this TransformSequence<T
public static TransformSequence<T> BalanceTo<T, TEasing>(this TransformSequence<T> sequence, double newBalance, double duration, TEasing easing)
where T : class, IAdjustableAudioComponent, IDrawable
where TEasing : IEasingFunction
=> sequence.Append(o => o.TransformBindableTo(o.Balance, newBalance, duration, easing));
=> sequence.Next(out T t).TransformBindableTo(t.Balance, newBalance, duration, easing);

/// <summary>
/// Smoothly adjusts <see cref="IAdjustableAudioComponent.Frequency"/> over time.
Expand All @@ -196,7 +196,7 @@ public static TransformSequence<T> BalanceTo<T, TEasing>(this TransformSequence<
public static TransformSequence<T> FrequencyTo<T, TEasing>(this TransformSequence<T> sequence, double newFrequency, double duration, TEasing easing)
where T : class, IAdjustableAudioComponent, IDrawable
where TEasing : IEasingFunction
=> sequence.Append(o => o.TransformBindableTo(o.Frequency, newFrequency, duration, easing));
=> sequence.Next(out T t).TransformBindableTo(t.Frequency, newFrequency, duration, easing);

/// <summary>
/// Smoothly adjusts <see cref="IAdjustableAudioComponent.Tempo"/> over time.
Expand All @@ -205,7 +205,7 @@ public static TransformSequence<T> FrequencyTo<T, TEasing>(this TransformSequenc
public static TransformSequence<T> TempoTo<T, TEasing>(this TransformSequence<T> sequence, double newTempo, double duration, TEasing easing)
where T : class, IAdjustableAudioComponent, IDrawable
where TEasing : IEasingFunction
=> sequence.Append(o => o.TransformBindableTo(o.Tempo, newTempo, duration, easing));
=> sequence.Next(out T t).TransformBindableTo(t.Tempo, newTempo, duration, easing);

#endregion
}
Expand Down
16 changes: 11 additions & 5 deletions osu.Framework/Graphics/Containers/ModelBackedDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void loadDrawable(Func<Drawable?>? createDrawableFunc)
/// <param name="wrapper">The current <see cref="DelayedLoadWrapper"/>.</param>
private void finishLoad(DelayedLoadWrapper? wrapper)
{
TransformSequence<Drawable>? showTransforms = null;
TransformSequence<Drawable> showTransforms = default;

if (wrapper != null)
{
Expand All @@ -155,14 +155,20 @@ private void finishLoad(DelayedLoadWrapper? wrapper)
{
var lastWrapper = displayedWrapper;

TransformSequence<Drawable> hideTransforms = default;

// If the new wrapper is non-null, we need to wait for the show transformation to complete before hiding the old wrapper,
// otherwise, we can hide the old wrapper instantaneously and leave a blank display
var hideTransforms = wrapper == null
? ApplyHideTransforms(lastWrapper)
: ((Drawable)lastWrapper)?.Delay(TransformDuration)?.Append(ApplyHideTransforms);
if (wrapper == null)
hideTransforms = ApplyHideTransforms(lastWrapper);
else if (lastWrapper is Drawable last)
hideTransforms = last.Delay(TransformDuration).Next(ApplyHideTransforms);

// Expire the last wrapper after the front-most transform has completed (the last wrapper is assumed to be invisible by that point)
(showTransforms ?? hideTransforms)?.OnComplete(_ => lastWrapper?.Expire());
if (!showTransforms.IsEmpty)
showTransforms.OnComplete(_ => lastWrapper?.Expire());
else if (!hideTransforms.IsEmpty)
hideTransforms.OnComplete(_ => lastWrapper?.Expire());
}

displayedWrapper = wrapper;
Expand Down
Loading
Loading