Skip to content

Commit 07b866a

Browse files
committed
Add CalculateTimedLazy, allowing lazy timed difficulty calculation
1 parent 14243b8 commit 07b866a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using System.Threading;
10+
using System.Threading.Tasks;
1011
using JetBrains.Annotations;
1112
using osu.Framework.Extensions.IEnumerableExtensions;
1213
using osu.Framework.Lists;
@@ -148,6 +149,52 @@ public List<TimedDifficultyAttributes> CalculateTimed([NotNull] IEnumerable<Mod>
148149
return attribs;
149150
}
150151

152+
/// <summary>
153+
/// Calculates the difficulty of the beatmap using a specific mod combination and returns enumerable <see cref="TimedDifficultyAttributes"/> representing the difficulty at every relevant time value in the beatmap.
154+
/// </summary>
155+
/// <remarks>
156+
/// The returned task represents the operations related to the initialization the difficulty calculation (pre-processing).<br />
157+
/// </remarks>
158+
/// <param name="mods">The mods that should be applied to the beatmap.</param>
159+
/// <param name="cancellationToken">The cancellation token for pre-processing.</param>
160+
/// <returns>The enumerable <see cref="TimedDifficultyAttributes"/>.</returns>
161+
public Task<IEnumerable<TimedDifficultyAttributes>> CalculateTimedLazy([NotNull] IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
162+
{
163+
cancellationToken.ThrowIfCancellationRequested();
164+
preProcess(mods, cancellationToken);
165+
166+
if (!Beatmap.HitObjects.Any())
167+
return Task.FromResult(Enumerable.Empty<TimedDifficultyAttributes>());
168+
169+
var skills = CreateSkills(Beatmap, playableMods, clockRate);
170+
var progressiveBeatmap = new ProgressiveCalculationBeatmap(Beatmap);
171+
var difficultyObjects = getDifficultyHitObjects().ToArray();
172+
173+
return Task.FromResult(enumerate());
174+
175+
IEnumerable<TimedDifficultyAttributes> enumerate()
176+
{
177+
int currentIndex = 0;
178+
179+
foreach (var obj in Beatmap.HitObjects)
180+
{
181+
progressiveBeatmap.HitObjects.Add(obj);
182+
183+
while (currentIndex < difficultyObjects.Length && difficultyObjects[currentIndex].BaseObject.GetEndTime() <= obj.GetEndTime())
184+
{
185+
foreach (var skill in skills)
186+
{
187+
skill.Process(difficultyObjects[currentIndex]);
188+
}
189+
190+
currentIndex++;
191+
}
192+
193+
yield return new TimedDifficultyAttributes(obj.GetEndTime(), CreateDifficultyAttributes(progressiveBeatmap, playableMods, skills, clockRate));
194+
}
195+
}
196+
}
197+
151198
/// <summary>
152199
/// Calculates the difficulty of the beatmap using all mod combinations applicable to the beatmap.
153200
/// </summary>

0 commit comments

Comments
 (0)