Use interface to convey beat sync information

This commit is contained in:
Dean Herbert
2022-05-22 22:15:53 +09:00
parent 9a780bcad3
commit eabf578282
9 changed files with 96 additions and 68 deletions

View File

@ -5,12 +5,9 @@ using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Play;
namespace osu.Game.Graphics.Containers
@ -75,74 +72,38 @@ namespace osu.Game.Graphics.Containers
/// </summary>
protected bool IsBeatSyncedWithTrack { get; private set; }
[Resolved]
protected IBeatSyncProvider BeatSyncSource { get; private set; }
protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
{
}
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
[Resolved(canBeNull: true)]
protected GameplayClock GameplayClock { get; private set; }
[Resolved(canBeNull: true)]
protected EditorBeatmap EditorBeatmap { get; private set; }
[Resolved(canBeNull: true)]
protected EditorClock EditorClock { get; private set; }
protected IBeatmap Beatmap => EditorBeatmap ?? beatmap?.Value.Beatmap;
protected IClock BeatSyncClock
{
get
{
if (EditorClock != null)
return EditorClock;
if (GameplayClock != null)
return GameplayClock;
if (beatmap.Value.TrackLoaded)
return beatmap.Value.Track;
return null;
}
}
protected override void Update()
{
ITrack track = null;
TimingControlPoint timingPoint;
EffectControlPoint effectPoint;
IClock clock = BeatSyncClock;
IsBeatSyncedWithTrack = BeatSyncSource.Clock?.IsRunning == true;
if (clock == null)
return;
double currentTrackTime = clock.CurrentTime + EarlyActivationMilliseconds;
if (beatmap.Value.TrackLoaded && beatmap.Value.BeatmapLoaded)
{
track = beatmap.Value.Track;
}
IsBeatSyncedWithTrack = beatmap != null && clock.IsRunning && track?.Length > 0;
double currentTrackTime;
if (IsBeatSyncedWithTrack)
{
Debug.Assert(beatmap != null);
Debug.Assert(BeatSyncSource.ControlPoints != null);
Debug.Assert(BeatSyncSource.Clock != null);
timingPoint = Beatmap.ControlPointInfo.TimingPointAt(currentTrackTime);
effectPoint = Beatmap.ControlPointInfo.EffectPointAt(currentTrackTime);
currentTrackTime = BeatSyncSource.Clock.CurrentTime + EarlyActivationMilliseconds;
timingPoint = BeatSyncSource.ControlPoints.TimingPointAt(currentTrackTime);
effectPoint = BeatSyncSource.ControlPoints.EffectPointAt(currentTrackTime);
}
else
{
// this may be the case where the beat syncing clock has been paused.
// we still want to show an idle animation, so use this container's time instead.
currentTrackTime = Clock.CurrentTime + EarlyActivationMilliseconds;
timingPoint = TimingControlPoint.DEFAULT;
effectPoint = EffectControlPoint.DEFAULT;
}
@ -172,7 +133,7 @@ namespace osu.Game.Graphics.Containers
if (AllowMistimedEventFiring || Math.Abs(TimeSinceLastBeat) < MISTIMED_ALLOWANCE)
{
using (BeginDelayedSequence(-TimeSinceLastBeat))
OnNewBeat(beatIndex, timingPoint, effectPoint, track?.CurrentAmplitudes ?? ChannelAmplitudes.Empty);
OnNewBeat(beatIndex, timingPoint, effectPoint, BeatSyncSource.Amplitudes ?? ChannelAmplitudes.Empty);
}
lastBeat = beatIndex;