Skip to content

Commit

Permalink
Fix timing bug for bmson parser
Browse files Browse the repository at this point in the history
Try to fix stop sequence errors in bms parser
Add handle for stop sequence
  • Loading branch information
JLChnToZ committed Oct 9, 2016
1 parent 9f706b6 commit 3dd9a61
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Assets/Scripts/BMS/BMSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ public partial class BMSManager: MonoBehaviour {
if(OnChangeBPM != null)
OnChangeBPM.Invoke(newBpm);
break;
case BMSEventType.STOP:
bpmBasePoint -= new TimeSpan(bmsEvent.data2);
break;
default:
if(!handledChannels.Contains(bmsEvent.data1)) {
bool shouldPlayWav = true;
Expand Down
9 changes: 6 additions & 3 deletions Assets/Scripts/BMS/Parser/BMSChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,15 @@ public class BMSChart: Chart {
BMSResourceData stopData;
if(!TryGetResourceData(ResourceType.stop, ev.data2, out stopData))
continue;
double stopSeconds = Convert.ToDouble(stopData.additionalData) / bpm * 1.25;
if(stopSeconds <= 0)
continue;
converted.type = BMSEventType.STOP;
stopTimePoint = converted.time;
stopMeasBeat = ev.measure + ev.beat;
double stopBeats = Convert.ToDouble(stopData.additionalData);
converted.data2 = BitConverter.DoubleToInt64Bits(stopBeats);
referenceTimePoint += MeasureBeatToTimeSpan(stopBeats, beatPerMeas, bpm);
TimeSpan stopTime = new TimeSpan((long)Math.Round(stopSeconds * TimeSpan.TicksPerSecond));
converted.data2 = stopTime.Ticks;
referenceTimePoint += stopTime;
break;
case BMSEventType.BMP:
converted.type = BMSEventType.BMP;
Expand Down
36 changes: 17 additions & 19 deletions Assets/Scripts/BMS/Parser/BmsonChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public class BmsonChart: Chart {
referencePoint = ev;
break;
case BMSEventType.STOP:
referencePoint.time = TicksToTime(referencePoint, (int)ev.data2);
referencePoint.time = TicksToTime(referencePoint, ev.ticks + (int)ev.data2);
ev.data2 = (referencePoint.time - ev.time).Ticks;
break;
}
bmev[i] = ev;
Expand Down Expand Up @@ -283,27 +284,24 @@ public class BmsonChart: Chart {
0, -1, TicksComparer.instance
);

BMSEvent lastReferencePoint;
if(index >= 0) {
BMSEvent lastReferencePoint = DefaultReferencePoint;
TimeSpan stopOffset = TimeSpan.Zero;
while(index >= 0) {
lastReferencePoint = bmev[index];
if(lastReferencePoint.type == BMSEventType.STOP) {
if(ticks == lastReferencePoint.ticks)
return lastReferencePoint.time;
bool foundBpmPoint = false;
for(int i = index; i >= 0; i--) {
if(bmev[i].type == BMSEventType.BPM) {
lastReferencePoint.data2 = bmev[i].data2;
foundBpmPoint = true;
break;
}
}
if(!foundBpmPoint)
lastReferencePoint.data2 = BitConverter.DoubleToInt64Bits(initialBPM);
bool found = false;
switch(lastReferencePoint.type) {
case BMSEventType.BPM:
lastReferencePoint.time += stopOffset;
found = true;
break;
case BMSEventType.STOP:
stopOffset += new TimeSpan(lastReferencePoint.data2);
break;
}
} else {
lastReferencePoint = DefaultReferencePoint;
if(found)
break;
index--;
}

return TicksToTime(lastReferencePoint, ticks);
}

Expand Down

0 comments on commit 3dd9a61

Please sign in to comment.