1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Change IBeatSyncProvider.Clock to always be non-null

This commit is contained in:
Dean Herbert 2023-07-13 22:12:55 +09:00
parent 9cba24e32c
commit 20e4e2581a
9 changed files with 9 additions and 23 deletions

View File

@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Audio.Track;
@ -283,8 +282,6 @@ namespace osu.Game.Tests.Visual.UserInterface
if (ReferenceEquals(timingPoints[^1], current))
{
Debug.Assert(BeatSyncSource.Clock != null);
return (int)Math.Ceiling((BeatSyncSource.Clock.CurrentTime - current.Time) / current.BeatLength);
}
@ -295,8 +292,6 @@ namespace osu.Game.Tests.Visual.UserInterface
{
base.Update();
Debug.Assert(BeatSyncSource.Clock != null);
timeUntilNextBeat.Value = TimeUntilNextBeat;
timeSinceLastBeat.Value = TimeSinceLastBeat;
currentTime.Value = BeatSyncSource.Clock.CurrentTime;

View File

@ -5,14 +5,9 @@ namespace osu.Game.Beatmaps
{
public static class BeatSyncProviderExtensions
{
/// <summary>
/// Check whether beat sync is currently available.
/// </summary>
public static bool CheckBeatSyncAvailable(this IBeatSyncProvider provider) => provider.Clock != null;
/// <summary>
/// Whether the beat sync provider is currently in a kiai section. Should make everything more epic.
/// </summary>
public static bool CheckIsKiaiTime(this IBeatSyncProvider provider) => provider.Clock != null && provider.ControlPoints?.EffectPointAt(provider.Clock.CurrentTime).KiaiMode == true;
public static bool CheckIsKiaiTime(this IBeatSyncProvider provider) => provider.ControlPoints?.EffectPointAt(provider.Clock.CurrentTime).KiaiMode == true;
}
}

View File

@ -24,6 +24,6 @@ namespace osu.Game.Beatmaps
/// <summary>
/// Access a clock currently responsible for providing beat sync. If <c>null</c>, no current provider is available.
/// </summary>
IClock? Clock { get; }
IClock Clock { get; }
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Containers;
@ -86,14 +85,12 @@ namespace osu.Game.Graphics.Containers
TimingControlPoint timingPoint;
EffectControlPoint effectPoint;
IsBeatSyncedWithTrack = BeatSyncSource.CheckBeatSyncAvailable() && BeatSyncSource.Clock?.IsRunning == true;
IsBeatSyncedWithTrack = BeatSyncSource.Clock.IsRunning;
double currentTrackTime;
if (IsBeatSyncedWithTrack)
{
Debug.Assert(BeatSyncSource.Clock != null);
currentTrackTime = BeatSyncSource.Clock.CurrentTime + EarlyActivationMilliseconds;
timingPoint = BeatSyncSource.ControlPoints?.TimingPointAt(currentTrackTime) ?? TimingControlPoint.DEFAULT;

View File

@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Mods
int timeSignature = timingPoint.TimeSignature.Numerator;
// play metronome from one measure before the first object.
if (BeatSyncSource.Clock?.CurrentTime < firstHitTime - timingPoint.BeatLength * timeSignature)
if (BeatSyncSource.Clock.CurrentTime < firstHitTime - timingPoint.BeatLength * timeSignature)
return;
sample.Frequency.Value = beatIndex % timeSignature == 0 ? 1 : 0.5f;

View File

@ -240,7 +240,7 @@ namespace osu.Game.Screens.Edit.Timing
{
base.Update();
if (BeatSyncSource.ControlPoints == null || BeatSyncSource.Clock == null)
if (BeatSyncSource.ControlPoints == null)
return;
metronomeClock.Rate = IsBeatSyncedWithTrack ? BeatSyncSource.Clock.Rate : 1;
@ -259,7 +259,7 @@ namespace osu.Game.Screens.Edit.Timing
this.TransformBindableTo(interpolatedBpm, (int)Math.Round(timingPoint.BPM), 600, Easing.OutQuint);
}
if (BeatSyncSource.Clock?.IsRunning != true && isSwinging)
if (!BeatSyncSource.Clock.IsRunning && isSwinging)
{
swing.ClearTransforms(true);

View File

@ -310,7 +310,7 @@ namespace osu.Game.Screens.Edit.Timing
}
double averageBeatLength = (tapTimings.Last() - tapTimings.Skip(initial_taps_to_ignore).First()) / (tapTimings.Count - initial_taps_to_ignore - 1);
double clockRate = beatSyncSource?.Clock?.Rate ?? 1;
double clockRate = beatSyncSource?.Clock.Rate ?? 1;
double bpm = Math.Round(60000 / averageBeatLength / clockRate);

View File

@ -102,8 +102,7 @@ namespace osu.Game.Screens.Menu
for (int i = 0; i < temporalAmplitudes.Length; i++)
temporalAmplitudes[i] = 0;
if (beatSyncProvider.Clock != null)
addAmplitudesFromSource(beatSyncProvider);
addAmplitudesFromSource(beatSyncProvider);
foreach (var source in amplitudeSources)
addAmplitudesFromSource(source);

View File

@ -128,7 +128,7 @@ namespace osu.Game.Storyboards.Drawables
//
// In the case of storyboard animations, we want to synchronise with game time perfectly
// so let's get a correct time based on gameplay clock and earliest transform.
PlaybackPosition = (beatSyncProvider.Clock?.CurrentTime ?? Clock.CurrentTime) - Animation.EarliestTransformTime;
PlaybackPosition = beatSyncProvider.Clock.CurrentTime - Animation.EarliestTransformTime;
}
private void skinSourceChanged()