Add flag to allow backwards seeks in tests

This commit is contained in:
Dean Herbert 2024-02-29 20:34:38 +08:00
parent 3a780e2b67
commit 4184a5c1ef
No known key found for this signature in database
12 changed files with 61 additions and 11 deletions

View File

@ -34,7 +34,9 @@ public partial class TestSceneTimingBasedNoteColouring : OsuTestScene
[SetUpSteps]
public void SetUpSteps()
{
AddStep("setup hierarchy", () => Child = new Container
AddStep("setup hierarchy", () =>
{
Child = new Container
{
Clock = new FramedClock(clock = new ManualClock()),
RelativeSizeAxes = Axes.Both,
@ -44,6 +46,9 @@ public void SetUpSteps()
{
drawableRuleset = (DrawableManiaRuleset)Ruleset.Value.CreateInstance().CreateDrawableRulesetWith(createTestBeatmap())
}
};
drawableRuleset.AllowBackwardsSeeks = true;
});
AddStep("retrieve config bindable", () =>
{

View File

@ -100,6 +100,7 @@ public override event Action<JudgementResult> RevertResult
public override Container FrameStableComponents { get; }
public override IFrameStableClock FrameStableClock { get; }
internal override bool FrameStablePlayback { get; set; }
public override bool AllowBackwardsSeeks { get; set; }
public override IReadOnlyList<Mod> Mods { get; }
public override double GameplayStartTime { get; }

View File

@ -29,6 +29,8 @@ public partial class TestSceneCompletionCancellation : OsuPlayerTestScene
protected override bool AllowFail => false;
protected override bool AllowBackwardsSeeks => true;
[SetUpSteps]
public override void SetUpSteps()
{

View File

@ -131,6 +131,9 @@ public void TestRatePreservedWhenTimeNotProgressing()
private void createStabilityContainer(double gameplayStartTime = double.MinValue) => AddStep("create container", () =>
mainContainer.Child = new FrameStabilityContainer(gameplayStartTime)
{
AllowBackwardsSeeks = true,
}
.WithChild(consumer = new ClockConsumingChild()));
private void seekManualTo(double time) => AddStep($"seek manual clock to {time}", () => manualClock.CurrentTime = time);

View File

@ -16,6 +16,8 @@ namespace osu.Game.Tests.Visual.Gameplay
{
public partial class TestSceneGameplaySamplePlayback : PlayerTestScene
{
protected override bool AllowBackwardsSeeks => true;
[Test]
public void TestAllSamplesStopDuringSeek()
{

View File

@ -28,6 +28,8 @@ namespace osu.Game.Tests.Visual.Gameplay
{
public partial class TestSceneGameplaySampleTriggerSource : PlayerTestScene
{
protected override bool AllowBackwardsSeeks => true;
private TestGameplaySampleTriggerSource sampleTriggerSource = null!;
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();

View File

@ -288,6 +288,7 @@ public override event Action<JudgementResult> RevertResult
public override Container FrameStableComponents { get; }
public override IFrameStableClock FrameStableClock { get; }
internal override bool FrameStablePlayback { get; set; }
public override bool AllowBackwardsSeeks { get; set; }
public override IReadOnlyList<Mod> Mods { get; }
public override double GameplayStartTime { get; }

View File

@ -269,6 +269,7 @@ private void createTest(IBeatmap beatmap, int poolSize, Func<IFrameBasedClock> c
drawableRuleset = (TestDrawablePoolingRuleset)ruleset.CreateDrawableRulesetWith(CreateWorkingBeatmap(beatmap).GetPlayableBeatmap(ruleset.RulesetInfo));
drawableRuleset.FrameStablePlayback = true;
drawableRuleset.AllowBackwardsSeeks = true;
drawableRuleset.PoolSize = poolSize;
Child = new Container

View File

@ -31,6 +31,8 @@ public partial class TestSceneStoryboardWithOutro : PlayerTestScene
{
protected override bool HasCustomSteps => true;
protected override bool AllowBackwardsSeeks => true;
protected new OutroPlayer Player => (OutroPlayer)base.Player;
private double currentBeatmapDuration;

View File

@ -81,6 +81,19 @@ public abstract partial class DrawableRuleset<TObject> : DrawableRuleset, IProvi
public override IFrameStableClock FrameStableClock => frameStabilityContainer;
private bool allowBackwardsSeeks;
public override bool AllowBackwardsSeeks
{
get => allowBackwardsSeeks;
set
{
allowBackwardsSeeks = value;
if (frameStabilityContainer != null)
frameStabilityContainer.AllowBackwardsSeeks = value;
}
}
private bool frameStablePlayback = true;
internal override bool FrameStablePlayback
@ -178,6 +191,7 @@ private void load(CancellationToken? cancellationToken)
InternalChild = frameStabilityContainer = new FrameStabilityContainer(GameplayStartTime)
{
FrameStablePlayback = FrameStablePlayback,
AllowBackwardsSeeks = AllowBackwardsSeeks,
Children = new Drawable[]
{
FrameStableComponents,
@ -463,6 +477,12 @@ public abstract partial class DrawableRuleset : CompositeDrawable
/// </summary>
internal abstract bool FrameStablePlayback { get; set; }
/// <summary>
/// When a replay is not attached, we usually block any backwards seeks.
/// This will bypass the check. Should only be used for tests.
/// </summary>
public abstract bool AllowBackwardsSeeks { get; set; }
/// <summary>
/// The mods which are to be applied.
/// </summary>

View File

@ -6,7 +6,6 @@
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Development;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
@ -26,6 +25,8 @@ public sealed partial class FrameStabilityContainer : Container, IHasReplayHandl
{
public ReplayInputHandler? ReplayInputHandler { get; set; }
public bool AllowBackwardsSeeks { get; set; }
/// <summary>
/// The number of CPU milliseconds to spend at most during seek catch-up.
/// </summary>
@ -157,7 +158,7 @@ private void updateClock()
//
// It basically says that "while we're running in frame stable mode, and don't have a replay attached,
// time should never go backwards". If it does, we stop running gameplay until it returns to normal.
if (!hasReplayAttached && FrameStablePlayback && proposedTime > referenceClock.CurrentTime && !DebugUtils.IsNUnitRunning)
if (!hasReplayAttached && FrameStablePlayback && proposedTime > referenceClock.CurrentTime && !AllowBackwardsSeeks)
{
Logger.Log($"Denying backwards seek during gameplay (reference: {referenceClock.CurrentTime:N2} stable: {proposedTime:N2})");
state = PlaybackState.NotValid;

View File

@ -70,10 +70,20 @@ protected void CreateTest([CanBeNull] Action action = null)
AddStep($"Load player for {CreatePlayerRuleset().Description}", LoadPlayer);
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
if (AllowBackwardsSeeks)
{
AddStep("allow backwards seeking", () =>
{
Player.DrawableRuleset.AllowBackwardsSeeks = AllowBackwardsSeeks;
});
}
}
protected virtual bool AllowFail => false;
protected virtual bool AllowBackwardsSeeks => false;
protected virtual bool Autoplay => false;
protected void LoadPlayer() => LoadPlayer(Array.Empty<Mod>());
@ -126,6 +136,6 @@ protected override void Dispose(bool isDisposing)
protected sealed override Ruleset CreateRuleset() => CreatePlayerRuleset();
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false, AllowBackwardsSeeks);
}
}