1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-19 02:13:08 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Difficulty/Preprocessing/Colour/Data/RepeatingHitPatterns.cs

95 lines
3.7 KiB
C#
Raw Normal View History

2022-07-15 19:07:01 +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.
using System;
using System.Collections.Generic;
2022-07-15 19:07:01 +08:00
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
{
/// <summary>
2022-08-19 15:31:03 +08:00
/// Encodes a list of <see cref="AlternatingMonoPattern"/>s, grouped together by back and forth repetition of the same
/// <see cref="AlternatingMonoPattern"/>. Also stores the repetition interval between this and the previous <see cref="RepeatingHitPatterns"/>.
/// </summary>
2022-08-19 15:31:03 +08:00
public class RepeatingHitPatterns
{
/// <summary>
2022-08-19 15:31:03 +08:00
/// Maximum amount of <see cref="RepeatingHitPatterns"/>s to look back to find a repetition.
/// </summary>
private const int max_repetition_interval = 16;
/// <summary>
2022-08-19 15:31:03 +08:00
/// The <see cref="AlternatingMonoPattern"/>s that are grouped together within this <see cref="RepeatingHitPatterns"/>.
/// </summary>
2022-08-19 15:45:43 +08:00
public readonly List<AlternatingMonoPattern> AlternatingMonoPatterns = new List<AlternatingMonoPattern>();
/// <summary>
/// The first <see cref="TaikoDifficultyHitObject"/> in this <see cref="RepeatingHitPatterns"/>
/// </summary>
public TaikoDifficultyHitObject FirstHitObject => AlternatingMonoPatterns[0].FirstHitObject;
/// <summary>
2022-08-19 15:31:03 +08:00
/// The previous <see cref="RepeatingHitPatterns"/>. This is used to determine the repetition interval.
/// </summary>
2022-08-19 15:31:03 +08:00
public readonly RepeatingHitPatterns? Previous;
/// <summary>
2022-08-19 15:31:03 +08:00
/// How many <see cref="RepeatingHitPatterns"/> between the current and previous identical <see cref="RepeatingHitPatterns"/>.
/// If no repetition is found this will have a value of <see cref="max_repetition_interval"/> + 1.
/// </summary>
public int RepetitionInterval { get; private set; } = max_repetition_interval + 1;
2022-08-19 15:31:03 +08:00
public RepeatingHitPatterns(RepeatingHitPatterns? previous)
{
Previous = previous;
}
/// <summary>
2022-08-19 15:45:43 +08:00
/// Returns true if other is considered a repetition of this pattern. This is true if other's first two payloads
2022-07-20 21:33:38 +08:00
/// have identical mono lengths.
/// </summary>
2022-08-19 15:31:03 +08:00
private bool isRepetitionOf(RepeatingHitPatterns other)
{
2022-08-19 15:45:43 +08:00
if (AlternatingMonoPatterns.Count != other.AlternatingMonoPatterns.Count) return false;
2022-08-19 15:45:43 +08:00
for (int i = 0; i < Math.Min(AlternatingMonoPatterns.Count, 2); i++)
{
2022-08-19 15:45:43 +08:00
if (!AlternatingMonoPatterns[i].HasIdenticalMonoLength(other.AlternatingMonoPatterns[i])) return false;
}
return true;
}
/// <summary>
2022-08-19 15:45:43 +08:00
/// Finds the closest previous <see cref="RepeatingHitPatterns"/> that has the identical <see cref="AlternatingMonoPatterns"/>.
/// Interval is defined as the amount of <see cref="RepeatingHitPatterns"/> chunks between the current and repeated patterns.
/// </summary>
public void FindRepetitionInterval()
{
if (Previous == null)
{
RepetitionInterval = max_repetition_interval + 1;
return;
}
2022-08-19 15:31:03 +08:00
RepeatingHitPatterns? other = Previous;
int interval = 1;
2022-07-15 19:07:01 +08:00
while (interval < max_repetition_interval)
{
2022-07-15 19:07:01 +08:00
if (isRepetitionOf(other))
{
RepetitionInterval = Math.Min(interval, max_repetition_interval);
return;
}
other = other.Previous;
if (other == null) break;
2022-07-15 19:07:01 +08:00
++interval;
}
RepetitionInterval = max_repetition_interval + 1;
}
}
2022-07-15 19:07:01 +08:00
}