2017-05-19 09:19:00 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
2017-05-17 14:18:56 +08:00
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-05-17 14:14:04 +08:00
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
{
|
|
|
|
public class BeatSyncedContainer : Container
|
|
|
|
{
|
2017-05-22 16:15:23 +08:00
|
|
|
/// <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;
|
|
|
|
|
2017-05-22 16:50:05 +08:00
|
|
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
2017-05-22 16:01:43 +08:00
|
|
|
|
2017-05-19 09:19:00 +08:00
|
|
|
private int lastBeat;
|
2017-05-22 16:15:23 +08:00
|
|
|
private ControlPoint lastControlPoint;
|
2017-05-17 14:14:04 +08:00
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
2017-05-22 16:01:43 +08:00
|
|
|
if (beatmap.Value?.Track == null)
|
2017-05-22 15:56:40 +08:00
|
|
|
return;
|
|
|
|
|
2017-05-22 16:15:23 +08:00
|
|
|
double currentTrackTime = beatmap.Value.Track.CurrentTime;
|
2017-05-22 16:00:53 +08:00
|
|
|
ControlPoint overridePoint;
|
2017-05-22 16:15:23 +08:00
|
|
|
ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTrackTime, out overridePoint);
|
2017-05-22 15:56:40 +08:00
|
|
|
|
2017-05-22 16:00:53 +08:00
|
|
|
bool kiai = (overridePoint ?? controlPoint).KiaiMode;
|
2017-05-22 16:15:23 +08:00
|
|
|
int beat = controlPoint.BeatLength > 0 ? (int)((currentTrackTime - controlPoint.Time) / controlPoint.BeatLength) : 0;
|
2017-05-22 15:59:44 +08:00
|
|
|
|
2017-05-22 16:15:23 +08:00
|
|
|
// The beats before the start of the first control point are off by 1, this should do the trick
|
|
|
|
if (currentTrackTime < controlPoint.Time)
|
2017-05-22 15:56:40 +08:00
|
|
|
beat--;
|
|
|
|
|
2017-05-22 16:15:23 +08:00
|
|
|
if (controlPoint == lastControlPoint && beat == lastBeat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((currentTrackTime - controlPoint.Time) % controlPoint.BeatLength > seek_tolerance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai);
|
|
|
|
|
2017-05-22 15:56:40 +08:00
|
|
|
lastBeat = beat;
|
2017-05-22 16:15:23 +08:00
|
|
|
lastControlPoint = controlPoint;
|
2017-05-17 14:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuGameBase game)
|
|
|
|
{
|
2017-05-22 16:01:43 +08:00
|
|
|
beatmap.BindTo(game.Beatmap);
|
2017-05-17 14:14:04 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 22:23:04 +08:00
|
|
|
}
|