Skip to content

Commit e778832

Browse files
committed
Add flag to allow backwards seeks in tests
1 parent 2d4e7c2 commit e778832

12 files changed

+61
-11
lines changed

osu.Game.Rulesets.Mania.Tests/TestSceneTimingBasedNoteColouring.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,21 @@ public partial class TestSceneTimingBasedNoteColouring : OsuTestScene
3434
[SetUpSteps]
3535
public void SetUpSteps()
3636
{
37-
AddStep("setup hierarchy", () => Child = new Container
37+
AddStep("setup hierarchy", () =>
3838
{
39-
Clock = new FramedClock(clock = new ManualClock()),
40-
RelativeSizeAxes = Axes.Both,
41-
Anchor = Anchor.Centre,
42-
Origin = Anchor.Centre,
43-
Children = new[]
39+
Child = new Container
4440
{
45-
drawableRuleset = (DrawableManiaRuleset)Ruleset.Value.CreateInstance().CreateDrawableRulesetWith(createTestBeatmap())
46-
}
41+
Clock = new FramedClock(clock = new ManualClock()),
42+
RelativeSizeAxes = Axes.Both,
43+
Anchor = Anchor.Centre,
44+
Origin = Anchor.Centre,
45+
Children = new[]
46+
{
47+
drawableRuleset = (DrawableManiaRuleset)Ruleset.Value.CreateInstance().CreateDrawableRulesetWith(createTestBeatmap())
48+
}
49+
};
50+
51+
drawableRuleset.AllowBackwardsSeeks = true;
4752
});
4853
AddStep("retrieve config bindable", () =>
4954
{

osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public override event Action<JudgementResult> RevertResult
100100
public override Container FrameStableComponents { get; }
101101
public override IFrameStableClock FrameStableClock { get; }
102102
internal override bool FrameStablePlayback { get; set; }
103+
public override bool AllowBackwardsSeeks { get; set; }
103104
public override IReadOnlyList<Mod> Mods { get; }
104105

105106
public override double GameplayStartTime { get; }

osu.Game.Tests/Visual/Gameplay/TestSceneCompletionCancellation.cs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public partial class TestSceneCompletionCancellation : OsuPlayerTestScene
2929

3030
protected override bool AllowFail => false;
3131

32+
protected override bool AllowBackwardsSeeks => true;
33+
3234
[SetUpSteps]
3335
public override void SetUpSteps()
3436
{

osu.Game.Tests/Visual/Gameplay/TestSceneFrameStabilityContainer.cs

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ public void TestRatePreservedWhenTimeNotProgressing()
131131

132132
private void createStabilityContainer(double gameplayStartTime = double.MinValue) => AddStep("create container", () =>
133133
mainContainer.Child = new FrameStabilityContainer(gameplayStartTime)
134+
{
135+
AllowBackwardsSeeks = true,
136+
}
134137
.WithChild(consumer = new ClockConsumingChild()));
135138

136139
private void seekManualTo(double time) => AddStep($"seek manual clock to {time}", () => manualClock.CurrentTime = time);

osu.Game.Tests/Visual/Gameplay/TestSceneGameplaySamplePlayback.cs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace osu.Game.Tests.Visual.Gameplay
1616
{
1717
public partial class TestSceneGameplaySamplePlayback : PlayerTestScene
1818
{
19+
protected override bool AllowBackwardsSeeks => true;
20+
1921
[Test]
2022
public void TestAllSamplesStopDuringSeek()
2123
{

osu.Game.Tests/Visual/Gameplay/TestSceneGameplaySampleTriggerSource.cs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace osu.Game.Tests.Visual.Gameplay
2828
{
2929
public partial class TestSceneGameplaySampleTriggerSource : PlayerTestScene
3030
{
31+
protected override bool AllowBackwardsSeeks => true;
32+
3133
private TestGameplaySampleTriggerSource sampleTriggerSource = null!;
3234
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
3335

osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public override event Action<JudgementResult> RevertResult
288288
public override Container FrameStableComponents { get; }
289289
public override IFrameStableClock FrameStableClock { get; }
290290
internal override bool FrameStablePlayback { get; set; }
291+
public override bool AllowBackwardsSeeks { get; set; }
291292
public override IReadOnlyList<Mod> Mods { get; }
292293

293294
public override double GameplayStartTime { get; }

osu.Game.Tests/Visual/Gameplay/TestScenePoolingRuleset.cs

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ private void createTest(IBeatmap beatmap, int poolSize, Func<IFrameBasedClock> c
269269

270270
drawableRuleset = (TestDrawablePoolingRuleset)ruleset.CreateDrawableRulesetWith(CreateWorkingBeatmap(beatmap).GetPlayableBeatmap(ruleset.RulesetInfo));
271271
drawableRuleset.FrameStablePlayback = true;
272+
drawableRuleset.AllowBackwardsSeeks = true;
272273
drawableRuleset.PoolSize = poolSize;
273274

274275
Child = new Container

osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardWithOutro.cs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public partial class TestSceneStoryboardWithOutro : PlayerTestScene
3131
{
3232
protected override bool HasCustomSteps => true;
3333

34+
protected override bool AllowBackwardsSeeks => true;
35+
3436
protected new OutroPlayer Player => (OutroPlayer)base.Player;
3537

3638
private double currentBeatmapDuration;

osu.Game/Rulesets/UI/DrawableRuleset.cs

+20
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ public abstract partial class DrawableRuleset<TObject> : DrawableRuleset, IProvi
8181

8282
public override IFrameStableClock FrameStableClock => frameStabilityContainer;
8383

84+
private bool allowBackwardsSeeks;
85+
86+
public override bool AllowBackwardsSeeks
87+
{
88+
get => allowBackwardsSeeks;
89+
set
90+
{
91+
allowBackwardsSeeks = value;
92+
if (frameStabilityContainer != null)
93+
frameStabilityContainer.AllowBackwardsSeeks = value;
94+
}
95+
}
96+
8497
private bool frameStablePlayback = true;
8598

8699
internal override bool FrameStablePlayback
@@ -178,6 +191,7 @@ private void load(CancellationToken? cancellationToken)
178191
InternalChild = frameStabilityContainer = new FrameStabilityContainer(GameplayStartTime)
179192
{
180193
FrameStablePlayback = FrameStablePlayback,
194+
AllowBackwardsSeeks = AllowBackwardsSeeks,
181195
Children = new Drawable[]
182196
{
183197
FrameStableComponents,
@@ -463,6 +477,12 @@ public abstract partial class DrawableRuleset : CompositeDrawable
463477
/// </summary>
464478
internal abstract bool FrameStablePlayback { get; set; }
465479

480+
/// <summary>
481+
/// When a replay is not attached, we usually block any backwards seeks.
482+
/// This will bypass the check. Should only be used for tests.
483+
/// </summary>
484+
public abstract bool AllowBackwardsSeeks { get; set; }
485+
466486
/// <summary>
467487
/// The mods which are to be applied.
468488
/// </summary>

osu.Game/Rulesets/UI/FrameStabilityContainer.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using osu.Framework.Allocation;
77
using osu.Framework.Audio;
88
using osu.Framework.Bindables;
9-
using osu.Framework.Development;
109
using osu.Framework.Graphics;
1110
using osu.Framework.Graphics.Containers;
1211
using osu.Framework.Logging;
@@ -26,6 +25,8 @@ public sealed partial class FrameStabilityContainer : Container, IHasReplayHandl
2625
{
2726
public ReplayInputHandler? ReplayInputHandler { get; set; }
2827

28+
public bool AllowBackwardsSeeks { get; set; }
29+
2930
/// <summary>
3031
/// The number of CPU milliseconds to spend at most during seek catch-up.
3132
/// </summary>
@@ -157,7 +158,7 @@ private void updateClock()
157158
//
158159
// It basically says that "while we're running in frame stable mode, and don't have a replay attached,
159160
// time should never go backwards". If it does, we stop running gameplay until it returns to normal.
160-
if (!hasReplayAttached && FrameStablePlayback && proposedTime > referenceClock.CurrentTime && !DebugUtils.IsNUnitRunning)
161+
if (!hasReplayAttached && FrameStablePlayback && proposedTime > referenceClock.CurrentTime && !AllowBackwardsSeeks)
161162
{
162163
Logger.Log($"Denying backwards seek during gameplay (reference: {referenceClock.CurrentTime:N2} stable: {proposedTime:N2})");
163164
state = PlaybackState.NotValid;

osu.Game/Tests/Visual/PlayerTestScene.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,20 @@ protected void CreateTest([CanBeNull] Action action = null)
7070

7171
AddStep($"Load player for {CreatePlayerRuleset().Description}", LoadPlayer);
7272
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
73+
74+
if (AllowBackwardsSeeks)
75+
{
76+
AddStep("allow backwards seeking", () =>
77+
{
78+
Player.DrawableRuleset.AllowBackwardsSeeks = AllowBackwardsSeeks;
79+
});
80+
}
7381
}
7482

7583
protected virtual bool AllowFail => false;
7684

85+
protected virtual bool AllowBackwardsSeeks => false;
86+
7787
protected virtual bool Autoplay => false;
7888

7989
protected void LoadPlayer() => LoadPlayer(Array.Empty<Mod>());
@@ -126,6 +136,6 @@ protected override void Dispose(bool isDisposing)
126136

127137
protected sealed override Ruleset CreateRuleset() => CreatePlayerRuleset();
128138

129-
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
139+
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false, AllowBackwardsSeeks);
130140
}
131141
}

0 commit comments

Comments
 (0)