1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32: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.

147 lines
4.6 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
2023-11-13 03:16:06 +08:00
using System;
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 partial class TestSceneUnstableRateCounter : OsuTestScene
{
[Cached(typeof(ScoreProcessor))]
private TestScoreProcessor scoreProcessor = new TestScoreProcessor();
2023-02-09 16:43:04 +08:00
private readonly OsuHitWindows hitWindows;
2021-11-04 23:23:29 +08:00
private UnstableRateCounter counter;
2021-11-04 23:23:29 +08:00
private double prev;
2023-02-09 16:43:04 +08:00
public TestSceneUnstableRateCounter()
{
hitWindows = new OsuHitWindows();
hitWindows.SetDifficulty(5);
}
2021-11-04 23:23:29 +08:00
[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())
{
2023-11-13 03:13:38 +08:00
GameplayRate = 1.0,
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);
}
2023-11-13 03:16:06 +08:00
[Test]
public void TestStaticRateChange()
{
AddStep("Create Display", recreateDisplay);
AddRepeatStep("Set UR to 250 at 1.5x", () => applyJudgement(25, true, 1.5), 4);
AddUntilStep("UR = 250/1.5", () => counter.Current.Value == Math.Round(250.0 / 1.5));
}
[Test]
public void TestDynamicRateChange()
{
AddStep("Create Display", recreateDisplay);
AddRepeatStep("Set UR to 100 at 1.0x", () => applyJudgement(10, true, 1.0), 4);
AddRepeatStep("Bring UR to 100 at 1.5x", () => applyJudgement(15, true, 1.5), 4);
AddUntilStep("UR = 100", () => counter.Current.Value == 100.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),
});
}
2023-11-13 03:13:38 +08:00
private void applyJudgement(double offsetMs, bool alt, double gameplayRate = 1.0)
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,
2023-11-13 03:13:38 +08:00
GameplayRate = gameplayRate,
Type = HitResult.Perfect,
2021-11-04 23:23:29 +08:00
});
}
private partial class TestScoreProcessor : ScoreProcessor
{
public TestScoreProcessor()
: base(new OsuRuleset())
{
}
2021-11-04 23:23:29 +08:00
public void Reset() => base.Reset(false);
}
}
}