From a1aecd4c3905bbd9cd9d9e1925d257ff40e6419a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 3 Mar 2020 12:59:41 +0900 Subject: [PATCH 1/7] Fix TrackVirtualManual not respecting rate adjustments --- osu.Game/Tests/Visual/OsuTestScene.cs | 57 ++++++--------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index b203557fab..3faecc87d2 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -229,17 +229,10 @@ namespace osu.Game.Tests.Visual /// public class TrackVirtualManual : Track { + private readonly StopwatchClock stopwatchClock = new StopwatchClock(); + private readonly IFrameBasedClock referenceClock; - private readonly ManualClock clock = new ManualClock(); - - private bool running; - - /// - /// Local offset added to the reference clock to resolve correct time. - /// - private double offset; - public TrackVirtualManual(IFrameBasedClock referenceClock) { this.referenceClock = referenceClock; @@ -248,60 +241,32 @@ namespace osu.Game.Tests.Visual public override bool Seek(double seek) { - offset = Math.Clamp(seek, 0, Length); - lastReferenceTime = null; + var offset = Math.Clamp(seek, 0, Length); + + stopwatchClock.Seek(offset); return offset == seek; } - public override void Start() - { - running = true; - } + public override void Start() => stopwatchClock.Start(); public override void Reset() { - Seek(0); + stopwatchClock.Seek(0); base.Reset(); } - public override void Stop() - { - if (running) - { - running = false; - // on stopping, the current value should be transferred out of the clock, as we can no longer rely on - // the referenceClock (which will still be counting time). - offset = clock.CurrentTime; - lastReferenceTime = null; - } - } + public override void Stop() => stopwatchClock.Stop(); - public override bool IsRunning => running; + public override bool IsRunning => stopwatchClock.IsRunning; - private double? lastReferenceTime; - - public override double CurrentTime => clock.CurrentTime; + public override double CurrentTime => stopwatchClock.CurrentTime; protected override void UpdateState() { base.UpdateState(); - if (running) - { - double refTime = referenceClock.CurrentTime; - - if (!lastReferenceTime.HasValue) - { - // if the clock just started running, the current value should be transferred to the offset - // (to zero the progression of time). - offset -= refTime; - } - - lastReferenceTime = refTime; - } - - clock.CurrentTime = Math.Min((lastReferenceTime ?? 0) + offset, Length); + stopwatchClock.Rate = Rate * referenceClock.Rate; if (CurrentTime >= Length) { From cc5b44e46681eb6b46c6c0fc1109cd5b64dd108b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 3 Mar 2020 13:36:55 +0900 Subject: [PATCH 2/7] Add test scene --- .../Mods/TestSceneOsuModDoubleTime.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs new file mode 100644 index 0000000000..deb733c581 --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs @@ -0,0 +1,41 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Game.Rulesets.Osu.Mods; +using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring; +using osu.Game.Tests.Visual; + +namespace osu.Game.Rulesets.Osu.Tests.Mods +{ + public class TestSceneOsuModDoubleTime : ModSandboxTestScene + { + public TestSceneOsuModDoubleTime() + : base(new OsuRuleset()) + { + } + + [TestCase(0.5)] + [TestCase(1.01)] + [TestCase(1.5)] + [TestCase(2)] + [TestCase(5)] + public void TestDefaultRate(double rate) => CreateModTest(new ModTestCaseData("1.5x", new OsuModDoubleTime { SpeedChange = { Value = rate } }) + { + PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2 + }); + + protected override TestPlayer CreateReplayPlayer(Score score) => new ScoreAccessibleTestPlayer(score); + + private class ScoreAccessibleTestPlayer : TestPlayer + { + public new ScoreProcessor ScoreProcessor => base.ScoreProcessor; + + public ScoreAccessibleTestPlayer(Score score) + : base(score) + { + } + } + } +} From 583e2c3f4a616fea8d2b9abc7065135e917217d3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 Mar 2020 00:10:05 +0900 Subject: [PATCH 3/7] Actually check rate is applied --- .../Mods/TestSceneOsuModDoubleTime.cs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs index deb733c581..dcf19ad993 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModDoubleTime.cs @@ -2,14 +2,13 @@ // See the LICENCE file in the repository root for full licence text. using NUnit.Framework; +using osu.Framework.Utils; using osu.Game.Rulesets.Osu.Mods; -using osu.Game.Rulesets.Scoring; -using osu.Game.Scoring; using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Osu.Tests.Mods { - public class TestSceneOsuModDoubleTime : ModSandboxTestScene + public class TestSceneOsuModDoubleTime : ModTestScene { public TestSceneOsuModDoubleTime() : base(new OsuRuleset()) @@ -21,21 +20,16 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods [TestCase(1.5)] [TestCase(2)] [TestCase(5)] - public void TestDefaultRate(double rate) => CreateModTest(new ModTestCaseData("1.5x", new OsuModDoubleTime { SpeedChange = { Value = rate } }) + public void TestSpeedChangeCustomisation(double rate) { - PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2 - }); + var mod = new OsuModDoubleTime { SpeedChange = { Value = rate } }; - protected override TestPlayer CreateReplayPlayer(Score score) => new ScoreAccessibleTestPlayer(score); - - private class ScoreAccessibleTestPlayer : TestPlayer - { - public new ScoreProcessor ScoreProcessor => base.ScoreProcessor; - - public ScoreAccessibleTestPlayer(Score score) - : base(score) + CreateModTest(new ModTestData { - } + Mod = mod, + PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2 && + Precision.AlmostEquals(Player.GameplayClockContainer.GameplayClock.Rate, mod.SpeedChange.Value) + }); } } } From e3509c742c4ec1bb9df56d4a3c1f733ad4587f58 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 Mar 2020 01:28:59 +0900 Subject: [PATCH 4/7] Track time in a simpler way in TrackVirtualManual --- osu.Game/Tests/Visual/OsuTestScene.cs | 47 ++++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 917d12ebb1..3c95b990e1 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -229,10 +229,10 @@ namespace osu.Game.Tests.Visual /// public class TrackVirtualManual : Track { - private readonly StopwatchClock stopwatchClock = new StopwatchClock(); - private readonly IFrameBasedClock referenceClock; + private bool running; + public TrackVirtualManual(IFrameBasedClock referenceClock) { this.referenceClock = referenceClock; @@ -241,32 +241,55 @@ namespace osu.Game.Tests.Visual public override bool Seek(double seek) { - var offset = Math.Clamp(seek, 0, Length); + accumulated = Math.Min(seek, Length); + lastReferenceTime = null; - stopwatchClock.Seek(offset); - - return offset == seek; + return accumulated == seek; } - public override void Start() => stopwatchClock.Start(); + public override void Start() + { + running = true; + } public override void Reset() { - stopwatchClock.Seek(0); + Seek(0); base.Reset(); } - public override void Stop() => stopwatchClock.Stop(); + public override void Stop() + { + if (running) + { + running = false; + lastReferenceTime = null; + } + } - public override bool IsRunning => stopwatchClock.IsRunning; + public override bool IsRunning => running; - public override double CurrentTime => stopwatchClock.CurrentTime; + private double? lastReferenceTime; + + private double accumulated; + + public override double CurrentTime => Math.Min(accumulated, Length); protected override void UpdateState() { base.UpdateState(); - stopwatchClock.Rate = Rate * referenceClock.Rate; + if (running) + { + double refTime = referenceClock.CurrentTime; + + if (lastReferenceTime.HasValue) + accumulated += (refTime - lastReferenceTime.Value) * Rate; + + lastReferenceTime = refTime; + } + + Console.WriteLine($"t={CurrentTime}"); if (CurrentTime >= Length) { From ebc86c10754ede8686e06b06682c272ff117b562 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 Mar 2020 02:08:49 +0900 Subject: [PATCH 5/7] Fix random test failure --- osu.Game/Screens/Play/SkipOverlay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/SkipOverlay.cs b/osu.Game/Screens/Play/SkipOverlay.cs index 3daf5b1ff1..ac7e509c2c 100644 --- a/osu.Game/Screens/Play/SkipOverlay.cs +++ b/osu.Game/Screens/Play/SkipOverlay.cs @@ -116,7 +116,7 @@ namespace osu.Game.Screens.Play { base.Update(); - var progress = Math.Max(0, 1 - (gameplayClock.CurrentTime - displayTime) / (fadeOutBeginTime - displayTime)); + var progress = fadeOutBeginTime <= displayTime ? 1 : Math.Max(0, 1 - (gameplayClock.CurrentTime - displayTime) / (fadeOutBeginTime - displayTime)); remainingTimeBox.Width = (float)Interpolation.Lerp(remainingTimeBox.Width, progress, Math.Clamp(Time.Elapsed / 40, 0, 1)); From c3ad08f230b635f4dcc8582c5ee2028f04cd25c8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 Mar 2020 02:18:35 +0900 Subject: [PATCH 6/7] Remove wild writeline --- osu.Game/Tests/Visual/OsuTestScene.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 3c95b990e1..5623435da4 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -289,8 +289,6 @@ namespace osu.Game.Tests.Visual lastReferenceTime = refTime; } - Console.WriteLine($"t={CurrentTime}"); - if (CurrentTime >= Length) { Stop(); From 3295f8657ac3d74a95c10016273068fbbdedde26 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 Mar 2020 22:44:11 +0900 Subject: [PATCH 7/7] Restore clamp behaviour --- osu.Game/Tests/Visual/OsuTestScene.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 5623435da4..d1d8059cb1 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -241,7 +241,7 @@ namespace osu.Game.Tests.Visual public override bool Seek(double seek) { - accumulated = Math.Min(seek, Length); + accumulated = Math.Clamp(seek, 0, Length); lastReferenceTime = null; return accumulated == seek;