2020-06-14 10:34:07 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-06-14 10:34:07 +08:00
|
|
|
using NUnit.Framework;
|
2022-01-30 04:39:45 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Bindables;
|
2020-06-19 21:43:25 +08:00
|
|
|
using osu.Framework.Testing;
|
2022-01-30 04:39:45 +08:00
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Configuration;
|
2020-06-14 10:34:07 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Gameplay
|
|
|
|
{
|
2020-06-19 21:43:25 +08:00
|
|
|
[HeadlessTest]
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneMasterGameplayClockContainer : OsuTestScene
|
2020-06-14 10:34:07 +08:00
|
|
|
{
|
2022-01-30 04:39:45 +08:00
|
|
|
private OsuConfigManager localConfig;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
|
|
|
|
}
|
|
|
|
|
2022-04-14 17:09:23 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("reset audio offset", () => localConfig.SetValue(OsuSetting.AudioOffset, 0.0));
|
|
|
|
}
|
|
|
|
|
2020-06-14 10:34:07 +08:00
|
|
|
[Test]
|
|
|
|
public void TestStartThenElapsedTime()
|
|
|
|
{
|
2022-01-31 14:23:31 +08:00
|
|
|
GameplayClockContainer gameplayClockContainer = null;
|
2020-06-14 10:34:07 +08:00
|
|
|
|
2020-08-06 17:31:08 +08:00
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
2022-03-18 17:16:45 +08:00
|
|
|
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
|
2020-08-06 17:31:08 +08:00
|
|
|
});
|
|
|
|
|
2022-01-31 14:23:31 +08:00
|
|
|
AddStep("start clock", () => gameplayClockContainer.Start());
|
2022-08-15 16:06:24 +08:00
|
|
|
AddUntilStep("elapsed greater than zero", () => gameplayClockContainer.ElapsedFrameTime > 0);
|
2020-06-14 10:34:07 +08:00
|
|
|
}
|
2021-04-20 12:56:13 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestElapseThenReset()
|
|
|
|
{
|
2022-01-31 14:23:31 +08:00
|
|
|
GameplayClockContainer gameplayClockContainer = null;
|
2021-04-20 12:56:13 +08:00
|
|
|
|
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
2022-03-18 17:16:45 +08:00
|
|
|
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
|
2021-04-20 12:56:13 +08:00
|
|
|
});
|
|
|
|
|
2022-01-31 14:23:31 +08:00
|
|
|
AddStep("start clock", () => gameplayClockContainer.Start());
|
2022-08-15 16:06:24 +08:00
|
|
|
AddUntilStep("current time greater 2000", () => gameplayClockContainer.CurrentTime > 2000);
|
2021-04-20 12:56:13 +08:00
|
|
|
|
|
|
|
double timeAtReset = 0;
|
|
|
|
AddStep("reset clock", () =>
|
|
|
|
{
|
2022-08-15 16:06:24 +08:00
|
|
|
timeAtReset = gameplayClockContainer.CurrentTime;
|
2022-01-31 14:23:31 +08:00
|
|
|
gameplayClockContainer.Reset();
|
2021-04-20 12:56:13 +08:00
|
|
|
});
|
|
|
|
|
2022-08-15 16:06:24 +08:00
|
|
|
AddAssert("current time < time at reset", () => gameplayClockContainer.CurrentTime < timeAtReset);
|
2021-04-20 12:56:13 +08:00
|
|
|
}
|
2022-01-30 04:39:45 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSeekPerformsInGameplayTime(
|
|
|
|
[Values(1.0, 0.5, 2.0)] double clockRate,
|
|
|
|
[Values(0.0, 200.0, -200.0)] double userOffset,
|
2022-03-24 13:55:01 +08:00
|
|
|
[Values(false, true)] bool whileStopped,
|
|
|
|
[Values(false, true)] bool setAudioOffsetBeforeConstruction)
|
2022-01-30 04:39:45 +08:00
|
|
|
{
|
|
|
|
ClockBackedTestWorkingBeatmap working = null;
|
2022-01-31 14:23:31 +08:00
|
|
|
GameplayClockContainer gameplayClockContainer = null;
|
2022-01-30 04:39:45 +08:00
|
|
|
|
2023-01-14 19:34:22 +08:00
|
|
|
// ReSharper disable once NotAccessedVariable
|
|
|
|
BindableDouble trackAdjustment = null; // keeping a reference for track adjustment
|
|
|
|
|
2022-03-24 13:55:01 +08:00
|
|
|
if (setAudioOffsetBeforeConstruction)
|
|
|
|
AddStep($"preset audio offset to {userOffset}", () => localConfig.SetValue(OsuSetting.AudioOffset, userOffset));
|
|
|
|
|
2022-01-30 04:39:45 +08:00
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
working = new ClockBackedTestWorkingBeatmap(new OsuRuleset().RulesetInfo, new FramedClock(new ManualClock()), Audio);
|
2022-03-18 17:16:45 +08:00
|
|
|
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
|
2022-01-30 04:39:45 +08:00
|
|
|
|
2022-03-18 14:08:25 +08:00
|
|
|
gameplayClockContainer.Reset(startClock: !whileStopped);
|
2022-01-30 04:39:45 +08:00
|
|
|
});
|
|
|
|
|
2023-01-14 19:34:22 +08:00
|
|
|
AddStep($"set clock rate to {clockRate}", () => working.Track.AddAdjustment(AdjustableProperty.Frequency, trackAdjustment = new BindableDouble(clockRate)));
|
2022-03-24 13:55:01 +08:00
|
|
|
|
|
|
|
if (!setAudioOffsetBeforeConstruction)
|
|
|
|
AddStep($"set audio offset to {userOffset}", () => localConfig.SetValue(OsuSetting.AudioOffset, userOffset));
|
2022-01-30 04:39:45 +08:00
|
|
|
|
2022-01-31 14:23:31 +08:00
|
|
|
AddStep("seek to 2500", () => gameplayClockContainer.Seek(2500));
|
2023-01-14 19:34:22 +08:00
|
|
|
AddAssert("gameplay clock time = 2500", () => gameplayClockContainer.CurrentTime, () => Is.EqualTo(2500).Within(10f));
|
2022-01-30 04:39:45 +08:00
|
|
|
|
2022-01-31 14:23:31 +08:00
|
|
|
AddStep("seek to 10000", () => gameplayClockContainer.Seek(10000));
|
2023-01-14 19:34:22 +08:00
|
|
|
AddAssert("gameplay clock time = 10000", () => gameplayClockContainer.CurrentTime, () => Is.EqualTo(10000).Within(10f));
|
2022-01-30 04:39:45 +08:00
|
|
|
}
|
|
|
|
|
2023-10-27 01:27:05 +08:00
|
|
|
[Test]
|
|
|
|
public void TestStopUsingBeatmapClock()
|
|
|
|
{
|
|
|
|
ClockBackedTestWorkingBeatmap working = null;
|
|
|
|
MasterGameplayClockContainer gameplayClockContainer = null;
|
|
|
|
BindableDouble frequencyAdjustment = new BindableDouble(2);
|
|
|
|
|
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
working = new ClockBackedTestWorkingBeatmap(new OsuRuleset().RulesetInfo, new FramedClock(new ManualClock()), Audio);
|
|
|
|
Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0);
|
|
|
|
|
|
|
|
gameplayClockContainer.Reset(startClock: true);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("apply frequency adjustment", () => gameplayClockContainer.AdjustmentsFromMods.AddAdjustment(AdjustableProperty.Frequency, frequencyAdjustment));
|
|
|
|
AddAssert("track frequency changed", () => working.Track.AggregateFrequency.Value, () => Is.EqualTo(2));
|
|
|
|
|
|
|
|
AddStep("stop using beatmap clock", () => gameplayClockContainer.StopUsingBeatmapClock());
|
|
|
|
AddAssert("frequency adjustment unapplied", () => working.Track.AggregateFrequency.Value, () => Is.EqualTo(1));
|
|
|
|
}
|
|
|
|
|
2022-01-30 04:39:45 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
localConfig?.Dispose();
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
}
|
2020-06-14 10:34:07 +08:00
|
|
|
}
|
|
|
|
}
|