From 1405c86f7a47c4fb43e6dae000e333695bb9ee5a Mon Sep 17 00:00:00 2001 From: sonicfind Date: Tue, 17 Oct 2023 15:59:46 -0500 Subject: [PATCH] Long term fix for vocal overdrive phrases (#99) + prefills the phrase tracking dictionary with the valid types to make TryGetValue-like calls redundant --- .../Loaders/MoonSong/MoonSongLoader.Vocals.cs | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/YARG.Core/Chart/Loaders/MoonSong/MoonSongLoader.Vocals.cs b/YARG.Core/Chart/Loaders/MoonSong/MoonSongLoader.Vocals.cs index 269ddb349..fc5e1c128 100644 --- a/YARG.Core/Chart/Loaders/MoonSong/MoonSongLoader.Vocals.cs +++ b/YARG.Core/Chart/Loaders/MoonSong/MoonSongLoader.Vocals.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -89,28 +89,36 @@ MoonSong.MoonInstrument.Vocals or private List GetVocalsPhrases(MoonChart moonChart, int harmonyPart) { var phrases = new List(); - var currentPhrases = new Dictionary(); + + // Prefill with the valid phrases + var phraseTracker = new Dictionary() + { + { SpecialPhrase.Type.Starpower , null }, + { SpecialPhrase.Type.Versus_Player1 , null }, + { SpecialPhrase.Type.Versus_Player2 , null }, + { SpecialPhrase.Type.Vocals_PercussionPhrase , null }, + }; int moonNoteIndex = 0; int moonTextIndex = 0; - // Load relative to special phrases, not notes - for (int moonPhraseIndex = 0; moonPhraseIndex < moonChart.specialPhrases.Count; moonPhraseIndex++) + for (int moonPhraseIndex = 0; moonPhraseIndex < moonChart.specialPhrases.Count;) { - var moonPhrase = moonChart.specialPhrases[moonPhraseIndex]; - currentPhrases[moonPhrase.type] = moonPhrase; - - if (moonPhrase.type != SpecialPhrase.Type.Vocals_LyricPhrase) continue; + var moonPhrase = moonChart.specialPhrases[moonPhraseIndex++]; + if (moonPhrase.type != SpecialPhrase.Type.Vocals_LyricPhrase) + { + phraseTracker[moonPhrase.type] = moonPhrase; + continue; + } // Ensure any other phrases on the same tick get tracked - moonPhraseIndex++; while (moonPhraseIndex < moonChart.specialPhrases.Count) { var moonPhrase2 = moonChart.specialPhrases[moonPhraseIndex]; if (moonPhrase2.tick > moonPhrase.tick) break; - currentPhrases[moonPhrase2.type] = moonPhrase2; + phraseTracker[moonPhrase2.type] = moonPhrase2; moonPhraseIndex++; } @@ -118,10 +126,11 @@ private List GetVocalsPhrases(MoonChart moonChart, int harmonyPart var notes = new List(); var lyrics = new List(); VocalNote? previousNote = null; + uint endOfPhrase = moonPhrase.tick + moonPhrase.length; while (moonNoteIndex < moonChart.notes.Count) { var moonNote = moonChart.notes[moonNoteIndex]; - if (moonNote.tick >= (moonPhrase.tick + moonPhrase.length)) + if (moonNote.tick >= endOfPhrase) break; moonNoteIndex++; @@ -180,7 +189,7 @@ private List GetVocalsPhrases(MoonChart moonChart, int harmonyPart continue; } - var vocalsPhrase = CreateVocalsPhrase(moonPhrase, currentPhrases, notes, lyrics); + var vocalsPhrase = CreateVocalsPhrase(moonPhrase, phraseTracker, notes, lyrics); phrases.Add(vocalsPhrase); } @@ -219,11 +228,11 @@ private VocalNoteType GetVocalNoteType(MoonNote moonNote) return flags; } - private VocalsPhrase CreateVocalsPhrase(SpecialPhrase moonPhrase, - Dictionary currentPhrases, List notes, List lyrics) + private VocalsPhrase CreateVocalsPhrase(SpecialPhrase moonPhrase, Dictionary phrasetracker, + List notes, List lyrics) { var bounds = GetVocalsPhraseBounds(moonPhrase); - var phraseFlags = GetVocalsPhraseFlags(moonPhrase, currentPhrases); + var phraseFlags = GetVocalsPhraseFlags(moonPhrase, phrasetracker); // Convert to SpecialPhrase into a vocal note phrase var phraseNote = new VocalNote(phraseFlags, bounds.Time, bounds.TimeLength, @@ -242,14 +251,14 @@ private Phrase GetVocalsPhraseBounds(SpecialPhrase moonPhrase) moonPhrase.tick, moonPhrase.length); } - private NoteFlags GetVocalsPhraseFlags(SpecialPhrase moonPhrase, - Dictionary currentPhrases) + private NoteFlags GetVocalsPhraseFlags(SpecialPhrase moonPhrase, Dictionary phrasetracker) { var phraseFlags = NoteFlags.None; - // Star power - if (currentPhrases.TryGetValue(SpecialPhrase.Type.Starpower, out var starPower) - && IsEventInPhrase(moonPhrase, starPower)) + // No need to check the start of the phrase, as entering the function + // already guarantees that condition *if* the below is true + var starPower = phrasetracker[SpecialPhrase.Type.Starpower]; + if (starPower != null && moonPhrase.tick < starPower.tick + starPower.length) { phraseFlags |= NoteFlags.StarPower; }