Merge remote-tracking branch 'origin/master' into new-diffcalc-mania

# Conflicts:
#	osu.Game.Rulesets.Mania/Difficulty/ManiaLegacyDifficultyCalculator.cs
This commit is contained in:
smoogipoo
2019-02-19 16:30:05 +09:00
15 changed files with 298 additions and 76 deletions

View File

@ -7,13 +7,12 @@ namespace osu.Game.Rulesets.Difficulty
{
public class DifficultyAttributes
{
public readonly Mod[] Mods;
public Mod[] Mods;
public double StarRating;
public DifficultyAttributes(Mod[] mods)
public DifficultyAttributes()
{
Mods = mods;
}
public DifficultyAttributes(Mod[] mods, double starRating)

View File

@ -23,17 +23,18 @@ namespace osu.Game.Rulesets.Difficulty
{
}
protected override DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods, double timeRate)
protected override DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods, double clockRate)
{
var attributes = CreateDifficultyAttributes(mods);
var attributes = CreateDifficultyAttributes();
attributes.Mods = mods;
if (!beatmap.HitObjects.Any())
return attributes;
var difficultyHitObjects = CreateDifficultyHitObjects(beatmap, timeRate).OrderBy(h => h.BaseObject.StartTime).ToList();
var difficultyHitObjects = CreateDifficultyHitObjects(beatmap, clockRate).OrderBy(h => h.BaseObject.StartTime).ToList();
var skills = CreateSkills();
double sectionLength = SectionLength * timeRate;
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;
@ -59,7 +60,7 @@ namespace osu.Game.Rulesets.Difficulty
foreach (Skill s in skills)
s.SaveCurrentPeak();
PopulateAttributes(attributes, beatmap, skills, timeRate);
PopulateAttributes(attributes, beatmap, skills, clockRate);
return attributes;
}
@ -112,16 +113,16 @@ namespace osu.Game.Rulesets.Difficulty
/// <param name="attributes">The <see cref="DifficultyAttributes"/> to populate with information about the difficulty of <paramref name="beatmap"/>.</param>
/// <param name="beatmap">The <see cref="IBeatmap"/> whose difficulty was processed.</param>
/// <param name="skills">The skills which processed the difficulty.</param>
/// <param name="timeRate">The rate of time in <paramref name="beatmap"/>.</param>
protected abstract void PopulateAttributes(DifficultyAttributes attributes, IBeatmap beatmap, Skill[] skills, double timeRate);
/// <param name="clockRate">The rate at which the gameplay clock is run at.</param>
protected abstract void PopulateAttributes(DifficultyAttributes attributes, IBeatmap beatmap, Skill[] skills, double clockRate);
/// <summary>
/// Enumerates <see cref="DifficultyHitObject"/>s to be processed from <see cref="HitObject"/>s in the <see cref="IBeatmap"/>.
/// </summary>
/// <param name="beatmap">The <see cref="IBeatmap"/> providing the <see cref="HitObject"/>s to enumerate.</param>
/// <param name="timeRate">The rate of time in <paramref name="beatmap"/>.</param>
/// <param name="clockRate">The rate at which the gameplay clock is run at.</param>
/// <returns>The enumerated <see cref="DifficultyHitObject"/>s.</returns>
protected abstract IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double timeRate);
protected abstract IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate);
/// <summary>
/// Creates the <see cref="Skill"/>s to calculate the difficulty of <see cref="DifficultyHitObject"/>s.
@ -132,8 +133,7 @@ namespace osu.Game.Rulesets.Difficulty
/// <summary>
/// Creates an empty <see cref="DifficultyAttributes"/>.
/// </summary>
/// <param name="mods">The <see cref="Mod"/>s which difficulty is being processed with.</param>
/// <returns>The empty <see cref="DifficultyAttributes"/>.</returns>
protected abstract DifficultyAttributes CreateDifficultyAttributes(Mod[] mods);
protected abstract DifficultyAttributes CreateDifficultyAttributes();
}
}

View File

@ -100,8 +100,8 @@ namespace osu.Game.Rulesets.Difficulty
/// </summary>
/// <param name="beatmap">The <see cref="IBeatmap"/> to compute the difficulty for.</param>
/// <param name="mods">The <see cref="Mod"/>s that should be applied.</param>
/// <param name="timeRate">The rate of time in <paramref name="beatmap"/>.</param>
/// <param name="clockRate">The rate at which the gameplay clock is run at.</param>
/// <returns>A structure containing the difficulty attributes.</returns>
protected abstract DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods, double timeRate);
protected abstract DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods, double clockRate);
}
}

View File

