1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00

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

@ -1,10 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
@ -24,7 +22,7 @@ namespace osu.Game.Tests.Gameplay
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack(); working.LoadTrack();
Add(gcc = new GameplayClockContainer(working, Array.Empty<Mod>(), 0)); Add(gcc = new GameplayClockContainer(working, 0));
}); });
AddStep("start track", () => gcc.Start()); AddStep("start track", () => gcc.Start());

View File

@ -62,7 +62,7 @@ namespace osu.Game.Tests.Gameplay
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack(); working.LoadTrack();
Add(gameplayContainer = new GameplayClockContainer(working, Array.Empty<Mod>(), 0)); Add(gameplayContainer = new GameplayClockContainer(working, 0));
gameplayContainer.Add(sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1)) gameplayContainer.Add(sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
{ {
@ -106,7 +106,7 @@ namespace osu.Game.Tests.Gameplay
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, Audio); Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, Audio);
SelectedMods.Value = new[] { testedMod }; SelectedMods.Value = new[] { testedMod };
Add(gameplayContainer = new GameplayClockContainer(Beatmap.Value, SelectedMods.Value, 0)); Add(gameplayContainer = new GameplayClockContainer(Beatmap.Value, 0));
gameplayContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1)) gameplayContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
{ {

View File

@ -1,11 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK; using osuTK;
@ -35,7 +33,7 @@ namespace osu.Game.Tests.Visual.Gameplay
var working = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)); var working = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
working.LoadTrack(); working.LoadTrack();
Child = gameplayClockContainer = new GameplayClockContainer(working, Array.Empty<Mod>(), 0) Child = gameplayClockContainer = new GameplayClockContainer(working, 0)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]

View File

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

View File

@ -179,7 +179,7 @@ namespace osu.Game.Screens.Play
if (!ScoreProcessor.Mode.Disabled) if (!ScoreProcessor.Mode.Disabled)
config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode); config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode);
InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime); InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, DrawableRuleset.GameplayStartTime);
AddInternal(gameplayBeatmap = new GameplayBeatmap(playableBeatmap)); AddInternal(gameplayBeatmap = new GameplayBeatmap(playableBeatmap));
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer)); AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));

View File

@ -29,6 +29,8 @@ namespace osu.Game.Tests.Visual
{ {
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage)); Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0; LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
MusicController.AllowRateAdjustments = true;
} }
[SetUpSteps] [SetUpSteps]