From b03c8a9cf8cfe8c00d88ed64d488dceac4992378 Mon Sep 17 00:00:00 2001 From: Kade <26305836+Kade-github@users.noreply.github.com> Date: Thu, 19 Sep 2024 00:02:59 -0700 Subject: [PATCH 1/4] Limit the song time to 0 and the songs max length use the new bool to tell if we should start the song add a public static bool to countdown: finished --- source/funkin/Conductor.hx | 10 +++++++--- source/funkin/play/Countdown.hx | 7 +++++++ source/funkin/play/PlayState.hx | 20 ++++++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/source/funkin/Conductor.hx b/source/funkin/Conductor.hx index e73b2860c7..3211f31f56 100644 --- a/source/funkin/Conductor.hx +++ b/source/funkin/Conductor.hx @@ -397,9 +397,12 @@ class Conductor */ public function update(?songPos:Float, applyOffsets:Bool = true, forceDispatch:Bool = false) { + var currentTime:Float = (FlxG.sound.music != null) ? FlxG.sound.music.time : 0.0; + var currentLength:Float = (FlxG.sound.music != null) ? FlxG.sound.music.length : 0.0; + if (songPos == null) { - songPos = (FlxG.sound.music != null) ? FlxG.sound.music.time : 0.0; + songPos = currentTime; } // Take into account instrumental and file format song offsets. @@ -410,7 +413,7 @@ class Conductor var oldStep:Float = this.currentStep; // Set the song position we are at (for purposes of calculating note positions, etc). - this.songPosition = songPos; + this.songPosition = Math.min(currentLength, Math.max(0, songPos)); currentTimeChange = timeChanges[0]; if (this.songPosition > 0.0) @@ -430,7 +433,8 @@ class Conductor else if (currentTimeChange != null && this.songPosition > 0.0) { // roundDecimal prevents representing 8 as 7.9999999 - this.currentStepTime = FlxMath.roundDecimal((currentTimeChange.beatTime * Constants.STEPS_PER_BEAT) + (this.songPosition - currentTimeChange.timeStamp) / stepLengthMs, 6); + this.currentStepTime = FlxMath.roundDecimal((currentTimeChange.beatTime * Constants.STEPS_PER_BEAT) + + (this.songPosition - currentTimeChange.timeStamp) / stepLengthMs, 6); this.currentBeatTime = currentStepTime / Constants.STEPS_PER_BEAT; this.currentMeasureTime = currentStepTime / stepsPerMeasure; this.currentStep = Math.floor(currentStepTime); diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index 643883a43f..c883006a01 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -29,6 +29,11 @@ class Countdown */ public static var soundSuffix:String = ''; + /** + * Whether the countdown has finished. + */ + public static var finished:Bool = false; + /** * Which alternate graphic on countdown to use. * You can set this via script. @@ -53,6 +58,7 @@ class Countdown */ public static function performCountdown():Bool { + finished = false; countdownStep = BEFORE; var cancelled:Bool = propagateCountdownEvent(countdownStep); if (cancelled) @@ -101,6 +107,7 @@ class Countdown if (countdownStep == AFTER) { + finished = true; stopCountdown(); } }, 5); // Before, 3, 2, 1, GO!, After diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 0b2b8846d3..06dd5f95e4 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -915,7 +915,11 @@ class PlayState extends MusicBeatSubState { // Do NOT apply offsets at this point, because they already got applied the previous frame! Conductor.instance.update(Conductor.instance.songPosition + elapsed * 1000, false); - if (Conductor.instance.songPosition >= (startTimestamp)) startSong(); + if (Conductor.instance.songPosition - Conductor.instance.instrumentalOffset >= (startTimestamp) && Countdown.finished) + { + trace("started song at " + Conductor.instance.songPosition); + startSong(); + } } } else @@ -1391,14 +1395,16 @@ class PlayState extends MusicBeatSubState // activeNotes.sort(SortUtil.byStrumtime, FlxSort.DESCENDING); } + var correctSync:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); + if (!startingSong && FlxG.sound.music != null - && (Math.abs(FlxG.sound.music.time - (Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)) > 100 - || Math.abs(vocals.checkSyncError(Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)) > 100)) + && (Math.abs(FlxG.sound.music.time - correctSync) > 100 || Math.abs(vocals.checkSyncError(correctSync)) > 100)) { trace("VOCALS NEED RESYNC"); - if (vocals != null) trace(vocals.checkSyncError(Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)); - trace(FlxG.sound.music.time - (Conductor.instance.songPosition + Conductor.instance.instrumentalOffset)); + if (vocals != null) trace(vocals.checkSyncError(correctSync)); + trace(FlxG.sound.music.time); + trace(correctSync); resyncVocals(); } @@ -1993,7 +1999,9 @@ class PlayState extends MusicBeatSubState // Skip this if the music is paused (GameOver, Pause menu, start-of-song offset, etc.) if (!(FlxG.sound.music?.playing ?? false)) return; - var timeToPlayAt:Float = Conductor.instance.songPosition - Conductor.instance.instrumentalOffset; + + var timeToPlayAt:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); + trace('Resyncing vocals to ${timeToPlayAt}'); FlxG.sound.music.pause(); vocals.pause(); From 4d73e0cc475f7195261cfff3592eb01b9192aac2 Mon Sep 17 00:00:00 2001 From: Kade <26305836+Kade-github@users.noreply.github.com> Date: Thu, 19 Sep 2024 01:20:16 -0700 Subject: [PATCH 2/4] fix some interesting issues with this redundant trace removal --- source/funkin/Conductor.hx | 11 ++++++++++- source/funkin/play/Countdown.hx | 7 ------- source/funkin/play/PlayState.hx | 29 +++++++++++++++++------------ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/source/funkin/Conductor.hx b/source/funkin/Conductor.hx index 3211f31f56..bd7c7196f7 100644 --- a/source/funkin/Conductor.hx +++ b/source/funkin/Conductor.hx @@ -412,8 +412,17 @@ class Conductor var oldBeat:Float = this.currentBeat; var oldStep:Float = this.currentStep; + // If the song is playing, limit the song position to the length of the song or beginning of the song. + if (FlxG.sound.music != null && FlxG.sound.music.playing) + { + this.songPosition = Math.min(currentLength, Math.max(0, songPos)); + } + else + { + this.songPosition = songPos; + } + // Set the song position we are at (for purposes of calculating note positions, etc). - this.songPosition = Math.min(currentLength, Math.max(0, songPos)); currentTimeChange = timeChanges[0]; if (this.songPosition > 0.0) diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index c883006a01..643883a43f 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -29,11 +29,6 @@ class Countdown */ public static var soundSuffix:String = ''; - /** - * Whether the countdown has finished. - */ - public static var finished:Bool = false; - /** * Which alternate graphic on countdown to use. * You can set this via script. @@ -58,7 +53,6 @@ class Countdown */ public static function performCountdown():Bool { - finished = false; countdownStep = BEFORE; var cancelled:Bool = propagateCountdownEvent(countdownStep); if (cancelled) @@ -107,7 +101,6 @@ class Countdown if (countdownStep == AFTER) { - finished = true; stopCountdown(); } }, 5); // Before, 3, 2, 1, GO!, After diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 06dd5f95e4..4e81d3a83c 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -687,7 +687,11 @@ class PlayState extends MusicBeatSubState } Conductor.instance.mapTimeChanges(currentChart.timeChanges); - Conductor.instance.update((Conductor.instance.beatLengthMs * -5) + startTimestamp); + var pre:Float = (Conductor.instance.beatLengthMs * -5) + startTimestamp; + + trace('Attempting to start at ' + pre); + + Conductor.instance.update(pre); // The song is now loaded. We can continue to initialize the play state. initCameras(); @@ -915,7 +919,7 @@ class PlayState extends MusicBeatSubState { // Do NOT apply offsets at this point, because they already got applied the previous frame! Conductor.instance.update(Conductor.instance.songPosition + elapsed * 1000, false); - if (Conductor.instance.songPosition - Conductor.instance.instrumentalOffset >= (startTimestamp) && Countdown.finished) + if (Conductor.instance.songPosition >= (startTimestamp + Conductor.instance.instrumentalOffset)) { trace("started song at " + Conductor.instance.songPosition); startSong(); @@ -1395,17 +1399,18 @@ class PlayState extends MusicBeatSubState // activeNotes.sort(SortUtil.byStrumtime, FlxSort.DESCENDING); } - var correctSync:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); - - if (!startingSong - && FlxG.sound.music != null - && (Math.abs(FlxG.sound.music.time - correctSync) > 100 || Math.abs(vocals.checkSyncError(correctSync)) > 100)) + if (FlxG.sound.music != null) { - trace("VOCALS NEED RESYNC"); - if (vocals != null) trace(vocals.checkSyncError(correctSync)); - trace(FlxG.sound.music.time); - trace(correctSync); - resyncVocals(); + var correctSync:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); + + if (!startingSong && (Math.abs(FlxG.sound.music.time - correctSync) > 100 || Math.abs(vocals.checkSyncError(correctSync)) > 100)) + { + trace("VOCALS NEED RESYNC"); + if (vocals != null) trace(vocals.checkSyncError(correctSync)); + trace(FlxG.sound.music.time); + trace(correctSync); + resyncVocals(); + } } // Only bop camera if zoom level is below 135% From a8aeae4f7fa97d99310a327cc0f218e404662d2c Mon Sep 17 00:00:00 2001 From: Kade <26305836+Kade-github@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:24:02 -0700 Subject: [PATCH 3/4] do not include offset in vocal (they're offset by inst) Fix a tiny little issue with vocal resync @ start --- source/funkin/play/PlayState.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 4e81d3a83c..96bce85e59 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1979,6 +1979,7 @@ class PlayState extends MusicBeatSubState vocals.play(); vocals.volume = 1.0; vocals.pitch = playbackRate; + vocals.time = startTimestamp; resyncVocals(); #if FEATURE_DISCORD_RPC From f9186b67a7df74f81137374f9d0972114fa4b786 Mon Sep 17 00:00:00 2001 From: Kade <26305836+Kade-github@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:00:52 -0700 Subject: [PATCH 4/4] less tolerance --- source/funkin/play/PlayState.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 96bce85e59..e2bff164e6 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1403,7 +1403,7 @@ class PlayState extends MusicBeatSubState { var correctSync:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); - if (!startingSong && (Math.abs(FlxG.sound.music.time - correctSync) > 100 || Math.abs(vocals.checkSyncError(correctSync)) > 100)) + if (!startingSong && (Math.abs(FlxG.sound.music.time - correctSync) > 5 || Math.abs(vocals.checkSyncError(correctSync)) > 5)) { trace("VOCALS NEED RESYNC"); if (vocals != null) trace(vocals.checkSyncError(correctSync));