osu/osu.Game.Tests/Gameplay/TestSceneMasterGameplayClockContainer.cs

Failed to ignore revisions in .git-blame-ignore-revs.

120 lines
4.5 KiB
C#
Raw Normal View History

2020-06-14 02:34:07 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
2022-01-29 20:39:45 +00:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
2020-06-19 13:43:25 +00:00
using osu.Framework.Testing;
2022-01-29 20:39:45 +00:00
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Configuration;
2020-06-14 02:34:07 +00:00
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Gameplay
{
2020-06-19 13:43:25 +00:00
[HeadlessTest]
2021-04-16 11:51:42 +00:00
public class TestSceneMasterGameplayClockContainer : OsuTestScene
2020-06-14 02:34:07 +00:00
{
2022-01-29 20:39:45 +00:00
private OsuConfigManager localConfig;
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("reset audio offset", () => localConfig.SetValue(OsuSetting.AudioOffset, 0.0));
}
2020-06-14 02:34:07 +00:00
[Test]
public void TestStartThenElapsedTime()
{
GameplayClockContainer gameplayClockContainer = null;
2020-06-14 02:34:07 +00:00
2020-08-06 09:31:08 +00:00
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
2020-08-17 06:38:16 +00:00
working.LoadTrack();
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
2020-08-06 09:31:08 +00:00
});
AddStep("start clock", () => gameplayClockContainer.Start());
AddUntilStep("elapsed greater than zero", () => gameplayClockContainer.GameplayClock.ElapsedFrameTime > 0);
2020-06-14 02:34:07 +00:00
}
2021-04-20 04:56:13 +00:00
[Test]
public void TestElapseThenReset()
{
GameplayClockContainer gameplayClockContainer = null;
2021-04-20 04:56:13 +00:00
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack();
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
2021-04-20 04:56:13 +00:00
});
AddStep("start clock", () => gameplayClockContainer.Start());
AddUntilStep("current time greater 2000", () => gameplayClockContainer.GameplayClock.CurrentTime > 2000);
2021-04-20 04:56:13 +00:00
double timeAtReset = 0;
AddStep("reset clock", () =>
{
timeAtReset = gameplayClockContainer.GameplayClock.CurrentTime;
gameplayClockContainer.Reset();
2021-04-20 04:56:13 +00:00
});
AddAssert("current time < time at reset", () => gameplayClockContainer.GameplayClock.CurrentTime < timeAtReset);
2021-04-20 04:56:13 +00:00
}
2022-01-29 20:39:45 +00:00
[Test]
public void TestSeekPerformsInGameplayTime(
[Values(1.0, 0.5, 2.0)] double clockRate,
[Values(0.0, 200.0, -200.0)] double userOffset,
[Values(false, true)] bool whileStopped,
[Values(false, true)] bool setAudioOffsetBeforeConstruction)
2022-01-29 20:39:45 +00:00
{
ClockBackedTestWorkingBeatmap working = null;
GameplayClockContainer gameplayClockContainer = null;
2022-01-29 20:39:45 +00:00
if (setAudioOffsetBeforeConstruction)
AddStep($"preset audio offset to {userOffset}", () => localConfig.SetValue(OsuSetting.AudioOffset, userOffset));
2022-01-29 20:39:45 +00:00
AddStep("create container", () =>
{
working = new ClockBackedTestWorkingBeatmap(new OsuRuleset().RulesetInfo, new FramedClock(new ManualClock()), Audio);
working.LoadTrack();
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
2022-01-29 20:39:45 +00:00
gameplayClockContainer.Reset(startClock: !whileStopped);
2022-01-29 20:39:45 +00:00
});
AddStep($"set clock rate to {clockRate}", () => working.Track.AddAdjustment(AdjustableProperty.Frequency, new BindableDouble(clockRate)));
if (!setAudioOffsetBeforeConstruction)
AddStep($"set audio offset to {userOffset}", () => localConfig.SetValue(OsuSetting.AudioOffset, userOffset));
2022-01-29 20:39:45 +00:00
AddStep("seek to 2500", () => gameplayClockContainer.Seek(2500));
AddAssert("gameplay clock time = 2500", () => Precision.AlmostEquals(gameplayClockContainer.CurrentTime, 2500, 10f));
2022-01-29 20:39:45 +00:00
AddStep("seek to 10000", () => gameplayClockContainer.Seek(10000));
AddAssert("gameplay clock time = 10000", () => Precision.AlmostEquals(gameplayClockContainer.CurrentTime, 10000, 10f));
2022-01-29 20:39:45 +00:00
}
protected override void Dispose(bool isDisposing)
{
localConfig?.Dispose();
base.Dispose(isDisposing);
}
2020-06-14 02:34:07 +00:00
}
}