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 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
slightly different way of doing it
based on minecraft's tickDelta variable they use for smoother rendering at high framerates
  • Loading branch information
KutikiPlayz committed Nov 27, 2024
commit 732a74334061a9234d8743effac1f1183173ca6d
14 changes: 4 additions & 10 deletions source/funkin/Conductor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ 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.
* The offset between frame time and music time.
* Used in `getTimeWithDelta()` to get a more accurate music time when on higher framerates.
*/
public var frameSongPosition(default, null):Float = 0;
var songPositionDelta(default, null):Float = 0;

var prevTimestamp:Float = 0;
var prevTime:Float = 0;
Expand Down Expand Up @@ -418,7 +417,6 @@ 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 @@ -431,12 +429,10 @@ 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 @@ -500,8 +496,7 @@ 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;
this.songPositionDelta = 0;

// Update the timestamp for use in-between frames
prevTime = this.songPosition;
Expand Down Expand Up @@ -710,7 +705,6 @@ 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.frameSongPosition - strumTime - Conductor.instance.inputOffset) * scrollSpeed * vwoosh * (Preferences.downscroll ? 1 : -1);
Constants.PIXELS_PER_MS * (conductorInUse.getTimeWithDelta() - strumTime - Conductor.instance.inputOffset) * scrollSpeed * vwoosh * (Preferences.downscroll ? 1 : -1);
}

function updateNotes():Void
Expand Down