Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make note rendering based on frames AND song position #3544

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/funkin/Conductor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class Conductor
*/
public var songPosition(default, null):Float = 0;

/**
* The current position in the song in milliseconds, updated every frame.
* `songPosition` doesn't update every frame, meaning things that are based on `songPosition` but update faster than `songPosition` appear to lag.
* An example is note rendering. Using `frameSongPosition` instead of `songPosition` fixes this.
*/
public var frameSongPosition(default, null):Float = 0;

var prevTimestamp:Float = 0;
var prevTime:Float = 0;

Expand Down Expand Up @@ -411,6 +418,7 @@ class Conductor
{
songPos = currentTime;
}
var frameSongPos:Float = frameSongPosition + FlxG.elapsed * 1000;

// Take into account instrumental and file format song offsets.
songPos += applyOffsets ? (combinedOffset) : 0;
Expand All @@ -423,10 +431,12 @@ class Conductor
if (FlxG.sound.music != null && FlxG.sound.music.playing)
{
this.songPosition = Math.min(currentLength, Math.max(0, songPos));
this.frameSongPosition = Math.min(currentLength, Math.max(0, frameSongPos));
}
else
{
this.songPosition = songPos;
this.frameSongPosition = frameSongPos;
}

// Set the song position we are at (for purposes of calculating note positions, etc).
Expand Down Expand Up @@ -488,6 +498,9 @@ class Conductor
// which it doesn't do every frame!
if (prevTime != this.songPosition)
{
// Set the frameSongPosition to the actual songPosition every time it actually changes to prevent desync
frameSongPosition = this.songPosition;

// Update the timestamp for use in-between frames
prevTime = this.songPosition;
prevTimestamp = Std.int(Timer.stamp() * 1000);
Expand Down Expand Up @@ -686,6 +699,7 @@ class Conductor
if (target == null) target = Conductor.instance;

FlxG.watch.addQuick('songPosition', target.songPosition);
FlxG.watch.addQuick('frameSongPosition', target.frameSongPosition);
FlxG.watch.addQuick('bpm', target.bpm);
FlxG.watch.addQuick('currentMeasureTime', target.currentMeasureTime);
FlxG.watch.addQuick('currentBeatTime', target.currentBeatTime);
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/play/notes/Strumline.hx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class Strumline extends FlxSpriteGroup
var vwoosh:Float = 1.0;

return
Constants.PIXELS_PER_MS * (conductorInUse.songPosition - strumTime - Conductor.instance.inputOffset) * scrollSpeed * vwoosh * (Preferences.downscroll ? 1 : -1);
Constants.PIXELS_PER_MS * (conductorInUse.frameSongPosition - strumTime - Conductor.instance.inputOffset) * scrollSpeed * vwoosh * (Preferences.downscroll ? 1 : -1);
}

function updateNotes():Void
Expand Down
Loading