1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Avoid returning a live IEnumerable

This commit is contained in:
Dean Herbert 2021-10-05 16:59:54 +09:00
parent fa7f11d906
commit 599d82e383
3 changed files with 13 additions and 9 deletions

View File

@ -148,9 +148,9 @@ namespace osu.Game.Beatmaps
}, token, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
}
public Task<TimedDifficultyAttributes[]> GetTimedDifficultyAttributesAsync(WorkingBeatmap beatmap, Ruleset ruleset, Mod[] mods, CancellationToken token = default)
public Task<List<TimedDifficultyAttributes>> GetTimedDifficultyAttributesAsync(WorkingBeatmap beatmap, Ruleset ruleset, Mod[] mods, CancellationToken token = default)
{
return Task.Factory.StartNew(() => ruleset.CreateDifficultyCalculator(beatmap).CalculateTimed(mods).ToArray(),
return Task.Factory.StartNew(() => ruleset.CreateDifficultyCalculator(beatmap).CalculateTimed(mods),
token,
TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously,
updateScheduler);

View File

@ -58,12 +58,14 @@ namespace osu.Game.Rulesets.Difficulty
return CreateDifficultyAttributes(Beatmap, playableMods, skills, clockRate);
}
public IEnumerable<TimedDifficultyAttributes> CalculateTimed(params Mod[] mods)
public List<TimedDifficultyAttributes> CalculateTimed(params Mod[] mods)
{
preProcess(mods);
var attribs = new List<TimedDifficultyAttributes>();
if (!Beatmap.HitObjects.Any())
yield break;
return attribs;
var skills = CreateSkills(Beatmap, playableMods, clockRate);
var progressiveBeatmap = new ProgressiveCalculationBeatmap(Beatmap);
@ -75,8 +77,10 @@ namespace osu.Game.Rulesets.Difficulty
foreach (var skill in skills)
skill.ProcessInternal(hitObject);
yield return new TimedDifficultyAttributes(hitObject.EndTime, CreateDifficultyAttributes(progressiveBeatmap, playableMods, skills, clockRate));
attribs.Add(new TimedDifficultyAttributes(hitObject.EndTime, CreateDifficultyAttributes(progressiveBeatmap, playableMods, skills, clockRate)));
}
return attribs;
}
/// <summary>

View File

@ -47,7 +47,7 @@ namespace osu.Game.Screens.Play.HUD
private GameplayState gameplayState { get; set; }
[CanBeNull]
private TimedDifficultyAttributes[] timedAttributes;
private List<TimedDifficultyAttributes> timedAttributes;
private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource();
@ -110,14 +110,14 @@ namespace osu.Game.Screens.Play.HUD
[CanBeNull]
private DifficultyAttributes getAttributeAtTime(JudgementResult judgement)
{
if (timedAttributes == null || timedAttributes.Length == 0)
if (timedAttributes == null || timedAttributes.Count == 0)
return null;
int attribIndex = Array.BinarySearch(timedAttributes, 0, timedAttributes.Length, new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
int attribIndex = timedAttributes.BinarySearch(new TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
if (attribIndex < 0)
attribIndex = ~attribIndex - 1;
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Length - 1)].Attributes;
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Count - 1)].Attributes;
}
private void onJudgementReverted(JudgementResult obj) => IsValid = false;