From 45e57a00238c86b1fbc216dbcf2c7d749de86811 Mon Sep 17 00:00:00 2001 From: khoeun03 Date: Thu, 3 Aug 2023 00:24:04 +0900 Subject: [PATCH] Fix timing precision --- Assets/Scripts/BMSParser.cs | 16 ++++++++-------- Assets/Scripts/TimeLine.cs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/BMSParser.cs b/Assets/Scripts/BMSParser.cs index 9447e43..a2bc412 100644 --- a/Assets/Scripts/BMSParser.cs +++ b/Assets/Scripts/BMSParser.cs @@ -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]; @@ -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; @@ -363,7 +363,7 @@ 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; } @@ -371,13 +371,13 @@ public void Parse(string path) { 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); diff --git a/Assets/Scripts/TimeLine.cs b/Assets/Scripts/TimeLine.cs index 167a37c..5ed2bb1 100644 --- a/Assets/Scripts/TimeLine.cs +++ b/Assets/Scripts/TimeLine.cs @@ -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; } } \ No newline at end of file