diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 666d0e3f77..8b38547037 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -11,40 +11,42 @@ namespace osu.Game.Graphics.Containers { public class BeatSyncedContainer : Container { + /// <summary> + /// A new beat will not be sent if the time since the beat is larger than this tolerance. + /// </summary> + private const int seek_tolerance = 20; + private Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private int lastBeat; - private double lastTimingPointStart; - //This is to avoid sending new beats when not at the very start of the beat - private const int seek_tolerance = 20; - private const double min_beat_length = 1E-100; + private ControlPoint lastControlPoint; protected override void Update() { if (beatmap.Value?.Track == null) return; - double trackCurrentTime = beatmap.Value.Track.CurrentTime; + double currentTrackTime = beatmap.Value.Track.CurrentTime; ControlPoint overridePoint; - ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out overridePoint); - - if (controlPoint == null) - return; + ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTrackTime, out overridePoint); bool kiai = (overridePoint ?? controlPoint).KiaiMode; + int beat = controlPoint.BeatLength > 0 ? (int)((currentTrackTime - controlPoint.Time) / controlPoint.BeatLength) : 0; - double beatLength = controlPoint.BeatLength; - double timingPointStart = controlPoint.Time; - int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0; - - //The beats before the start of the first control point are off by 1, this should do the trick - if (trackCurrentTime < timingPointStart) + // The beats before the start of the first control point are off by 1, this should do the trick + if (currentTrackTime < controlPoint.Time) beat--; - if ((timingPointStart != lastTimingPointStart || beat != lastBeat) && (int)((trackCurrentTime - timingPointStart) % beatLength) <= seek_tolerance) - OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); + if (controlPoint == lastControlPoint && beat == lastBeat) + return; + + if ((currentTrackTime - controlPoint.Time) % controlPoint.BeatLength > seek_tolerance) + return; + + OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); + lastBeat = beat; - lastTimingPointStart = timingPointStart; + lastControlPoint = controlPoint; } protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai)