mirror of
https://github.com/ppy/osu.git
synced 2026-06-04 20:34:14 +08:00
45234b5b72
- Part of https://github.com/ppy/osu/issues/37818 Access to difficulty info is required for the upcoming multiplier proposals. All places providing difficulty info intentionally use `IBeatmapInfo` as the difficulty info exposed to the calculator should _always_ be pre-mods for our usecase. There's a couple of quirks: - The usage in `ScoreProcessor` is a bit troubling to me but I can't see a way to make it better without refactoring it. Essentially, we don't have a beatmap until `ApplyBeatmap` is called, but most usages of `ScoreProcessor` are setting `Mods` prior to `ApplyBeatmap` so there is a `null` check in the logic for when mods change. Additionally, this means a new bindable of the beatmap via `ApplyBeatmap` which also feels a bit dirty. Open to suggestions. - ~~`BeatmapLeaderboardScore.Tooltip` is using a null-forgiving on the `BeatmapInfo`, but there's basically no context available on if this is an issue - the only code path which sets the score is `SetContent` which has no callers, so it's essentially dead code. Makes sense given it's Select V1.~~ --------- Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
// 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 System.Collections.Generic;
|
|
using BenchmarkDotNet.Attributes;
|
|
using NUnit.Framework;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Rulesets.Mods;
|
|
using osu.Game.Rulesets.Osu;
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
namespace osu.Game.Benchmarks
|
|
{
|
|
public class BenchmarkScoreMultiplierCalculator : BenchmarkTest
|
|
{
|
|
private ScoreMultiplierCalculator calculator = null!;
|
|
|
|
[Params(1, 10, 100)]
|
|
public int Times { get; set; }
|
|
|
|
public record ModTestCase(string Description, IEnumerable<Mod> Mods)
|
|
{
|
|
public override string ToString() => Description;
|
|
}
|
|
|
|
public static IEnumerable<ModTestCase> ValuesForMods =>
|
|
[
|
|
new ModTestCase("no mods", []),
|
|
new ModTestCase("single mod", [new OsuModHardRock()]),
|
|
new ModTestCase("single mod 2", [new OsuModEasy()]),
|
|
new ModTestCase("multiple mods", [new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime()]),
|
|
new ModTestCase("mods with adjusted settings", [
|
|
new OsuModDoubleTime { SpeedChange = { Value = 2 } },
|
|
new OsuModHidden { OnlyFadeApproachCircles = { Value = true } },
|
|
new OsuModHardRock()
|
|
]),
|
|
];
|
|
|
|
[ParamsSource(nameof(ValuesForMods))]
|
|
public ModTestCase Mods { get; set; } = null!;
|
|
|
|
public override void SetUp()
|
|
{
|
|
base.SetUp();
|
|
calculator = new OsuRuleset().CreateScoreMultiplierCalculator(new ScoreMultiplierContext(new BeatmapDifficulty()));
|
|
}
|
|
|
|
[Benchmark]
|
|
public double ViaCalculator()
|
|
=> viaCalculator(Times, Mods);
|
|
|
|
[Test]
|
|
public void ViaCalculator([Values(100)] int times, [ValueSource(nameof(ValuesForMods))] ModTestCase mods)
|
|
=> viaCalculator(times, mods);
|
|
|
|
private double viaCalculator(int times, ModTestCase mods)
|
|
{
|
|
double scoreMultiplier = 1;
|
|
|
|
for (int i = 0; i < times; ++i)
|
|
scoreMultiplier = calculator.CalculateFor(mods.Mods);
|
|
|
|
return scoreMultiplier;
|
|
}
|
|
}
|
|
}
|