1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Fix mania difficulty calculator crashing

This commit is contained in:
smoogipoo 2021-10-01 19:57:45 +09:00
parent 36be041846
commit 5820a71652
3 changed files with 28 additions and 22 deletions

View File

@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Mania.Difficulty
Mods = mods,
// Todo: This int cast is temporary to achieve 1:1 results with osu!stable, and should be removed in the future
GreatHitWindow = (int)Math.Ceiling(getHitWindow300(mods) / clockRate),
ScoreMultiplier = getScoreMultiplier(beatmap, mods),
ScoreMultiplier = getScoreMultiplier(mods),
MaxCombo = beatmap.HitObjects.Sum(h => h is HoldNote ? 2 : 1),
Skills = skills
};
@ -70,7 +70,7 @@ namespace osu.Game.Rulesets.Mania.Difficulty
protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate) => new Skill[]
{
new Strain(mods, ((ManiaBeatmap)beatmap).TotalColumns)
new Strain(mods, ((ManiaBeatmap)Beatmap).TotalColumns)
};
protected override Mod[] DifficultyAdjustmentMods
@ -138,7 +138,7 @@ namespace osu.Game.Rulesets.Mania.Difficulty
}
}
private double getScoreMultiplier(IBeatmap beatmap, Mod[] mods)
private double getScoreMultiplier(Mod[] mods)
{
double scoreMultiplier = 1;
@ -154,7 +154,7 @@ namespace osu.Game.Rulesets.Mania.Difficulty
}
}
var maniaBeatmap = (ManiaBeatmap)beatmap;
var maniaBeatmap = (ManiaBeatmap)Beatmap;
int diff = maniaBeatmap.TotalColumns - maniaBeatmap.OriginalTotalColumns;
if (diff > 0)

View File

@ -18,13 +18,17 @@ namespace osu.Game.Rulesets.Difficulty
{
public abstract class DifficultyCalculator
{
private readonly Ruleset ruleset;
private readonly WorkingBeatmap beatmap;
/// <summary>
/// The beatmap for which difficulty will be calculated.
/// </summary>
protected IBeatmap Beatmap { get; private set; }
private IBeatmap playableBeatmap;
private Mod[] playableMods;
private double clockRate;
private readonly Ruleset ruleset;
private readonly WorkingBeatmap beatmap;
protected DifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap)
{
this.ruleset = ruleset;
@ -40,10 +44,10 @@ namespace osu.Game.Rulesets.Difficulty
{
preProcess(mods);
var skills = CreateSkills(playableBeatmap, playableMods, clockRate);
var skills = CreateSkills(Beatmap, playableMods, clockRate);
if (!playableBeatmap.HitObjects.Any())
return CreateDifficultyAttributes(playableBeatmap, playableMods, skills, clockRate);
if (!Beatmap.HitObjects.Any())
return CreateDifficultyAttributes(Beatmap, playableMods, skills, clockRate);
foreach (var hitObject in getDifficultyHitObjects())
{
@ -51,18 +55,18 @@ namespace osu.Game.Rulesets.Difficulty
skill.ProcessInternal(hitObject);
}
return CreateDifficultyAttributes(playableBeatmap, playableMods, skills, clockRate);
return CreateDifficultyAttributes(Beatmap, playableMods, skills, clockRate);
}
public IEnumerable<TimedDifficultyAttributes> CalculateTimed(params Mod[] mods)
{
preProcess(mods);
if (!playableBeatmap.HitObjects.Any())
if (!Beatmap.HitObjects.Any())
yield break;
var skills = CreateSkills(playableBeatmap, playableMods, clockRate);
var progressiveBeatmap = new ProgressiveCalculationBeatmap(playableBeatmap);
var skills = CreateSkills(Beatmap, playableMods, clockRate);
var progressiveBeatmap = new ProgressiveCalculationBeatmap(Beatmap);
foreach (var hitObject in getDifficultyHitObjects())
{
@ -93,7 +97,7 @@ namespace osu.Game.Rulesets.Difficulty
/// <summary>
/// Retrieves the <see cref="DifficultyHitObject"/>s to calculate against.
/// </summary>
private IEnumerable<DifficultyHitObject> getDifficultyHitObjects() => SortObjects(CreateDifficultyHitObjects(playableBeatmap, clockRate));
private IEnumerable<DifficultyHitObject> getDifficultyHitObjects() => SortObjects(CreateDifficultyHitObjects(Beatmap, clockRate));
/// <summary>
/// Performs required tasks before every calculation.
@ -102,7 +106,7 @@ namespace osu.Game.Rulesets.Difficulty
private void preProcess(Mod[] mods)
{
playableMods = mods.Select(m => m.DeepClone()).ToArray();
playableBeatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods);
Beatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods);
var track = new TrackVirtual(10000);
mods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
@ -118,7 +122,7 @@ namespace osu.Game.Rulesets.Difficulty
=> input.OrderBy(h => h.BaseObject.StartTime);
/// <summary>
/// Creates all <see cref="Mod"/> combinations which adjust the <see cref="Beatmap"/> difficulty.
/// Creates all <see cref="Mod"/> combinations which adjust the <see cref="Beatmaps.Beatmap"/> difficulty.
/// </summary>
public Mod[] CreateDifficultyAdjustmentModCombinations()
{
@ -186,14 +190,15 @@ namespace osu.Game.Rulesets.Difficulty
}
/// <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="Beatmaps.Beatmap"/> difficulty.
/// </summary>
protected virtual Mod[] DifficultyAdjustmentMods => Array.Empty<Mod>();
/// <summary>
/// Creates <see cref="DifficultyAttributes"/> to describe beatmap's calculated difficulty.
/// </summary>
/// <param name="beatmap">The <see cref="IBeatmap"/> whose difficulty was calculated.</param>
/// <param name="beatmap">The <see cref="IBeatmap"/> whose difficulty was calculated.
/// This may differ from <see cref="Beatmap"/> in the case of timed calculation.</param>
/// <param name="mods">The <see cref="Mod"/>s that difficulty was calculated with.</param>
/// <param name="skills">The skills which processed the beatmap.</param>
/// <param name="clockRate">The rate at which the gameplay clock is run at.</param>
@ -210,7 +215,8 @@ namespace osu.Game.Rulesets.Difficulty
/// <summary>
/// Creates the <see cref="Skill"/>s to calculate the difficulty of an <see cref="IBeatmap"/>.
/// </summary>
/// <param name="beatmap">The <see cref="IBeatmap"/> whose difficulty will be calculated.</param>
/// <param name="beatmap">The <see cref="IBeatmap"/> whose difficulty will be calculated.
/// This may differ from <see cref="Beatmap"/> in the case of timed calculation.</param>
/// <param name="mods">Mods to calculate difficulty with.</param>
/// <param name="clockRate">Clockrate to calculate difficulty with.</param>
/// <returns>The <see cref="Skill"/>s.</returns>

View File

@ -143,9 +143,9 @@ namespace osu.Game.Screens.Play.HUD
}
public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null)
=> gameplayBeatmap;
=> gameplayBeatmap.PlayableBeatmap;
protected override IBeatmap GetBeatmap() => gameplayBeatmap;
protected override IBeatmap GetBeatmap() => gameplayBeatmap.PlayableBeatmap;
protected override Texture GetBackground() => throw new NotImplementedException();