1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 16:32:59 +08:00

Use fresh mods for each difficulty calculation

This commit is contained in:
smoogipoo 2019-03-14 23:39:45 +09:00
parent bbf42fdd00
commit 24fb25f1cd
6 changed files with 46 additions and 42 deletions

View File

@ -90,12 +90,12 @@ namespace osu.Game.Rulesets.Catch.Difficulty
new Movement(), new Movement(),
}; };
protected override Mod[] DifficultyAdjustmentMods => new Mod[] protected override Type[] DifficultyAdjustmentMods => new[]
{ {
new CatchModDoubleTime(), typeof(CatchModDoubleTime),
new CatchModHalfTime(), typeof(CatchModHalfTime),
new CatchModHardRock(), typeof(CatchModHardRock),
new CatchModEasy(), typeof(CatchModEasy),
}; };
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -91,33 +92,33 @@ namespace osu.Game.Rulesets.Mania.Difficulty
return skills.ToArray(); return skills.ToArray();
} }
protected override Mod[] DifficultyAdjustmentMods protected override Type[] DifficultyAdjustmentMods
{ {
get get
{ {
var mods = new Mod[] var mods = new[]
{ {
new ManiaModDoubleTime(), typeof(ManiaModDoubleTime),
new ManiaModHalfTime(), typeof(ManiaModHalfTime),
new ManiaModEasy(), typeof(ManiaModEasy),
new ManiaModHardRock(), typeof(ManiaModHardRock)
}; };
if (isForCurrentRuleset) if (isForCurrentRuleset)
return mods; return mods;
// if we are a convert, we can be played in any key mod. // if we are a convert, we can be played in any key mod.
return mods.Concat(new Mod[] return mods.Concat(new[]
{ {
new ManiaModKey1(), typeof(ManiaModKey1),
new ManiaModKey2(), typeof(ManiaModKey2),
new ManiaModKey3(), typeof(ManiaModKey3),
new ManiaModKey4(), typeof(ManiaModKey4),
new ManiaModKey5(), typeof(ManiaModKey5),
new ManiaModKey6(), typeof(ManiaModKey6),
new ManiaModKey7(), typeof(ManiaModKey7),
new ManiaModKey8(), typeof(ManiaModKey8),
new ManiaModKey9(), typeof(ManiaModKey9),
}).ToArray(); }).ToArray();
} }
} }

View File

@ -74,12 +74,12 @@ namespace osu.Game.Rulesets.Osu.Difficulty
new Speed() new Speed()
}; };
protected override Mod[] DifficultyAdjustmentMods => new Mod[] protected override Type[] DifficultyAdjustmentMods => new[]
{ {
new OsuModDoubleTime(), typeof(OsuModDoubleTime),
new OsuModHalfTime(), typeof(OsuModHalfTime),
new OsuModEasy(), typeof(OsuModEasy),
new OsuModHardRock(), typeof(OsuModHardRock),
}; };
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -47,12 +48,12 @@ namespace osu.Game.Rulesets.Taiko.Difficulty
protected override Skill[] CreateSkills(IBeatmap beatmap) => new Skill[] { new Strain() }; protected override Skill[] CreateSkills(IBeatmap beatmap) => new Skill[] { new Strain() };
protected override Mod[] DifficultyAdjustmentMods => new Mod[] protected override Type[] DifficultyAdjustmentMods => new[]
{ {
new TaikoModDoubleTime(), typeof(TaikoModDoubleTime),
new TaikoModHalfTime(), typeof(TaikoModHalfTime),
new TaikoModEasy(), typeof(TaikoModEasy),
new TaikoModHardRock(), typeof(TaikoModHardRock),
}; };
} }
} }

View File

