mirror of https://github.com/ppy/osu
Cleanup logic
This commit is contained in:
parent
f4c7a02a6f
commit
793b760ff2
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
@ -12,8 +12,8 @@ namespace osu.Game.Graphics.Containers
|
||||||
public class BeatSyncedContainer : Container
|
public class BeatSyncedContainer : Container
|
||||||
{
|
{
|
||||||
private Bindable<WorkingBeatmap> beatmap;
|
private Bindable<WorkingBeatmap> beatmap;
|
||||||
private int beat;
|
private int lastBeat;
|
||||||
private double timingPointStart;
|
private double lastTimingPointStart;
|
||||||
//This is to avoid sending new beats when not at the very start of the beat
|
//This is to avoid sending new beats when not at the very start of the beat
|
||||||
private const int seek_tolerance = 20;
|
private const int seek_tolerance = 20;
|
||||||
private const double min_beat_length = 1E-100;
|
private const double min_beat_length = 1E-100;
|
||||||
|
@ -22,27 +22,25 @@ protected override void Update()
|
||||||
{
|
{
|
||||||
if (beatmap.Value != null)
|
if (beatmap.Value != null)
|
||||||
{
|
{
|
||||||
double currentTime = beatmap.Value.Track.CurrentTime;
|
double trackCurrentTime = beatmap.Value.Track.CurrentTime;
|
||||||
ControlPoint kiaiControlPoint;
|
ControlPoint kiaiControlPoint;
|
||||||
ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTime, out kiaiControlPoint);
|
ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out kiaiControlPoint);
|
||||||
|
|
||||||
if (controlPoint != null)
|
if (controlPoint != null)
|
||||||
{
|
{
|
||||||
double oldTimingPointStart = timingPointStart;
|
|
||||||
double beatLength = controlPoint.BeatLength;
|
double beatLength = controlPoint.BeatLength;
|
||||||
int oldBeat = beat;
|
|
||||||
bool kiai = kiaiControlPoint?.KiaiMode ?? false;
|
bool kiai = kiaiControlPoint?.KiaiMode ?? false;
|
||||||
timingPointStart = controlPoint.Time;
|
double timingPointStart = controlPoint.Time;
|
||||||
|
int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0;
|
||||||
|
|
||||||
beat = beatLength > min_beat_length ? (int)((currentTime - timingPointStart) / beatLength) : 0;
|
|
||||||
|
|
||||||
//should we handle negative beats? (before the start of the controlPoint)
|
|
||||||
//The beats before the start of the first control point are off by 1, this should do the trick
|
//The beats before the start of the first control point are off by 1, this should do the trick
|
||||||
if (currentTime < timingPointStart)
|
if (trackCurrentTime < timingPointStart)
|
||||||
beat--;
|
beat--;
|
||||||
|
|
||||||
if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (int)((currentTime - timingPointStart) % beatLength) <= seek_tolerance)
|
if ((timingPointStart != lastTimingPointStart || beat != lastBeat) && (int)((trackCurrentTime - timingPointStart) % beatLength) <= seek_tolerance)
|
||||||
OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai);
|
OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai);
|
||||||
|
lastBeat = beat;
|
||||||
|
lastTimingPointStart = timingPointStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue