1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:42:54 +08:00

Move sample pausing logic out of FrameStabilityContainer

This commit is contained in:
Dean Herbert 2020-10-27 13:54:33 +09:00
parent 11ebd2d7f8
commit 6853da459d
5 changed files with 47 additions and 50 deletions

View File

@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("get variables", () =>
{
gameplayClock = Player.ChildrenOfType<FrameStabilityContainer>().First();
gameplayClock = Player as ISamplePlaybackDisabler;
slider = Player.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).First();
samples = slider.ChildrenOfType<DrawableSample>().ToArray();
});

View File

@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.UI
public override Container FrameStableComponents { get; } = new Container { RelativeSizeAxes = Axes.Both };
public override GameplayClock FrameStableClock => frameStabilityContainer.GameplayClock;
public override FrameStableClock FrameStableClock => frameStabilityContainer.FrameStableClock;
private bool frameStablePlayback = true;
@ -404,7 +404,7 @@ namespace osu.Game.Rulesets.UI
/// <summary>
/// The frame-stable clock which is being used for playfield display.
/// </summary>
public abstract GameplayClock FrameStableClock { get; }
public abstract FrameStableClock FrameStableClock { get; }
/// <summary>~
/// The associated ruleset.

View File

@ -2,10 +2,7 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
@ -18,11 +15,8 @@ namespace osu.Game.Rulesets.UI
/// A container which consumes a parent gameplay clock and standardises frame counts for children.
/// Will ensure a minimum of 50 frames per clock second is maintained, regardless of any system lag or seeks.
/// </summary>
[Cached(typeof(ISamplePlaybackDisabler))]
public class FrameStabilityContainer : Container, IHasReplayHandler, ISamplePlaybackDisabler
public class FrameStabilityContainer : Container, IHasReplayHandler
{
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
private readonly double gameplayStartTime;
/// <summary>
@ -35,16 +29,14 @@ namespace osu.Game.Rulesets.UI
/// </summary>
internal bool FrameStablePlayback = true;
public GameplayClock GameplayClock => stabilityGameplayClock;
[Cached(typeof(GameplayClock))]
private readonly StabilityGameplayClock stabilityGameplayClock;
public readonly FrameStableClock FrameStableClock;
public FrameStabilityContainer(double gameplayStartTime = double.MinValue)
{
RelativeSizeAxes = Axes.Both;
stabilityGameplayClock = new StabilityGameplayClock(framedClock = new FramedClock(manualClock = new ManualClock()));
FrameStableClock = new FrameStableClock(framedClock = new FramedClock(manualClock = new ManualClock()));
this.gameplayStartTime = gameplayStartTime;
}
@ -65,12 +57,9 @@ namespace osu.Game.Rulesets.UI
{
if (clock != null)
{
parentGameplayClock = stabilityGameplayClock.ParentGameplayClock = clock;
GameplayClock.IsPaused.BindTo(clock.IsPaused);
parentGameplayClock = FrameStableClock.ParentGameplayClock = clock;
FrameStableClock.IsPaused.BindTo(clock.IsPaused);
}
// this is a bit temporary. should really be done inside of GameplayClock (but requires large structural changes).
stabilityGameplayClock.ParentSampleDisabler = sampleDisabler;
}
protected override void LoadComplete()
@ -102,9 +91,7 @@ namespace osu.Game.Rulesets.UI
public override bool UpdateSubTree()
{
requireMoreUpdateLoops = true;
validState = !GameplayClock.IsPaused.Value;
samplePlaybackDisabled.Value = stabilityGameplayClock.ShouldDisableSamplePlayback;
validState = !FrameStableClock.IsPaused.Value;
int loops = 0;
@ -222,32 +209,10 @@ namespace osu.Game.Rulesets.UI
}
else
{
Clock = GameplayClock;
Clock = FrameStableClock;
}
}
public ReplayInputHandler ReplayInputHandler { get; set; }
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => samplePlaybackDisabled;
private class StabilityGameplayClock : GameplayClock
{
public GameplayClock ParentGameplayClock;
public ISamplePlaybackDisabler ParentSampleDisabler;
public override IEnumerable<Bindable<double>> NonGameplayAdjustments => ParentGameplayClock?.NonGameplayAdjustments ?? Enumerable.Empty<Bindable<double>>();
public StabilityGameplayClock(FramedClock underlyingClock)
: base(underlyingClock)
{
}
public override bool ShouldDisableSamplePlayback =>
// handle the case where playback is catching up to real-time.
base.ShouldDisableSamplePlayback
|| ParentSampleDisabler?.SamplePlaybackDisabled.Value == true
|| (ParentGameplayClock != null && Math.Abs(CurrentTime - ParentGameplayClock.CurrentTime) > 200);
}
}
}

View File

@ -0,0 +1,28 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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.Bindables;
using osu.Framework.Timing;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.UI
{
public class FrameStableClock : GameplayClock
{
public GameplayClock ParentGameplayClock;
public override IEnumerable<Bindable<double>> NonGameplayAdjustments => ParentGameplayClock?.NonGameplayAdjustments ?? Enumerable.Empty<Bindable<double>>();
public FrameStableClock(FramedClock underlyingClock)
: base(underlyingClock)
{
}
public override bool ShouldDisableSamplePlayback =>
// handle the case where playback is catching up to real-time.
base.ShouldDisableSamplePlayback || (ParentGameplayClock != null && Math.Abs(CurrentTime - ParentGameplayClock.CurrentTime) > 200);
}
}

View File

@ -238,11 +238,8 @@ namespace osu.Game.Screens.Play
skipOverlay.Hide();
}
DrawableRuleset.IsPaused.BindValueChanged(paused =>
{
updateGameplayState();
samplePlaybackDisabled.Value = paused.NewValue;
});
DrawableRuleset.IsPaused.BindValueChanged(_ => updateGameplayState());
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateGameplayState());
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
@ -370,6 +367,13 @@ namespace osu.Game.Screens.Play
}
};
protected override void Update()
{
base.Update();
samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.ShouldDisableSamplePlayback;
}
private void onBreakTimeChanged(ValueChangedEvent<bool> isBreakTime)
{
updateGameplayState();