From ce0e5cf9a168ce86b5ea176a4767d4929aa6f211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 18 Aug 2020 19:47:36 +0200 Subject: [PATCH] Slightly optimise and de-branch rhythm pattern recognition --- .../Difficulty/Skills/Rhythm.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs b/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs index 483e94cd70..4c06deb5c0 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/Skills/Rhythm.cs @@ -38,28 +38,29 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills { for (int start = rhythmHistory.Count - l - 1; start >= 0; start--) { - bool samePattern = true; + if (!samePattern(start, l)) + continue; - for (int i = 0; i < l; i++) - { - if (rhythmHistory[start + i].Rhythm != rhythmHistory[rhythmHistory.Count - l + i].Rhythm) - { - samePattern = false; - } - } - - if (samePattern) // Repetition found! - { - int notesSince = hitobject.ObjectIndex - rhythmHistory[start].ObjectIndex; - penalty *= repetitionPenalty(notesSince); - break; - } + int notesSince = hitobject.ObjectIndex - rhythmHistory[start].ObjectIndex; + penalty *= repetitionPenalty(notesSince); + break; } } return penalty; } + private bool samePattern(int start, int l) + { + for (int i = 0; i < l; i++) + { + if (rhythmHistory[start + i].Rhythm != rhythmHistory[rhythmHistory.Count - l + i].Rhythm) + return false; + } + + return true; + } + private double patternLengthPenalty(int patternLength) { double shortPatternPenalty = Math.Min(0.15 * patternLength, 1.0);