@ -5,28 +5,37 @@ using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Difficulty.Preprocessing
{
/// <summary>
/// Wraps a <see cref="HitObject"/> and provides additional information to be used for difficulty calculation.
/// </summary>
public class DifficultyHitObject
{
/// <summary>
/// Milliseconds elapsed since the <see cref="HitObject.StartTime"/> of the previous <see cref="DifficultyHitObject"/>.
/// </summary>
public double DeltaTime { get; private set; }
/// <summary>
/// The <see cref="HitObject"/> this <see cref="DifficultyHitObject"/> refers to.
/// The <see cref="HitObject"/> this <see cref="DifficultyHitObject"/> wraps.
/// </summary>
public readonly HitObject BaseObject;
/// <summary>
/// The previous <see cref="HitObject"/> to <see cref="BaseObject"/>.
/// The last <see cref="HitObject"/> which occurs before <see cref="BaseObject"/>.
/// </summary>
public readonly HitObject LastObject;
public DifficultyHitObject(HitObject hitObject, HitObject lastObject, double timeRate)
/// <summary>
/// Amount of time elapsed between <see cref="BaseObject"/> and <see cref="LastObject"/>.
/// </summary>
public readonly double DeltaTime;
/// <summary>
/// Creates a new <see cref="DifficultyHitObject"/>.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> which this <see cref="DifficultyHitObject"/> wraps.</param>
/// <param name="lastObject">The last <see cref="HitObject"/> which occurs before <paramref name="hitObject"/> in the beatmap.</param>
/// <param name="clockRate">The rate at which the gameplay clock is run at.</param>
public DifficultyHitObject(HitObject hitObject, HitObject lastObject, double clockRate)
{
BaseObject = hitObject;
LastObject = lastObject;
DeltaTime = (hitObject.StartTime - lastObject.StartTime) / timeRate;
DeltaTime = (hitObject.StartTime - lastObject.StartTime) / clockRate;
}
}
}

View File

@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Difficulty.Skills
/// <summary>
/// <see cref="DifficultyHitObject"/>s that were processed previously. They can affect the strain values of the following objects.
/// </summary>
protected readonly History<DifficultyHitObject> Previous = new History<DifficultyHitObject>(2); // Contained objects not used yet
protected readonly LimitedCapacityStack<DifficultyHitObject> Previous = new LimitedCapacityStack<DifficultyHitObject>(2); // Contained objects not used yet
private double currentStrain = 1; // We keep track of the strain level at all times throughout the beatmap.
private double currentSectionPeak = 1; // We also keep track of the peak strain level in the current section.

View File

@ -8,11 +8,13 @@ using System.Collections.Generic;
namespace osu.Game.Rulesets.Difficulty.Utils
{
/// <summary>
/// An indexed stack with Push() only, which disposes items at the bottom after the capacity is full.
/// Indexing starts at the top of the stack.
/// An indexed stack with limited depth. Indexing starts at the top of the stack.
/// </summary>
public class History<T> : IEnumerable<T>
public class LimitedCapacityStack<T> : IEnumerable<T>
{
/// <summary>
/// The number of elements in the stack.
/// </summary>
public int Count { get; private set; }
private readonly T[] array;
@ -20,10 +22,10 @@ namespace osu.Game.Rulesets.Difficulty.Utils
private int marker; // Marks the position of the most recently added item.
/// <summary>
/// Initializes a new instance of the History class that is empty and has the specified capacity.
/// Constructs a new <see cref="LimitedCapacityStack{T}"/>.
/// </summary>
/// <param name="capacity">The number of items the History can hold.</param>
public History(int capacity)
/// <param name="capacity">The number of items the stack can hold.</param>
public LimitedCapacityStack(int capacity)
{
if (capacity < 0)
throw new ArgumentOutOfRangeException();
@ -34,8 +36,9 @@ namespace osu.Game.Rulesets.Difficulty.Utils
}
/// <summary>
/// The most recently added item is returned at index 0.
/// Retrieves the item at an index in the stack.
/// </summary>
/// <param name="i">The index of the item to retrieve. The top of the stack is returned at index 0.</param>
public T this[int i]
{
get
@ -52,11 +55,12 @@ namespace osu.Game.Rulesets.Difficulty.Utils
}
/// <summary>
/// Adds the item as the most recent one in the history.
/// The oldest item is disposed if the history is full.
/// Pushes an item to this <see cref="LimitedCapacityStack{T}"/>.
/// </summary>
public void Push(T item) // Overwrite the oldest item instead of shifting every item by one with every addition.
/// <param name="item">The item to push.</param>
public void Push(T item)
{
// Overwrite the oldest item instead of shifting every item by one with every addition.
if (marker == 0)
marker = capacity - 1;
else

View File

@ -22,7 +22,8 @@ namespace osu.Game.Rulesets
{
AppDomain.CurrentDomain.AssemblyResolve += currentDomain_AssemblyResolve;
foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, $"{ruleset_library_prefix}.*.dll"))
foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, $"{ruleset_library_prefix}.*.dll")
.Where(f => !Path.GetFileName(f).Contains("Tests")))
loadRulesetFromFile(file);
}
@ -124,7 +125,7 @@ namespace osu.Game.Rulesets
}
catch (Exception e)
{
Logger.Error(e, "Failed to load ruleset");
Logger.Error(e, $"Failed to load ruleset {filename}");
}
}
}