1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 08:33:20 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

176 lines
6.4 KiB
C#
Raw Normal View History

2020-06-08 15:30:26 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-06-08 15:30:26 +08:00
using System;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
2020-08-19 01:13:18 +08:00
using osu.Game.Rulesets.Difficulty.Utils;
using osu.Game.Rulesets.Mods;
2020-06-08 15:30:26 +08:00
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Objects;
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
{
/// <summary>
/// Calculates the rhythm coefficient of taiko difficulty.
/// </summary>
public class Rhythm : StrainDecaySkill
2020-06-08 15:30:26 +08:00
{
protected override double SkillMultiplier => 10;
protected override double StrainDecayBase => 0;
2020-08-22 23:51:35 +08:00
/// <summary>
/// The note-based decay for rhythm strain.
/// </summary>
/// <remarks>
/// <see cref="StrainDecayBase"/> is not used here, as it's time- and not note-based.
/// </remarks>
2020-06-08 15:30:26 +08:00
private const double strain_decay = 0.96;
/// <summary>
/// Maximum number of entries in <see cref="rhythmHistory"/>.
/// </summary>
2020-08-22 23:51:35 +08:00
private const int rhythm_history_max_length = 8;
2020-06-08 15:30:26 +08:00
/// <summary>
/// Contains the last <see cref="rhythm_history_max_length"/> changes in note sequence rhythms.
/// </summary>
2020-08-19 01:13:18 +08:00
private readonly LimitedCapacityQueue<TaikoDifficultyHitObject> rhythmHistory = new LimitedCapacityQueue<TaikoDifficultyHitObject>(rhythm_history_max_length);
2020-06-08 15:30:26 +08:00
/// <summary>
/// Contains the rolling rhythm strain.
/// Used to apply per-note decay.
/// </summary>
2020-08-22 23:51:35 +08:00
private double currentStrain;
/// <summary>
/// Number of notes since the last rhythm change has taken place.
/// </summary>
2020-06-08 15:30:26 +08:00
private int notesSinceRhythmChange;
public Rhythm(Mod[] mods)
: base(mods)
{
}
2020-08-22 23:51:35 +08:00
protected override double StrainValueOf(DifficultyHitObject current)
2020-06-08 15:30:26 +08:00
{
// drum rolls and swells are exempt.
2020-08-22 23:51:35 +08:00
if (!(current.BaseObject is Hit))
{
resetRhythmAndStrain();
2020-08-22 23:51:35 +08:00
return 0.0;
}
currentStrain *= strain_decay;
TaikoDifficultyHitObject hitObject = (TaikoDifficultyHitObject)current;
2020-08-22 23:51:35 +08:00
notesSinceRhythmChange += 1;
// rhythm difficulty zero (due to rhythm not changing) => no rhythm strain.
if (hitObject.Rhythm.Difficulty == 0.0)
2020-08-22 23:51:35 +08:00
{
return 0.0;
}
double objectStrain = hitObject.Rhythm.Difficulty;
2020-08-22 23:51:35 +08:00
objectStrain *= repetitionPenalties(hitObject);
2020-08-22 23:51:35 +08:00
objectStrain *= patternLengthPenalty(notesSinceRhythmChange);
objectStrain *= speedPenalty(hitObject.DeltaTime);
2020-08-22 23:51:35 +08:00
// careful - needs to be done here since calls above read this value
2020-08-22 23:51:35 +08:00
notesSinceRhythmChange = 0;
currentStrain += objectStrain;
return currentStrain;
2020-06-08 15:30:26 +08:00
}
/// <summary>
/// Returns a penalty to apply to the current hit object caused by repeating rhythm changes.
/// </summary>
/// <remarks>
/// Repetitions of more recent patterns are associated with a higher penalty.
/// </remarks>
/// <param name="hitObject">The current hit object being considered.</param>
private double repetitionPenalties(TaikoDifficultyHitObject hitObject)
2020-06-08 15:30:26 +08:00
{
double penalty = 1;
rhythmHistory.Enqueue(hitObject);
2020-06-08 15:30:26 +08:00
for (int mostRecentPatternsToCompare = 2; mostRecentPatternsToCompare <= rhythm_history_max_length / 2; mostRecentPatternsToCompare++)
2020-06-08 15:30:26 +08:00
{
for (int start = rhythmHistory.Count - mostRecentPatternsToCompare - 1; start >= 0; start--)
2020-06-08 15:30:26 +08:00
{
if (!samePattern(start, mostRecentPatternsToCompare))
continue;
2020-06-08 15:30:26 +08:00
2022-06-09 17:49:11 +08:00
int notesSince = hitObject.Index - rhythmHistory[start].Index;
penalty *= repetitionPenalty(notesSince);
break;
2020-06-08 15:30:26 +08:00
}
}
return penalty;
}
/// <summary>
/// Determines whether the rhythm change pattern starting at <paramref name="start"/> is a repeat of any of the
/// <paramref name="mostRecentPatternsToCompare"/>.
/// </summary>
private bool samePattern(int start, int mostRecentPatternsToCompare)
{
for (int i = 0; i < mostRecentPatternsToCompare; i++)
{
if (rhythmHistory[start + i].Rhythm != rhythmHistory[rhythmHistory.Count - mostRecentPatternsToCompare + i].Rhythm)
return false;
}
return true;
}
/// <summary>
/// Calculates a single rhythm repetition penalty.
/// </summary>
/// <param name="notesSince">Number of notes since the last repetition of a rhythm change.</param>
private static double repetitionPenalty(int notesSince) => Math.Min(1.0, 0.032 * notesSince);
/// <summary>
/// Calculates a penalty based on the number of notes since the last rhythm change.
/// Both rare and frequent rhythm changes are penalised.
/// </summary>
/// <param name="patternLength">Number of notes since the last rhythm change.</param>
private static double patternLengthPenalty(int patternLength)
2020-06-08 15:30:26 +08:00
{
double shortPatternPenalty = Math.Min(0.15 * patternLength, 1.0);
2020-08-19 01:50:16 +08:00
double longPatternPenalty = Math.Clamp(2.5 - 0.15 * patternLength, 0.0, 1.0);
2020-06-08 15:30:26 +08:00
return Math.Min(shortPatternPenalty, longPatternPenalty);
}
/// <summary>
/// Calculates a penalty for objects that do not require alternating hands.
/// </summary>
/// <param name="deltaTime">Time (in milliseconds) since the last hit object.</param>
private double speedPenalty(double deltaTime)
2020-06-08 15:30:26 +08:00
{
if (deltaTime < 80) return 1;
if (deltaTime < 210) return Math.Max(0, 1.4 - 0.005 * deltaTime);
2020-06-08 15:30:26 +08:00
resetRhythmAndStrain();
2020-06-08 15:30:26 +08:00
return 0.0;
}
/// <summary>
/// Resets the rolling strain value and <see cref="notesSinceRhythmChange"/> counter.
/// </summary>
private void resetRhythmAndStrain()
{
currentStrain = 0.0;
notesSinceRhythmChange = 0;
}
2020-06-08 15:30:26 +08:00
}
}