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

Fix timing precision #31

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
16 changes: 8 additions & 8 deletions Assets/Scripts/BMSParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void Parse(string path)
br?.Close();
var lastMeasure = measures.Keys.Max();

long timePassed = 0;
double timePassed = 0;

var currentBpm = chart.Bpm;
var lastNote = new Note[TempKey];
Expand Down Expand Up @@ -346,15 +346,15 @@ public void Parse(string path)


var lastPosition = 0.0;
measure.Timing = timePassed;
measure.Timing = (long)timePassed;
chart.Measures.Add(measure);
foreach (var (position, timeline) in timelines)
{

// Debug.Log($"measure: {i}, position: {position}, lastPosition: {lastPosition} bpm: {bpm} scale: {measure.scale} interval: {240 * 1000 * 1000 * (position - lastPosition) * measure.scale / bpm}");
var interval = 240 * 1000 * 1000 * (position - lastPosition) * measure.Scale / currentBpm;
timePassed += (long)interval;
timeline.Timing = timePassed;
double interval = 240 * 1000 * 1000 * (position - lastPosition) * measure.Scale / currentBpm;
timePassed += interval;
timeline.Timing = (long)timePassed;
if (timeline.BpmChange) currentBpm = timeline.Bpm;
else timeline.Bpm = currentBpm;

Expand All @@ -363,21 +363,21 @@ public void Parse(string path)
measure.Timelines.Add(timeline);
timePassed += timeline.GetStopDuration();
lastPosition = position;
if (timeline.Notes.Count > 0) chart.PlayLength = timePassed;
if (timeline.Notes.Count > 0) chart.PlayLength = (long)timePassed;
lastPosition = position;
}

if (measure.Timelines.Count == 0)
{
var timeline = new TimeLine(TempKey)
{
Timing = timePassed,
Timing = (long)timePassed,
Bpm = currentBpm
};
measure.Timelines.Add(timeline);
}

chart.TotalLength = timePassed;
chart.TotalLength = (long)timePassed;

timePassed += (long)(240 * 1000 * 1000 * (1 - lastPosition) * measure.Scale / currentBpm);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/TimeLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public TimeLine AddBackgroundNote(Note note)
}


public long GetStopDuration()
public double GetStopDuration()
{
return (long)(240 * 1000 * 1000 / 192 * StopLength / Bpm);
return 240 * 1000 * 1000 / 192 * StopLength / Bpm;
}
}