1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 17:27:24 +08:00

Add test coverage of gameplay only running forwards

This commit is contained in:
Dean Herbert 2024-02-29 14:15:29 +08:00
parent f44aadaaa8
commit 5495c2090a
No known key found for this signature in database

View File

@ -16,6 +16,7 @@ using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Rulesets;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osuTK;
@ -31,6 +32,9 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override Container<Drawable> Content => content;
private bool gameplayClockAlwaysGoingForward = true;
private double lastForwardCheckTime;
public TestScenePause()
{
base.Content.Add(content = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both });
@ -67,12 +71,20 @@ namespace osu.Game.Tests.Visual.Gameplay
confirmPausedWithNoOverlay();
}
[Test]
public void TestForwardPlaybackGuarantee()
{
hookForwardPlaybackCheck();
AddUntilStep("wait for forward playback", () => Player.GameplayClockContainer.CurrentTime > 1000);
AddStep("seek before gameplay", () => Player.GameplayClockContainer.Seek(-5000));
checkForwardPlayback();
}
[Test]
public void TestPauseWithLargeOffset()
{
double lastStopTime;
bool alwaysGoingForward = true;
AddStep("force large offset", () =>
{
var offset = (BindableDouble)LocalConfig.GetBindable<double>(OsuSetting.AudioOffset);
@ -82,25 +94,7 @@ namespace osu.Game.Tests.Visual.Gameplay
offset.Value = -5000;
});
AddStep("add time forward check hook", () =>
{
lastStopTime = double.MinValue;
alwaysGoingForward = true;
Player.OnUpdate += _ =>
{
var masterClock = (MasterGameplayClockContainer)Player.GameplayClockContainer;
double currentTime = masterClock.CurrentTime;
bool goingForward = currentTime >= lastStopTime;
alwaysGoingForward &= goingForward;
if (!goingForward)
Logger.Log($"Went too far backwards (last stop: {lastStopTime:N1} current: {currentTime:N1})");
};
});
hookForwardPlaybackCheck();
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
@ -108,11 +102,37 @@ namespace osu.Game.Tests.Visual.Gameplay
resumeAndConfirm();
AddAssert("time didn't go too far backwards", () => alwaysGoingForward);
checkForwardPlayback();
AddStep("reset offset", () => LocalConfig.SetValue(OsuSetting.AudioOffset, 0.0));
}
private void checkForwardPlayback() => AddAssert("time didn't go too far backwards", () => gameplayClockAlwaysGoingForward);
private void hookForwardPlaybackCheck()
{
AddStep("add time forward check hook", () =>
{
lastForwardCheckTime = double.MinValue;
gameplayClockAlwaysGoingForward = true;
Player.OnUpdate += _ =>
{
var frameStableClock = Player.ChildrenOfType<FrameStabilityContainer>().Single().Clock;
double currentTime = frameStableClock.CurrentTime;
bool goingForward = currentTime >= lastForwardCheckTime;
lastForwardCheckTime = currentTime;
gameplayClockAlwaysGoingForward &= goingForward;
if (!goingForward)
Logger.Log($"Went too far backwards (last stop: {lastForwardCheckTime:N1} current: {currentTime:N1})");
};
});
}
[Test]
public void TestPauseResume()
{