1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 04:42:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneUnstableRateCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
3.7 KiB
C#
Raw Normal View History

2021-11-04 23:23:29 +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
2021-11-04 23:23:29 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu;
2021-11-04 23:23:29 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneUnstableRateCounter : OsuTestScene
{
[Cached(typeof(ScoreProcessor))]
private TestScoreProcessor scoreProcessor = new TestScoreProcessor();
private readonly OsuHitWindows hitWindows = new OsuHitWindows();
2021-11-04 23:23:29 +08:00
private UnstableRateCounter counter;
2021-11-04 23:23:29 +08:00
private double prev;
[SetUpSteps]
public void SetUp()
{
AddStep("Reset Score Processor", () => scoreProcessor.Reset());
}
[Test]
public void TestBasic()
{
AddStep("Create Display", recreateDisplay);
2021-11-04 23:23:29 +08:00
// Needs multiples 2 by the nature of UR, and went for 4 to be safe.
// Creates a 250 UR by placing a +25ms then a -25ms judgement, which then results in a 250 UR
AddRepeatStep("Set UR to 250", () => applyJudgement(25, true), 4);
2021-11-04 23:23:29 +08:00
AddUntilStep("UR = 250", () => counter.Current.Value == 250.0);
2021-11-04 23:23:29 +08:00
AddRepeatStep("Revert UR", () =>
2021-11-04 23:23:29 +08:00
{
scoreProcessor.RevertResult(
new JudgementResult(new HitCircle { HitWindows = hitWindows }, new Judgement())
{
TimeOffset = 25,
Type = HitResult.Perfect,
});
}, 4);
AddUntilStep("UR is 0", () => counter.Current.Value == 0.0);
AddUntilStep("Counter is invalid", () => counter.Child.Alpha == 0.3f);
//Sets a UR of 0 by creating 10 10ms offset judgements. Since average = offset, UR = 0
AddRepeatStep("Set UR to 0", () => applyJudgement(10, false), 10);
//Applies a UR of 100 by creating 10 -10ms offset judgements. At the 10th judgement, offset should be 100.
AddRepeatStep("Bring UR to 100", () => applyJudgement(-10, false), 10);
2021-11-04 23:23:29 +08:00
}
2021-11-11 19:55:14 +08:00
[Test]
public void TestCounterReceivesJudgementsBeforeCreation()
{
AddRepeatStep("Set UR to 250", () => applyJudgement(25, true), 4);
AddStep("Create Display", recreateDisplay);
AddUntilStep("UR = 250", () => counter.Current.Value == 250.0);
}
private void recreateDisplay()
2021-11-04 23:23:29 +08:00
{
Clear();
Add(counter = new UnstableRateCounter
2021-11-04 23:23:29 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5),
});
}
private void applyJudgement(double offsetMs, bool alt)
2021-11-04 23:23:29 +08:00
{
double placement = offsetMs;
if (alt)
2021-11-04 23:23:29 +08:00
{
placement = prev > 0 ? -offsetMs : offsetMs;
prev = placement;
}
2021-11-04 23:23:29 +08:00
scoreProcessor.ApplyResult(new JudgementResult(new HitCircle { HitWindows = hitWindows }, new Judgement())
2021-11-04 23:23:29 +08:00
{
TimeOffset = placement,
Type = HitResult.Perfect,
2021-11-04 23:23:29 +08:00
});
}
private class TestScoreProcessor : ScoreProcessor
{
public TestScoreProcessor()
: base(new OsuRuleset())
{
}
2021-11-04 23:23:29 +08:00
public void Reset() => base.Reset(false);
}
}
}