Skip to content

Commit

Permalink
fix some interesting issues with this
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed Sep 19, 2024
1 parent e5dbe38 commit ba0d2f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
11 changes: 10 additions & 1 deletion source/funkin/Conductor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions source/funkin/play/Countdown.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -58,7 +53,6 @@ class Countdown
*/
public static function performCountdown():Bool
{
finished = false;
countdownStep = BEFORE;
var cancelled:Bool = propagateCountdownEvent(countdownStep);
if (cancelled)
Expand Down Expand Up @@ -107,7 +101,6 @@ class Countdown

if (countdownStep == AFTER)
{
finished = true;
stopCountdown();
}
}, 5); // Before, 3, 2, 1, GO!, After
Expand Down
31 changes: 19 additions & 12 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,13 @@ 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);

trace('Pre-start song at ' + Conductor.instance.songPosition);

// The song is now loaded. We can continue to initialize the play state.
initCameras();
Expand Down Expand Up @@ -915,7 +921,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();
Expand Down Expand Up @@ -1395,17 +1401,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%
Expand Down

0 comments on commit ba0d2f5

Please sign in to comment.