From 75d0deef72ab44b075345f6f4aeddde4d1a52492 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 7 Sep 2022 17:38:00 +0900 Subject: [PATCH] Apply proposed changes to remove inheritance from `MasterGameplayClockContainer` --- .../NonVisual/GameplayClockContainerTest.cs | 6 +- .../Rulesets/UI/FrameStabilityContainer.cs | 7 ++- .../Screens/Play/GameplayClockContainer.cs | 5 +- .../Screens/Play/GameplayClockExtensions.cs | 8 ++- osu.Game/Screens/Play/IGameplayClock.cs | 6 +- .../Play/MasterGameplayClockContainer.cs | 57 +------------------ osu.Game/Screens/Play/Player.cs | 7 ++- 7 files changed, 24 insertions(+), 72 deletions(-) diff --git a/osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs b/osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs index 95bf1ab354..80f0aaeb55 100644 --- a/osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs +++ b/osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs @@ -1,8 +1,9 @@ // 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 NUnit.Framework; +using osu.Framework.Audio; +using osu.Framework.Bindables; using osu.Framework.Timing; using osu.Game.Screens.Play; @@ -23,11 +24,10 @@ namespace osu.Game.Tests.NonVisual private class TestGameplayClockContainer : GameplayClockContainer { - public override IEnumerable GameplayAdjustments => new[] { 2.0 }; - public TestGameplayClockContainer(IFrameBasedClock underlyingClock) : base(underlyingClock) { + GameplayAdjustments.AddAdjustment(AdjustableProperty.Frequency, new BindableDouble(2.0)); } } } diff --git a/osu.Game/Rulesets/UI/FrameStabilityContainer.cs b/osu.Game/Rulesets/UI/FrameStabilityContainer.cs index 4f4a2d908d..f0c7a398eb 100644 --- a/osu.Game/Rulesets/UI/FrameStabilityContainer.cs +++ b/osu.Game/Rulesets/UI/FrameStabilityContainer.cs @@ -2,10 +2,9 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -264,7 +263,9 @@ namespace osu.Game.Rulesets.UI public double StartTime => parentGameplayClock?.StartTime ?? 0; - public IEnumerable GameplayAdjustments => parentGameplayClock?.GameplayAdjustments ?? Enumerable.Empty(); + private readonly AudioAdjustments gameplayAdjustments = new AudioAdjustments(); + + public IAdjustableAudioComponent GameplayAdjustments => parentGameplayClock?.GameplayAdjustments ?? gameplayAdjustments; #endregion diff --git a/osu.Game/Screens/Play/GameplayClockContainer.cs b/osu.Game/Screens/Play/GameplayClockContainer.cs index 5dfaf2d584..e64c628fa0 100644 --- a/osu.Game/Screens/Play/GameplayClockContainer.cs +++ b/osu.Game/Screens/Play/GameplayClockContainer.cs @@ -2,9 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -45,7 +44,7 @@ namespace osu.Game.Screens.Play /// public double StartTime { get; protected set; } - public virtual IEnumerable GameplayAdjustments => Enumerable.Empty(); + public IAdjustableAudioComponent GameplayAdjustments { get; } = new AudioAdjustments(); private readonly BindableBool isPaused = new BindableBool(true); diff --git a/osu.Game/Screens/Play/GameplayClockExtensions.cs b/osu.Game/Screens/Play/GameplayClockExtensions.cs index b683c61f63..3cc12f7afe 100644 --- a/osu.Game/Screens/Play/GameplayClockExtensions.cs +++ b/osu.Game/Screens/Play/GameplayClockExtensions.cs @@ -13,10 +13,12 @@ namespace osu.Game.Screens.Play /// public static double GetTrueGameplayRate(this IGameplayClock clock) { + // To handle rewind, we still want to maintain the same direction as the underlying clock. double rate = Math.Sign(clock.Rate); - foreach (double a in clock.GameplayAdjustments) - rate *= a; - return rate; + + return rate + * clock.GameplayAdjustments.AggregateFrequency.Value + * clock.GameplayAdjustments.AggregateTempo.Value; } } } diff --git a/osu.Game/Screens/Play/IGameplayClock.cs b/osu.Game/Screens/Play/IGameplayClock.cs index 7c50b9d407..c58d2dbcac 100644 --- a/osu.Game/Screens/Play/IGameplayClock.cs +++ b/osu.Game/Screens/Play/IGameplayClock.cs @@ -1,7 +1,7 @@ // 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 osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Timing; @@ -19,9 +19,9 @@ namespace osu.Game.Screens.Play double StartTime { get; } /// - /// All adjustments applied to this clock which don't come from gameplay or mods. + /// All adjustments applied to this clock which come from gameplay or mods. /// - IEnumerable GameplayAdjustments { get; } + IAdjustableAudioComponent GameplayAdjustments { get; } IBindable IsPaused { get; } } diff --git a/osu.Game/Screens/Play/MasterGameplayClockContainer.cs b/osu.Game/Screens/Play/MasterGameplayClockContainer.cs index 7c30f86125..226ce8b0d8 100644 --- a/osu.Game/Screens/Play/MasterGameplayClockContainer.cs +++ b/osu.Game/Screens/Play/MasterGameplayClockContainer.cs @@ -2,13 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using osu.Framework.Audio; using osu.Framework.Audio.Track; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -25,7 +23,7 @@ namespace osu.Game.Screens.Play /// /// This is intended to be used as a single controller for gameplay, or as a reference source for other s. /// - public class MasterGameplayClockContainer : GameplayClockContainer, IBeatSyncProvider, IAdjustableAudioComponent + public class MasterGameplayClockContainer : GameplayClockContainer, IBeatSyncProvider { /// /// Duration before gameplay start time required before skip button displays. @@ -57,11 +55,6 @@ namespace osu.Game.Screens.Play /// private double? actualStopTime; - /// - /// Maintained solely to delegate pieces to (to maintain parent lookups). - /// - private readonly AudioContainer audioContainer; - /// /// Create a new master gameplay clock container. /// @@ -75,8 +68,6 @@ namespace osu.Game.Screens.Play this.skipTargetTime = skipTargetTime; StartTime = findEarliestStartTime(); - - AddInternal(audioContainer = new AudioContainer()); } private double findEarliestStartTime() @@ -202,6 +193,7 @@ namespace osu.Game.Screens.Play if (speedAdjustmentsApplied) return; + track.BindAdjustments(GameplayAdjustments); track.AddAdjustment(AdjustableProperty.Frequency, GameplayClock.ExternalPauseFrequencyAdjust); track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate); @@ -213,6 +205,7 @@ namespace osu.Game.Screens.Play if (!speedAdjustmentsApplied) return; + track.UnbindAdjustments(GameplayAdjustments); track.RemoveAdjustment(AdjustableProperty.Frequency, GameplayClock.ExternalPauseFrequencyAdjust); track.RemoveAdjustment(AdjustableProperty.Tempo, UserPlaybackRate); @@ -229,49 +222,5 @@ namespace osu.Game.Screens.Play IClock IBeatSyncProvider.Clock => this; ChannelAmplitudes IHasAmplitudes.CurrentAmplitudes => beatmap.TrackLoaded ? beatmap.Track.CurrentAmplitudes : ChannelAmplitudes.Empty; - - private readonly List> speedAdjustments = new List>(); - - public override IEnumerable GameplayAdjustments => speedAdjustments.Select(bindable => bindable.Value); - - void IAdjustableAudioComponent.AddAdjustment(AdjustableProperty type, IBindable adjustBindable) - { - speedAdjustments.Add(adjustBindable); - track.AddAdjustment(type, adjustBindable); - } - - void IAdjustableAudioComponent.RemoveAdjustment(AdjustableProperty type, IBindable adjustBindable) - { - speedAdjustments.Remove(adjustBindable); - track.RemoveAdjustment(type, adjustBindable); - } - - void IAdjustableAudioComponent.RemoveAllAdjustments(AdjustableProperty type) => audioContainer.RemoveAllAdjustments(type); - - void IAdjustableAudioComponent.BindAdjustments(IAggregateAudioAdjustment component) => audioContainer.BindAdjustments(component); - - void IAdjustableAudioComponent.UnbindAdjustments(IAggregateAudioAdjustment component) => audioContainer.UnbindAdjustments(component); - - BindableNumber IAdjustableAudioComponent.Volume => audioContainer.Volume; - - BindableNumber IAdjustableAudioComponent.Balance => audioContainer.Balance; - - BindableNumber IAdjustableAudioComponent.Frequency => audioContainer.Frequency; - - BindableNumber IAdjustableAudioComponent.Tempo => audioContainer.Tempo; - - public override void ResetSpeedAdjustments() - { - track.RemoveAllAdjustments(AdjustableProperty.Frequency); - track.RemoveAllAdjustments(AdjustableProperty.Tempo); - } - - IBindable IAggregateAudioAdjustment.AggregateVolume => audioContainer.AggregateVolume; - - IBindable IAggregateAudioAdjustment.AggregateBalance => audioContainer.AggregateBalance; - - IBindable IAggregateAudioAdjustment.AggregateFrequency => audioContainer.AggregateFrequency; - - IBindable IAggregateAudioAdjustment.AggregateTempo => audioContainer.AggregateTempo; } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 21a02fbe0b..17cae05862 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -999,11 +999,12 @@ namespace osu.Game.Screens.Play // Our mods are local copies of the global mods so they need to be re-applied to the track. // This is done through the music controller (for now), because resetting speed adjustments on the beatmap track also removes adjustments provided by DrawableTrack. // Todo: In the future, player will receive in a track and will probably not have to worry about this... - if (GameplayClockContainer is IAdjustableAudioComponent adjustableClock) + if (GameplayClockContainer is MasterGameplayClockContainer masterClock) { - GameplayClockContainer.ResetSpeedAdjustments(); + musicController.ResetTrackAdjustments(); + foreach (var mod in GameplayState.Mods.OfType()) - mod.ApplyToTrack(adjustableClock); + mod.ApplyToTrack(masterClock.GameplayAdjustments); } updateGameplayState();