1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Merge branch 'master' into right-click-circle-delete

This commit is contained in:
Bartłomiej Dach 2020-10-28 22:12:14 +01:00
commit a1696942f0
11 changed files with 111 additions and 97 deletions

View File

@ -11,7 +11,6 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Osu.Mods
{
@ -31,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private OsuInputManager inputManager;
private GameplayClock gameplayClock;
private IFrameStableClock gameplayClock;
private List<OsuReplayFrame> replayFrames;

View File

@ -9,7 +9,6 @@ using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
@ -22,11 +21,11 @@ namespace osu.Game.Tests.Visual.Gameplay
{
DrawableSlider slider = null;
DrawableSample[] samples = null;
ISamplePlaybackDisabler gameplayClock = null;
ISamplePlaybackDisabler sampleDisabler = null;
AddStep("get variables", () =>
{
gameplayClock = Player.ChildrenOfType<FrameStabilityContainer>().First();
sampleDisabler = Player;
slider = Player.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).First();
samples = slider.ChildrenOfType<DrawableSample>().ToArray();
});
@ -43,16 +42,16 @@ namespace osu.Game.Tests.Visual.Gameplay
return true;
});
AddAssert("sample playback disabled", () => gameplayClock.SamplePlaybackDisabled.Value);
AddAssert("sample playback disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
// because we are in frame stable context, it's quite likely that not all samples are "played" at this point.
// the important thing is that at least one started, and that sample has since stopped.
AddAssert("all looping samples stopped immediately", () => allStopped(allLoopingSounds));
AddUntilStep("all samples stopped eventually", () => allStopped(allSounds));
AddAssert("sample playback still disabled", () => gameplayClock.SamplePlaybackDisabled.Value);
AddAssert("sample playback still disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
AddUntilStep("seek finished, sample playback enabled", () => !gameplayClock.SamplePlaybackDisabled.Value);
AddUntilStep("seek finished, sample playback enabled", () => !sampleDisabler.SamplePlaybackDisabled.Value);
AddUntilStep("any sample is playing", () => Player.ChildrenOfType<PausableSkinnableSound>().Any(s => s.IsPlaying));
}

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 IFrameStableClock 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 IFrameStableClock FrameStableClock { get; }
/// <summary>~
/// The associated ruleset.

View File

@ -18,11 +18,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 +32,16 @@ namespace osu.Game.Rulesets.UI
/// </summary>
internal bool FrameStablePlayback = true;
public GameplayClock GameplayClock => stabilityGameplayClock;
public IFrameStableClock FrameStableClock => frameStableClock;
[Cached(typeof(GameplayClock))]
private readonly StabilityGameplayClock stabilityGameplayClock;
private readonly FrameStabilityClock frameStableClock;
public FrameStabilityContainer(double gameplayStartTime = double.MinValue)
{
RelativeSizeAxes = Axes.Both;
stabilityGameplayClock = new StabilityGameplayClock(framedClock = new FramedClock(manualClock = new ManualClock()));
frameStableClock = new FrameStabilityClock(framedClock = new FramedClock(manualClock = new ManualClock()));
this.gameplayStartTime = gameplayStartTime;
}
@ -65,12 +62,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 +96,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;
@ -205,7 +197,11 @@ namespace osu.Game.Rulesets.UI
manualClock.Rate = Math.Abs(parentGameplayClock.Rate) * direction;
manualClock.IsRunning = parentGameplayClock.IsRunning;
requireMoreUpdateLoops |= manualClock.CurrentTime != parentGameplayClock.CurrentTime;
double timeBehind = Math.Abs(manualClock.CurrentTime - parentGameplayClock.CurrentTime);
requireMoreUpdateLoops |= timeBehind != 0;
frameStableClock.IsCatchingUp.Value = timeBehind > 200;
// The manual clock time has changed in the above code. The framed clock now needs to be updated
// to ensure that the its time is valid for our children before input is processed
@ -222,32 +218,26 @@ namespace osu.Game.Rulesets.UI
}
else
{
Clock = GameplayClock;
Clock = frameStableClock;
}
}
public ReplayInputHandler ReplayInputHandler { get; set; }
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => samplePlaybackDisabled;
private class StabilityGameplayClock : GameplayClock
private class FrameStabilityClock : GameplayClock, IFrameStableClock
{
public GameplayClock ParentGameplayClock;
public ISamplePlaybackDisabler ParentSampleDisabler;
public readonly Bindable<bool> IsCatchingUp = new Bindable<bool>();
public override IEnumerable<Bindable<double>> NonGameplayAdjustments => ParentGameplayClock?.NonGameplayAdjustments ?? Enumerable.Empty<Bindable<double>>();
public StabilityGameplayClock(FramedClock underlyingClock)
public FrameStabilityClock(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);
IBindable<bool> IFrameStableClock.IsCatchingUp => IsCatchingUp;
}
}
}

