mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Prevent KeysPerSecondCounter from NRE when no instance is initialized
This commit is contained in:
@ -18,7 +18,7 @@ namespace osu.Game.Screens.Play.HUD.KPSCounter
|
|||||||
|
|
||||||
public static void AddInput()
|
public static void AddInput()
|
||||||
{
|
{
|
||||||
instance?.onNewInput.Invoke();
|
instance?.onNewInput?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeysPerSecondCalculator GetInstance(GameplayClock gameplayClock = null, DrawableRuleset drawableRuleset = null)
|
public static KeysPerSecondCalculator GetInstance(GameplayClock gameplayClock = null, DrawableRuleset drawableRuleset = null)
|
||||||
@ -41,9 +41,9 @@ namespace osu.Game.Screens.Play.HUD.KPSCounter
|
|||||||
|
|
||||||
private event Action onNewInput;
|
private event Action onNewInput;
|
||||||
|
|
||||||
private IClock workingClock => (IClock)drawableRuleset.FrameStableClock ?? gameplayClock;
|
private IClock workingClock => (IClock)drawableRuleset?.FrameStableClock ?? gameplayClock;
|
||||||
|
|
||||||
// Having the rate from mods is preffered to using GameplayClock.TrueGameplayRate()
|
// Having the rate from mods is preferred to using GameplayClock.TrueGameplayRate()
|
||||||
// as it returns 0 when paused in replays, not useful for players who want to "analyze" a replay.
|
// as it returns 0 when paused in replays, not useful for players who want to "analyze" a replay.
|
||||||
private double rate => (drawableRuleset.Mods.FirstOrDefault(m => m is ModRateAdjust) as ModRateAdjust)?.SpeedChange.Value
|
private double rate => (drawableRuleset.Mods.FirstOrDefault(m => m is ModRateAdjust) as ModRateAdjust)?.SpeedChange.Value
|
||||||
?? 1;
|
?? 1;
|
||||||
@ -64,7 +64,7 @@ namespace osu.Game.Screens.Play.HUD.KPSCounter
|
|||||||
|
|
||||||
private void addTimestamp()
|
private void addTimestamp()
|
||||||
{
|
{
|
||||||
if (workingClock != null && workingClock.CurrentTime >= maxTime && gameplayClock.TrueGameplayRate > 0)
|
if (Ready && workingClock.CurrentTime >= maxTime && gameplayClock.TrueGameplayRate > 0)
|
||||||
{
|
{
|
||||||
timestamps.Add(workingClock.CurrentTime);
|
timestamps.Add(workingClock.CurrentTime);
|
||||||
maxTime = workingClock.CurrentTime;
|
maxTime = workingClock.CurrentTime;
|
||||||
|
@ -1046,7 +1046,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
fadeOut();
|
fadeOut();
|
||||||
|
|
||||||
KeysPerSecondCalculator.GetInstance().Dispose();
|
KeysPerSecondCalculator.GetInstance()?.Dispose();
|
||||||
|
|
||||||
return base.OnExiting(e);
|
return base.OnExiting(e);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user