1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 07:32:54 +08:00
osu-lazer/osu.Game/Rulesets/Difficulty/Skills/Skill.cs

65 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Utils;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Rulesets.Difficulty.Skills
{
/// <summary>
/// A bare minimal abstract skill for fully custom skill implementations.
/// </summary>
/// <remarks>
/// This class should be considered a "processing" class and not persisted, as it keeps references to
/// gameplay objects after processing is run (see <see cref="Previous"/>).
/// </remarks>
public abstract class Skill
{
/// <summary>
/// <see cref="DifficultyHitObject"/>s that were processed previously. They can affect the strain values of the following objects.
/// </summary>
protected readonly ReverseQueue<DifficultyHitObject> Previous;
/// <summary>
2021-04-06 15:39:02 +08:00
/// Number of previous <see cref="DifficultyHitObject"/>s to keep inside the <see cref="Previous"/> queue.
/// </summary>
2021-04-06 15:39:02 +08:00
protected virtual int HistoryLength => 1;
/// <summary>
/// Mods for use in skill calculations.
/// </summary>
protected IReadOnlyList<Mod> Mods => mods;
private readonly Mod[] mods;
protected Skill(Mod[] mods)
{
this.mods = mods;
2021-04-06 15:39:02 +08:00
Previous = new ReverseQueue<DifficultyHitObject>(HistoryLength + 1);
}
internal void ProcessInternal(DifficultyHitObject current)
{
2021-04-06 15:39:02 +08:00
while (Previous.Count > HistoryLength)
Previous.Dequeue();
2021-04-06 15:39:02 +08:00
Process(current);
2021-04-06 15:39:02 +08:00
Previous.Enqueue(current);
}
/// <summary>
/// Process a <see cref="DifficultyHitObject"/>.
/// </summary>
/// <param name="current">The <see cref="DifficultyHitObject"/> to process.</param>
protected abstract void Process(DifficultyHitObject current);
/// <summary>
/// Returns the calculated difficulty value representing all <see cref="DifficultyHitObject"/>s that have been processed up to this point.
/// </summary>
public abstract double DifficultyValue();
}
}