View File

@ -0,0 +1,13 @@
// 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 osu.Framework.Bindables;
using osu.Framework.Timing;
namespace osu.Game.Rulesets.UI
{
public interface IFrameStableClock : IFrameBasedClock
{
IBindable<bool> IsCatchingUp { get; }
}
}

View File

@ -43,8 +43,9 @@ using osuTK.Input;
namespace osu.Game.Screens.Edit
{
[Cached(typeof(IBeatSnapProvider))]
[Cached(typeof(ISamplePlaybackDisabler))]
[Cached]
public class Editor : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>, IKeyBindingHandler<PlatformAction>, IBeatSnapProvider
public class Editor : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>, IKeyBindingHandler<PlatformAction>, IBeatSnapProvider, ISamplePlaybackDisabler
{
public override float BackgroundParallaxAmount => 0.1f;
@ -64,6 +65,10 @@ namespace osu.Game.Screens.Edit
[Resolved(canBeNull: true)]
private DialogOverlay dialogOverlay { get; set; }
public IBindable<bool> SamplePlaybackDisabled => samplePlaybackDisabled;
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
private bool exitConfirmed;
private string lastSavedHash;
@ -109,9 +114,10 @@ namespace osu.Game.Screens.Edit
UpdateClockSource();
dependencies.CacheAs(clock);
dependencies.CacheAs<ISamplePlaybackDisabler>(clock);
AddInternal(clock);
clock.SeekingOrStopped.BindValueChanged(_ => updateSampleDisabledState());
// todo: remove caching of this and consume via editorBeatmap?
dependencies.Cache(beatDivisor);
@ -557,40 +563,52 @@ namespace osu.Game.Screens.Edit
.ScaleTo(0.98f, 200, Easing.OutQuint)
.FadeOut(200, Easing.OutQuint);
if ((currentScreen = screenContainer.SingleOrDefault(s => s.Type == e.NewValue)) != null)
try
{
screenContainer.ChangeChildDepth(currentScreen, lastScreen?.Depth + 1 ?? 0);
if ((currentScreen = screenContainer.SingleOrDefault(s => s.Type == e.NewValue)) != null)
{
screenContainer.ChangeChildDepth(currentScreen, lastScreen?.Depth + 1 ?? 0);
currentScreen
.ScaleTo(1, 200, Easing.OutQuint)
.FadeIn(200, Easing.OutQuint);
return;
currentScreen
.ScaleTo(1, 200, Easing.OutQuint)
.FadeIn(200, Easing.OutQuint);
return;
}
switch (e.NewValue)
{
case EditorScreenMode.SongSetup:
currentScreen = new SetupScreen();
break;
case EditorScreenMode.Compose:
currentScreen = new ComposeScreen();
break;
case EditorScreenMode.Design:
currentScreen = new DesignScreen();
break;
case EditorScreenMode.Timing:
currentScreen = new TimingScreen();
break;
}
LoadComponentAsync(currentScreen, newScreen =>
{
if (newScreen == currentScreen)
screenContainer.Add(newScreen);
});
}
switch (e.NewValue)
finally
{
case EditorScreenMode.SongSetup:
currentScreen = new SetupScreen();
break;
case EditorScreenMode.Compose:
currentScreen = new ComposeScreen();
break;
case EditorScreenMode.Design:
currentScreen = new DesignScreen();
break;
case EditorScreenMode.Timing:
currentScreen = new TimingScreen();
break;
updateSampleDisabledState();
}
}
LoadComponentAsync(currentScreen, newScreen =>
{
if (newScreen == currentScreen)
screenContainer.Add(newScreen);
});
private void updateSampleDisabledState()
{
samplePlaybackDisabled.Value = clock.SeekingOrStopped.Value || !(currentScreen is ComposeScreen);
}
private void seek(UIEvent e, int direction)

View File

@ -11,14 +11,13 @@ using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Screens.Play;
namespace osu.Game.Screens.Edit
{
/// <summary>
/// A decoupled clock which adds editor-specific functionality, such as snapping to a user-defined beat divisor.
/// </summary>
public class EditorClock : Component, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock, ISamplePlaybackDisabler
public class EditorClock : Component, IFrameBasedClock, IAdjustableClock, ISourceChangeableClock
{
public IBindable<Track> Track => track;
@ -32,9 +31,9 @@ namespace osu.Game.Screens.Edit
private readonly DecoupleableInterpolatingFramedClock underlyingClock;
public IBindable<bool> SamplePlaybackDisabled => samplePlaybackDisabled;
public IBindable<bool> SeekingOrStopped => seekingOrStopped;
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
private readonly Bindable<bool> seekingOrStopped = new Bindable<bool>(true);
public EditorClock(WorkingBeatmap beatmap, BindableBeatDivisor beatDivisor)
: this(beatmap.Beatmap.ControlPointInfo, beatmap.Track.Length, beatDivisor)
@ -171,13 +170,13 @@ namespace osu.Game.Screens.Edit
public void Stop()
{
samplePlaybackDisabled.Value = true;
seekingOrStopped.Value = true;
underlyingClock.Stop();
}
public bool Seek(double position)
{
samplePlaybackDisabled.Value = true;
seekingOrStopped.Value = true;
ClearTransforms();
return underlyingClock.Seek(position);
@ -228,7 +227,7 @@ namespace osu.Game.Screens.Edit
private void updateSeekingState()
{
if (samplePlaybackDisabled.Value)
if (seekingOrStopped.Value)
{
if (track.Value?.IsRunning != true)
{
@ -240,13 +239,13 @@ namespace osu.Game.Screens.Edit
// we are either running a seek tween or doing an immediate seek.
// in the case of an immediate seek the seeking bool will be set to false after one update.
// this allows for silencing hit sounds and the likes.
samplePlaybackDisabled.Value = Transforms.Any();
seekingOrStopped.Value = Transforms.Any();
}
}
public void SeekTo(double seekDestination)
{
samplePlaybackDisabled.Value = true;
seekingOrStopped.Value = true;
if (IsRunning)
Seek(seekDestination);

View File

@ -177,6 +177,9 @@ namespace osu.Game.Screens.Edit.Timing
private readonly Box hoveredBackground;
[Resolved]
private EditorClock clock { get; set; }
[Resolved]
private Bindable<ControlPointGroup> selectedGroup { get; set; }
@ -200,7 +203,11 @@ namespace osu.Game.Screens.Edit.Timing
},
};
Action = () => selectedGroup.Value = controlGroup;
Action = () =>
{
selectedGroup.Value = controlGroup;
clock.SeekTo(controlGroup.Time);
};
}
private Color4 colourHover;

View File

@ -22,9 +22,6 @@ namespace osu.Game.Screens.Edit.Timing
[Cached]
private Bindable<ControlPointGroup> selectedGroup = new Bindable<ControlPointGroup>();
[Resolved]
private EditorClock clock { get; set; }
public TimingScreen()
: base(EditorScreenMode.Timing)
{
@ -48,17 +45,6 @@ namespace osu.Game.Screens.Edit.Timing
}
};
protected override void LoadComplete()
{
base.LoadComplete();
selectedGroup.BindValueChanged(selected =>
{
if (selected.NewValue != null)
clock.SeekTo(selected.NewValue.Time);
});
}
protected override void OnTimelineLoaded(TimelineArea timelineArea)
{
base.OnTimelineLoaded(timelineArea);

View File

@ -61,11 +61,6 @@ namespace osu.Game.Screens.Play
public bool IsRunning => underlyingClock.IsRunning;
/// <summary>
/// Whether nested samples supporting the <see cref="ISamplePlaybackDisabler"/> interface should be paused.
/// </summary>
public virtual bool ShouldDisableSamplePlayback => IsPaused.Value;
public void ProcessFrame()
{
// intentionally not updating the underlying clock (handled externally).

View File

@ -241,8 +241,11 @@ namespace osu.Game.Screens.Play
DrawableRuleset.IsPaused.BindValueChanged(paused =>
{
updateGameplayState();
samplePlaybackDisabled.Value = paused.NewValue;
updateSampleDisabledState();
});
DrawableRuleset.FrameStableClock.IsCatchingUp.BindValueChanged(_ => updateSampleDisabledState());
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateGameplayState());
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
@ -384,6 +387,11 @@ namespace osu.Game.Screens.Play
LocalUserPlaying.Value = inGameplay;
}
private void updateSampleDisabledState()
{
samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.IsCatchingUp.Value || GameplayClockContainer.GameplayClock.IsPaused.Value;
}
private void updatePauseOnFocusLostState() =>
HUDOverlay.HoldToQuit.PauseOnFocusLost = PauseOnFocusLost
&& !DrawableRuleset.HasReplayLoaded.Value