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.
|
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2022-07-15 19:07:01 +08:00
|
|
|
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
|
2022-07-05 14:41:40 +08:00
|
|
|
{
|
2022-07-14 16:29:23 +08:00
|
|
|
/// <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"/>.
|
2022-07-14 16:29:23 +08:00
|
|
|
/// </summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
public class RepeatingHitPatterns
|
2022-07-05 14:41:40 +08:00
|
|
|
{
|
2022-07-14 16:29:23 +08:00
|
|
|
/// <summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
/// Maximum amount of <see cref="RepeatingHitPatterns"/>s to look back to find a repetition.
|
2022-07-14 16:29:23 +08:00
|
|
|
/// </summary>
|
2022-07-05 14:41:40 +08:00
|
|
|
private const int max_repetition_interval = 16;
|
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
/// <summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
/// The <see cref="AlternatingMonoPattern"/>s that are grouped together within this <see cref="RepeatingHitPatterns"/>.
|
2022-07-14 16:29:23 +08:00
|
|
|
/// </summary>
|
2022-08-19 15:45:43 +08:00
|
|
|
public readonly List<AlternatingMonoPattern> AlternatingMonoPatterns = new List<AlternatingMonoPattern>();
|
2022-07-05 14:41:40 +08:00
|
|
|
|
2022-08-19 16:13:36 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The parent <see cref="TaikoDifficultyHitObject"/> in this <see cref="RepeatingHitPatterns"/>
|
|
|
|
/// </summary>
|
|
|
|
public TaikoDifficultyHitObject FirstHitObject => AlternatingMonoPatterns[0].FirstHitObject;
|
|
|
|
|
2022-07-14 16:29:23 +08:00
|
|
|
/// <summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
/// The previous <see cref="RepeatingHitPatterns"/>. This is used to determine the repetition interval.
|
2022-07-14 16:29:23 +08:00
|
|
|
/// </summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
public readonly RepeatingHitPatterns? Previous;
|
2022-07-05 14:41:40 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
/// How many <see cref="RepeatingHitPatterns"/> between the current and previous identical <see cref="RepeatingHitPatterns"/>.
|
2022-07-05 14:41:40 +08:00
|
|
|
/// 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)
|
2022-08-15 20:30:40 +08:00
|
|
|
{
|
|
|
|
Previous = previous;
|
|
|
|
}
|
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
/// <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.
|
2022-07-05 14:41:40 +08:00
|
|
|
/// </summary>
|
2022-08-19 15:31:03 +08:00
|
|
|
private bool isRepetitionOf(RepeatingHitPatterns other)
|
2022-07-05 14:41:40 +08:00
|
|
|
{
|
2022-08-19 15:45:43 +08:00
|
|
|
if (AlternatingMonoPatterns.Count != other.AlternatingMonoPatterns.Count) return false;
|
2022-07-05 14:41:40 +08:00
|
|
|
|
2022-08-19 15:45:43 +08:00
|
|
|
for (int i = 0; i < Math.Min(AlternatingMonoPatterns.Count, 2); i++)
|
2022-07-05 14:41:40 +08:00
|
|
|
{
|
2022-08-19 15:45:43 +08:00
|
|
|
if (!AlternatingMonoPatterns[i].HasIdenticalMonoLength(other.AlternatingMonoPatterns[i])) return false;
|
2022-07-05 14:41:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2022-07-05 14:41:40 +08:00
|
|
|
/// </summary>
|
|
|
|
public void FindRepetitionInterval()
|
|
|
|
{
|
2022-08-18 14:12:03 +08:00
|
|
|
if (Previous == null)
|
2022-07-05 14:41:40 +08:00
|
|
|
{
|
|
|
|
RepetitionInterval = max_repetition_interval + 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-19 15:31:03 +08:00
|
|
|
RepeatingHitPatterns? other = Previous;
|
2022-08-18 14:12:03 +08:00
|
|
|
int interval = 1;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
while (interval < max_repetition_interval)
|
|
|
|
{
|
2022-07-15 19:07:01 +08:00
|
|
|
if (isRepetitionOf(other))
|
2022-07-05 14:41:40 +08:00
|
|
|
{
|
|
|
|
RepetitionInterval = Math.Min(interval, max_repetition_interval);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
other = other.Previous;
|
|
|
|
if (other == null) break;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
++interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
RepetitionInterval = max_repetition_interval + 1;
|
|
|
|
}
|
|
|
|
}
|
2022-07-15 19:07:01 +08:00
|
|
|
}
|