|
7 | 7 | using System.Collections.Generic; |
8 | 8 | using System.Linq; |
9 | 9 | using System.Threading; |
| 10 | +using System.Threading.Tasks; |
10 | 11 | using JetBrains.Annotations; |
11 | 12 | using osu.Framework.Extensions.IEnumerableExtensions; |
12 | 13 | using osu.Framework.Lists; |
@@ -148,6 +149,52 @@ public List<TimedDifficultyAttributes> CalculateTimed([NotNull] IEnumerable<Mod> |
148 | 149 | return attribs; |
149 | 150 | } |
150 | 151 |
|
| 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 | + |
151 | 198 | /// <summary> |
152 | 199 | /// Calculates the difficulty of the beatmap using all mod combinations applicable to the beatmap. |
153 | 200 | /// </summary> |
|
0 commit comments