Remove local reset method in GameplayClockContainer

This commit is contained in:
Dean Herbert
2020-08-17 22:36:03 +09:00
parent d9debef156
commit 93a8bc3d5a
6 changed files with 19 additions and 28 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
@ -16,7 +15,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Screens.Play
{
@ -26,7 +24,6 @@ namespace osu.Game.Screens.Play
public class GameplayClockContainer : Container
{
private readonly WorkingBeatmap beatmap;
private readonly IReadOnlyList<Mod> mods;
[NotNull]
private ITrack track;
@ -62,10 +59,9 @@ namespace osu.Game.Screens.Play
private readonly FramedOffsetClock platformOffsetClock;
public GameplayClockContainer(WorkingBeatmap beatmap, IReadOnlyList<Mod> mods, double gameplayStartTime)
public GameplayClockContainer(WorkingBeatmap beatmap, double gameplayStartTime)
{
this.beatmap = beatmap;
this.mods = mods;
this.gameplayStartTime = gameplayStartTime;
track = beatmap.Track;
@ -122,13 +118,10 @@ namespace osu.Game.Screens.Play
public void Restart()
{
// The Reset() call below causes speed adjustments to be reset in an async context, leading to deadlocks.
// The deadlock can be prevented by resetting the track synchronously before entering the async context.
track.ResetSpeedAdjustments();
Task.Run(() =>
{
track.Reset();
track.Seek(0);
track.Stop();
Schedule(() =>
{
@ -216,14 +209,13 @@ namespace osu.Game.Screens.Play
private void updateRate()
{
speedAdjustmentsApplied = true;
track.ResetSpeedAdjustments();
if (speedAdjustmentsApplied)
return;
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
foreach (var mod in mods.OfType<IApplicableToTrack>())
mod.ApplyToTrack(track);
speedAdjustmentsApplied = true;
}
protected override void Dispose(bool isDisposing)
@ -234,11 +226,12 @@ namespace osu.Game.Screens.Play
private void removeSourceClockAdjustments()
{
if (speedAdjustmentsApplied)
{
track.ResetSpeedAdjustments();
speedAdjustmentsApplied = false;
}
if (!speedAdjustmentsApplied) return;
track.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track.RemoveAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
speedAdjustmentsApplied = false;
}
private class HardwareCorrectionOffsetClock : FramedOffsetClock