mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:12:56 +08:00
Merge pull request #5961 from jorolf/background-beat
Add a 60bpm beat when no beatmap is playing
This commit is contained in:
commit
6a3f210766
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
@ -25,6 +26,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
private readonly NowPlayingOverlay np;
|
private readonly NowPlayingOverlay np;
|
||||||
|
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(BeatSyncedContainer)
|
||||||
|
};
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private MusicController musicController = new MusicController();
|
private MusicController musicController = new MusicController();
|
||||||
|
|
||||||
@ -154,7 +160,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
if (timingPoints[timingPoints.Count - 1] == current)
|
if (timingPoints[timingPoints.Count - 1] == current)
|
||||||
return current;
|
return current;
|
||||||
|
|
||||||
return timingPoints[timingPoints.IndexOf(current) + 1];
|
int index = timingPoints.IndexOf(current); // -1 means that this is a "default beat"
|
||||||
|
|
||||||
|
return index == -1 ? current : timingPoints[index + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateBeatCount(TimingControlPoint current)
|
private int calculateBeatCount(TimingControlPoint current)
|
||||||
|
@ -33,23 +33,46 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double TimeSinceLastBeat { get; private set; }
|
public double TimeSinceLastBeat { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default length of a beat in milliseconds. Used whenever there is no beatmap or track playing.
|
||||||
|
/// </summary>
|
||||||
|
private const double default_beat_length = 60000.0 / 60.0;
|
||||||
|
|
||||||
|
private TimingControlPoint defaultTiming;
|
||||||
|
private EffectControlPoint defaultEffect;
|
||||||
|
private TrackAmplitudes defaultAmplitudes;
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if (!Beatmap.Value.TrackLoaded || !Beatmap.Value.BeatmapLoaded) return;
|
Track track = null;
|
||||||
|
IBeatmap beatmap = null;
|
||||||
|
|
||||||
var track = Beatmap.Value.Track;
|
double currentTrackTime;
|
||||||
var beatmap = Beatmap.Value.Beatmap;
|
TimingControlPoint timingPoint;
|
||||||
|
EffectControlPoint effectPoint;
|
||||||
|
|
||||||
if (track == null || beatmap == null)
|
if (Beatmap.Value.TrackLoaded && Beatmap.Value.BeatmapLoaded)
|
||||||
return;
|
{
|
||||||
|
track = Beatmap.Value.Track;
|
||||||
|
beatmap = Beatmap.Value.Beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
double currentTrackTime = track.Length > 0 ? track.CurrentTime + EarlyActivationMilliseconds : Clock.CurrentTime;
|
if (track != null && beatmap != null && track.IsRunning)
|
||||||
|
{
|
||||||
|
currentTrackTime = track.Length > 0 ? track.CurrentTime + EarlyActivationMilliseconds : Clock.CurrentTime;
|
||||||
|
|
||||||
TimingControlPoint timingPoint = beatmap.ControlPointInfo.TimingPointAt(currentTrackTime);
|
timingPoint = beatmap.ControlPointInfo.TimingPointAt(currentTrackTime);
|
||||||
EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(currentTrackTime);
|
effectPoint = beatmap.ControlPointInfo.EffectPointAt(currentTrackTime);
|
||||||
|
|
||||||
if (timingPoint.BeatLength == 0)
|
if (timingPoint.BeatLength == 0)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentTrackTime = Clock.CurrentTime;
|
||||||
|
timingPoint = defaultTiming;
|
||||||
|
effectPoint = defaultEffect;
|
||||||
|
}
|
||||||
|
|
||||||
int beatIndex = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength);
|
int beatIndex = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength);
|
||||||
|
|
||||||
@ -67,7 +90,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
using (BeginDelayedSequence(-TimeSinceLastBeat, true))
|
using (BeginDelayedSequence(-TimeSinceLastBeat, true))
|
||||||
OnNewBeat(beatIndex, timingPoint, effectPoint, track.CurrentAmplitudes);
|
OnNewBeat(beatIndex, timingPoint, effectPoint, track?.CurrentAmplitudes ?? defaultAmplitudes);
|
||||||
|
|
||||||
lastBeat = beatIndex;
|
lastBeat = beatIndex;
|
||||||
lastTimingPoint = timingPoint;
|
lastTimingPoint = timingPoint;
|
||||||
@ -77,6 +100,28 @@ namespace osu.Game.Graphics.Containers
|
|||||||
private void load(IBindable<WorkingBeatmap> beatmap)
|
private void load(IBindable<WorkingBeatmap> beatmap)
|
||||||
{
|
{
|
||||||
Beatmap.BindTo(beatmap);
|
Beatmap.BindTo(beatmap);
|
||||||
|
|
||||||
|
defaultTiming = new TimingControlPoint
|
||||||
|
{
|
||||||
|
BeatLength = default_beat_length,
|
||||||
|
AutoGenerated = true,
|
||||||
|
Time = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultEffect = new EffectControlPoint
|
||||||
|
{
|
||||||
|
Time = 0,
|
||||||
|
AutoGenerated = true,
|
||||||
|
KiaiMode = false,
|
||||||
|
OmitFirstBarLine = false
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultAmplitudes = new TrackAmplitudes
|
||||||
|
{
|
||||||
|
FrequencyAmplitudes = new float[256],
|
||||||
|
LeftChannel = 0,
|
||||||
|
RightChannel = 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
|
protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
|
||||||
|
Loading…
Reference in New Issue
Block a user