mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 21:32:57 +08:00
Add test coverage of gameplay only running forwards
This commit is contained in:
parent
f44aadaaa8
commit
5495c2090a
@ -16,6 +16,7 @@ using osu.Game.Configuration;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -31,6 +32,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
protected override Container<Drawable> Content => content;
|
protected override Container<Drawable> Content => content;
|
||||||
|
|
||||||
|
private bool gameplayClockAlwaysGoingForward = true;
|
||||||
|
private double lastForwardCheckTime;
|
||||||
|
|
||||||
public TestScenePause()
|
public TestScenePause()
|
||||||
{
|
{
|
||||||
base.Content.Add(content = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both });
|
base.Content.Add(content = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both });
|
||||||
@ -67,12 +71,20 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
confirmPausedWithNoOverlay();
|
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]
|
[Test]
|
||||||
public void TestPauseWithLargeOffset()
|
public void TestPauseWithLargeOffset()
|
||||||
{
|
{
|
||||||
double lastStopTime;
|
|
||||||
bool alwaysGoingForward = true;
|
|
||||||
|
|
||||||
AddStep("force large offset", () =>
|
AddStep("force large offset", () =>
|
||||||
{
|
{
|
||||||
var offset = (BindableDouble)LocalConfig.GetBindable<double>(OsuSetting.AudioOffset);
|
var offset = (BindableDouble)LocalConfig.GetBindable<double>(OsuSetting.AudioOffset);
|
||||||
@ -82,25 +94,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
offset.Value = -5000;
|
offset.Value = -5000;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("add time forward check hook", () =>
|
hookForwardPlaybackCheck();
|
||||||
{
|
|
||||||
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})");
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
|
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
|
||||||
|
|
||||||
@ -108,11 +102,37 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
resumeAndConfirm();
|
resumeAndConfirm();
|
||||||
|
|
||||||
AddAssert("time didn't go too far backwards", () => alwaysGoingForward);
|
checkForwardPlayback();
|
||||||
|
|
||||||
AddStep("reset offset", () => LocalConfig.SetValue(OsuSetting.AudioOffset, 0.0));
|
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]
|
[Test]
|
||||||
public void TestPauseResume()
|
public void TestPauseResume()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user