Skip to content
Merged
88 changes: 88 additions & 0 deletions osu.Game.Benchmarks/BenchmarkScoreMultiplierCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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.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();
}

[Benchmark]
public double ViaModScoreMultiplier() => viaModScoreMultiplier(Times, Mods);

[Test]
public void ViaModScoreMultiplier([Values(100)] int times, [ValueSource(nameof(ValuesForMods))] ModTestCase mods)
=> viaModScoreMultiplier(times, mods);

private double viaModScoreMultiplier(int times, ModTestCase mods)
{
double scoreMultiplier = 1;

for (int i = 0; i < times; ++i)
{
scoreMultiplier = 1;

foreach (var mod in mods.Mods)
scoreMultiplier *= mod.ScoreMultiplier;
}

return scoreMultiplier;
}

[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;
}
}
}
41 changes: 41 additions & 0 deletions osu.Game.Rulesets.Catch.Tests/CatchScoreMultiplierTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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;
using osu.Game.Rulesets.Catch.Mods;
using osu.Game.Tests.Rulesets;

namespace osu.Game.Rulesets.Catch.Tests
{
public class CatchScoreMultiplierTest : RulesetScoreMultiplierTest
{
public CatchScoreMultiplierTest()
: base(new CatchRuleset())
{
}

[Test]
public void TestFlashlightOnNonDefaultSettings()
=> TestModCombination([new CatchModFlashlight { ComboBasedSize = { Value = false } }]);

[Test]
public void TestHalfTimeSpeeds([Values(0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99)] double speedChange)
=> TestModCombination([new CatchModHalfTime { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestDaycoreSpeeds([Values(0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99)] double speedChange)
=> TestModCombination([new CatchModDaycore { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestDoubleTimeSpeeds([Values(1.01, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2)] double speedChange)
=> TestModCombination([new CatchModDoubleTime { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestNightcoreSpeeds([Values(1.01, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2)] double speedChange)
=> TestModCombination([new CatchModNightcore { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestMultiplicativeCombination()
=> TestModCombination([new CatchModHidden(), new CatchModHardRock()]);
}
}
2 changes: 2 additions & 0 deletions osu.Game.Rulesets.Catch/CatchRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
}
}

public override ScoreMultiplierCalculator CreateScoreMultiplierCalculator() => new CatchScoreMultiplierCalculator();

public override string Description => "osu!catch";

public override string ShortName => SHORT_NAME;
Expand Down
85 changes: 85 additions & 0 deletions osu.Game.Rulesets.Catch/Scoring/CatchScoreMultiplierCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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 osu.Game.Rulesets.Catch.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;

namespace osu.Game.Rulesets.Catch.Scoring
{
public class CatchScoreMultiplierCalculator : ScoreMultiplierCalculator
{
static CatchScoreMultiplierCalculator()
{
#region Difficulty Reduction

Single<CatchModEasy>(hasMultiplier: 0.5);
Single<CatchModNoFail>(hasMultiplier: 0.5);
Single<CatchModHalfTime>(hasMultiplier: halfTime => rateAdjustMultiplier(halfTime.SpeedChange.Value));
Single<CatchModDaycore>(hasMultiplier: daycore => rateAdjustMultiplier(daycore.SpeedChange.Value));

#endregion

#region Difficulty Increase

Single<CatchModHardRock>(hasMultiplier: hardRock => hardRock.UsesDefaultConfiguration ? 1.12 : 1);
// Sudden Death
// Perfect
Single<CatchModDoubleTime>(hasMultiplier: doubleTime => rateAdjustMultiplier(doubleTime.SpeedChange.Value));
Single<CatchModNightcore>(hasMultiplier: nightcore => rateAdjustMultiplier(nightcore.SpeedChange.Value));
Single<CatchModHidden>(hasMultiplier: hidden => hidden.UsesDefaultConfiguration ? 1.06 : 1);
Single<CatchModFlashlight>(hasMultiplier: flashlight => flashlight.UsesDefaultConfiguration ? 1.12 : 1);
// Accuracy Challenge

#endregion

#region Conversion

Single<CatchModDifficultyAdjust>(hasMultiplier: 0.5);
Single<CatchModClassic>(hasMultiplier: 0.96);
// Mirror

#endregion

#region Automation

// Autoplay
// Cinema
Single<CatchModRelax>(hasMultiplier: 0.1);

#endregion

#region Fun

Single<ModWindUp>(hasMultiplier: 0.5);
Single<ModWindDown>(hasMultiplier: 0.5);
// Floating Fruits
// Muted
// No Scope
// Moving Fast
Single<CatchModSynesthesia>(hasMultiplier: 0.8);

#endregion

#region System

// Score V2

#endregion
}

private static double rateAdjustMultiplier(double speedChange)
{
// Round to the nearest multiple of 0.1.
double value = (int)(speedChange * 10) / 10.0;

// Offset back to 0.
value -= 1;

if (speedChange >= 1)
return 1 + value / 5;
else
return 0.6 + value;
}
}
}
37 changes: 37 additions & 0 deletions osu.Game.Rulesets.Mania.Tests/ManiaScoreMultiplierTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Tests.Rulesets;

namespace osu.Game.Rulesets.Mania.Tests
{
public class ManiaScoreMultiplierTest : RulesetScoreMultiplierTest
{
public ManiaScoreMultiplierTest()
: base(new ManiaRuleset())
{
}

[Test]
public void TestHalfTimeSpeeds([Values(0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99)] double speedChange)
=> TestModCombination([new ManiaModHalfTime { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestDaycoreSpeeds([Values(0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 0.99)] double speedChange)
=> TestModCombination([new ManiaModDaycore { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestDoubleTimeSpeeds([Values(1.01, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2)] double speedChange)
=> TestModCombination([new ManiaModDoubleTime { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestNightcoreSpeeds([Values(1.01, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2)] double speedChange)
=> TestModCombination([new ManiaModNightcore { SpeedChange = { Value = speedChange } }]);

[Test]
public void TestMultiplicativeCombination()
=> TestModCombination([new ManiaModEasy(), new ManiaModKey4()]);
}
}
2 changes: 2 additions & 0 deletions osu.Game.Rulesets.Mania/ManiaRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
}
}

public override ScoreMultiplierCalculator CreateScoreMultiplierCalculator() => new ManiaScoreMultiplierCalculator();

public override string Description => "osu!mania";

public override string ShortName => SHORT_NAME;
Expand Down
99 changes: 99 additions & 0 deletions osu.Game.Rulesets.Mania/Scoring/ManiaScoreMultiplierCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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 osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;

namespace osu.Game.Rulesets.Mania.Scoring
{
public class ManiaScoreMultiplierCalculator : ScoreMultiplierCalculator
{
static ManiaScoreMultiplierCalculator()
{
#region Difficulty Reduction

Single<ManiaModEasy>(hasMultiplier: 0.5);
Single<ManiaModNoFail>(hasMultiplier: 0.5);
Single<ManiaModHalfTime>(hasMultiplier: halfTime => rateAdjustMultiplier(halfTime.SpeedChange.Value));
Single<ManiaModDaycore>(hasMultiplier: daycore => rateAdjustMultiplier(daycore.SpeedChange.Value));
Single<ManiaModNoRelease>(hasMultiplier: 0.9);

#endregion

#region Difficulty Increase

// Hard Rock
// Sudden Death
// Perfect
// Double Time
// Nightcore
// Fade In
// Hidden
// Cover
// Flashlight
// Accuracy Challenge

#endregion

#region Conversion

// Random
// Dual Stages
// Mirror
Single<ManiaModDifficultyAdjust>(hasMultiplier: 0.5);
Single<ManiaModClassic>(hasMultiplier: 0.96);
// Invert
Single<ManiaModConstantSpeed>(hasMultiplier: 0.9);
Single<ManiaModHoldOff>(hasMultiplier: 0.9);
Single<ManiaModKey1>(hasMultiplier: 0.9);
Single<ManiaModKey2>(hasMultiplier: 0.9);
Single<ManiaModKey3>(hasMultiplier: 0.9);
Single<ManiaModKey4>(hasMultiplier: 0.9);
Single<ManiaModKey5>(hasMultiplier: 0.9);
Single<ManiaModKey6>(hasMultiplier: 0.9);
Single<ManiaModKey7>(hasMultiplier: 0.9);
Single<ManiaModKey8>(hasMultiplier: 0.9);
Single<ManiaModKey9>(hasMultiplier: 0.9);
Single<ManiaModKey10>(hasMultiplier: 0.9);

#endregion

#region Automation

// Autoplay
// Cinema

#endregion

#region Fun

Single<ModWindUp>(hasMultiplier: 0.5);
Single<ModWindDown>(hasMultiplier: 0.5);
// Muted
Single<ModAdaptiveSpeed>(hasMultiplier: 0.5);

#endregion

#region System

// Score V2

#endregion
}

private static double rateAdjustMultiplier(double speedChange)
{
// Round to the nearest multiple of 0.1.
double value = (int)(speedChange * 10) / 10.0;

// Offset back to 0.
value -= 1;

if (speedChange >= 1)
return 1 + value / 5;
else
return 0.6 + value;
}
}
}
Loading
Loading