@ -27,7 +27,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestSingleMod() public void TestSingleMod()
{ {
var combinations = new TestLegacyDifficultyCalculator(new ModA()).CreateDifficultyAdjustmentModCombinations(); var combinations = new TestLegacyDifficultyCalculator(typeof(ModA)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(2, combinations.Length); Assert.AreEqual(2, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod); Assert.IsTrue(combinations[0] is ModNoMod);
@ -37,7 +37,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestDoubleMod() public void TestDoubleMod()
{ {
var combinations = new TestLegacyDifficultyCalculator(new ModA(), new ModB()).CreateDifficultyAdjustmentModCombinations(); var combinations = new TestLegacyDifficultyCalculator(typeof(ModA), typeof(ModB)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(4, combinations.Length); Assert.AreEqual(4, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod); Assert.IsTrue(combinations[0] is ModNoMod);
@ -52,7 +52,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestIncompatibleMods() public void TestIncompatibleMods()
{ {
var combinations = new TestLegacyDifficultyCalculator(new ModA(), new ModIncompatibleWithA()).CreateDifficultyAdjustmentModCombinations(); var combinations = new TestLegacyDifficultyCalculator(typeof(ModA), typeof(ModIncompatibleWithA)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(3, combinations.Length); Assert.AreEqual(3, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod); Assert.IsTrue(combinations[0] is ModNoMod);
@ -63,7 +63,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestDoubleIncompatibleMods() public void TestDoubleIncompatibleMods()
{ {
var combinations = new TestLegacyDifficultyCalculator(new ModA(), new ModB(), new ModIncompatibleWithA(), new ModIncompatibleWithAAndB()).CreateDifficultyAdjustmentModCombinations(); var combinations = new TestLegacyDifficultyCalculator(typeof(ModA), typeof(ModB), typeof(ModIncompatibleWithA), typeof(ModIncompatibleWithAAndB)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(8, combinations.Length); Assert.AreEqual(8, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod); Assert.IsTrue(combinations[0] is ModNoMod);
@ -86,7 +86,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestIncompatibleThroughBaseType() public void TestIncompatibleThroughBaseType()
{ {
var combinations = new TestLegacyDifficultyCalculator(new ModAofA(), new ModIncompatibleWithAofA()).CreateDifficultyAdjustmentModCombinations(); var combinations = new TestLegacyDifficultyCalculator(typeof(ModAofA), typeof(ModIncompatibleWithAofA)).CreateDifficultyAdjustmentModCombinations();
Assert.AreEqual(3, combinations.Length); Assert.AreEqual(3, combinations.Length);
Assert.IsTrue(combinations[0] is ModNoMod); Assert.IsTrue(combinations[0] is ModNoMod);
@ -141,13 +141,13 @@ namespace osu.Game.Tests.NonVisual
private class TestLegacyDifficultyCalculator : DifficultyCalculator private class TestLegacyDifficultyCalculator : DifficultyCalculator
{ {
public TestLegacyDifficultyCalculator(params Mod[] mods) public TestLegacyDifficultyCalculator(params Type[] mods)
: base(null, null) : base(null, null)
{ {
DifficultyAdjustmentMods = mods; DifficultyAdjustmentMods = mods;
} }
protected override Mod[] DifficultyAdjustmentMods { get; } protected override Type[] DifficultyAdjustmentMods { get; }
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate) protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
{ {

View File

@ -106,7 +106,7 @@ namespace osu.Game.Rulesets.Difficulty
{ {
return createDifficultyAdjustmentModCombinations(Enumerable.Empty<Mod>(), DifficultyAdjustmentMods).ToArray(); return createDifficultyAdjustmentModCombinations(Enumerable.Empty<Mod>(), DifficultyAdjustmentMods).ToArray();
IEnumerable<Mod> createDifficultyAdjustmentModCombinations(IEnumerable<Mod> currentSet, Mod[] adjustmentSet, int currentSetCount = 0, int adjustmentSetStart = 0) IEnumerable<Mod> createDifficultyAdjustmentModCombinations(IEnumerable<Mod> currentSet, Type[] adjustmentSet, int currentSetCount = 0, int adjustmentSetStart = 0)
{ {
switch (currentSetCount) switch (currentSetCount)
{ {
@ -129,12 +129,14 @@ namespace osu.Game.Rulesets.Difficulty
// combinations in further recursions, so a moving subset is used to eliminate this effect // combinations in further recursions, so a moving subset is used to eliminate this effect
for (int i = adjustmentSetStart; i < adjustmentSet.Length; i++) for (int i = adjustmentSetStart; i < adjustmentSet.Length; i++)
{ {
var adjustmentMod = adjustmentSet[i]; var adjustmentMod = createMod();
if (currentSet.Any(c => c.IncompatibleMods.Any(m => m.IsInstanceOfType(adjustmentMod)))) if (currentSet.Any(c => c.IncompatibleMods.Any(m => m.IsInstanceOfType(adjustmentMod))))
continue; continue;
foreach (var combo in createDifficultyAdjustmentModCombinations(currentSet.Append(adjustmentMod), adjustmentSet, currentSetCount + 1, i + 1)) foreach (var combo in createDifficultyAdjustmentModCombinations(currentSet.Append(createMod()), adjustmentSet, currentSetCount + 1, i + 1))
yield return combo; yield return combo;
Mod createMod() => (Mod)Activator.CreateInstance(adjustmentSet[i]);
} }
} }
} }
@ -142,7 +144,7 @@ namespace osu.Game.Rulesets.Difficulty
/// <summary> /// <summary>
/// Retrieves all <see cref="Mod"/>s which adjust the <see cref="Beatmap"/> difficulty. /// Retrieves all <see cref="Mod"/>s which adjust the <see cref="Beatmap"/> difficulty.
/// </summary> /// </summary>
protected virtual Mod[] DifficultyAdjustmentMods => Array.Empty<Mod>(); protected virtual Type[] DifficultyAdjustmentMods => Array.Empty<Type>();
/// <summary> /// <summary>
/// Creates <see cref="DifficultyAttributes"/> to describe beatmap's calculated difficulty. /// Creates <see cref="DifficultyAttributes"/> to describe beatmap's calculated difficulty.