Refactor to encapsulate strain logic into Skill class

As strains are an implementation detail of the current Skill calculations, it makes sense that strain related logic should be encapsulated within the Skill class.
This commit is contained in:
Samuel Cattini-Schultz
2021-04-03 20:47:39 +11:00
parent eb1e850f99
commit 5b2dcea8a8
7 changed files with 49 additions and 51 deletions

View File

@ -16,11 +16,6 @@ namespace osu.Game.Rulesets.Difficulty
{
public abstract class DifficultyCalculator
{
/// <summary>
/// The length of each strain section.
/// </summary>
protected virtual int SectionLength => 400;
private readonly Ruleset ruleset;
private readonly WorkingBeatmap beatmap;
@ -71,32 +66,14 @@ namespace osu.Game.Rulesets.Difficulty
var difficultyHitObjects = SortObjects(CreateDifficultyHitObjects(beatmap, clockRate)).ToList();
double sectionLength = SectionLength * clockRate;
// The first object doesn't generate a strain, so we begin with an incremented section end
double currentSectionEnd = Math.Ceiling(beatmap.HitObjects.First().StartTime / sectionLength) * sectionLength;
foreach (DifficultyHitObject h in difficultyHitObjects)
foreach (var hitObject in difficultyHitObjects)
{
while (h.BaseObject.StartTime > currentSectionEnd)
foreach (var skill in skills)
{
foreach (Skill s in skills)
{
s.SaveCurrentPeak();
s.StartNewSectionFrom(currentSectionEnd / clockRate);
}
currentSectionEnd += sectionLength;
skill.Process(hitObject);
}
foreach (Skill s in skills)
s.Process(h);
}
// The peak strain will not be saved for the last section in the above loop
foreach (Skill s in skills)
s.SaveCurrentPeak();
return CreateDifficultyAttributes(beatmap, mods, skills, clockRate);
}