mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:47:29 +08:00
Cache IFrameStableClock
in Player
for easier access
Allows directly referencing rather than going through `DrawableRuleset`. Helps with testing and implementation of the new song progress display (#22144).
This commit is contained in:
parent
f7c4199a77
commit
7d0388c55c
@ -15,14 +15,12 @@ namespace osu.Game.Screens.Play.HUD.ClicksPerSecond
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IGameplayClock gameplayClock { get; set; } = null!;
|
private IGameplayClock gameplayClock { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved]
|
||||||
private DrawableRuleset? drawableRuleset { get; set; }
|
private IFrameStableClock? frameStableClock { get; set; }
|
||||||
|
|
||||||
public int Value { get; private set; }
|
public int Value { get; private set; }
|
||||||
|
|
||||||
// Even though `FrameStabilityContainer` caches as a `GameplayClock`, we need to check it directly via `drawableRuleset`
|
private IGameplayClock clock => frameStableClock ?? gameplayClock;
|
||||||
// as this calculator is not contained within the `FrameStabilityContainer` and won't see the dependency.
|
|
||||||
private IGameplayClock clock => drawableRuleset?.FrameStableClock ?? gameplayClock;
|
|
||||||
|
|
||||||
public ClicksPerSecondCalculator()
|
public ClicksPerSecondCalculator()
|
||||||
{
|
{
|
||||||
|
@ -25,10 +25,15 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
protected IGameplayClock GameplayClock { get; private set; } = null!;
|
protected IGameplayClock GameplayClock { get; private set; } = null!;
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved]
|
||||||
private DrawableRuleset? drawableRuleset { get; set; }
|
private IFrameStableClock? frameStableClock { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The reference clock is used to accurately tell the current playfield's time (including catch-up lag).
|
||||||
|
/// However, if none is available (i.e. used in tests), we fall back to the gameplay clock.
|
||||||
|
/// </summary>
|
||||||
|
protected IClock FrameStableClock => frameStableClock ?? GameplayClock;
|
||||||
|
|
||||||
private IClock? referenceClock;
|
|
||||||
private IEnumerable<HitObject>? objects;
|
private IEnumerable<HitObject>? objects;
|
||||||
|
|
||||||
public IEnumerable<HitObject> Objects
|
public IEnumerable<HitObject> Objects
|
||||||
@ -58,12 +63,11 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
protected virtual void UpdateObjects(IEnumerable<HitObject> objects) { }
|
protected virtual void UpdateObjects(IEnumerable<HitObject> objects) { }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(DrawableRuleset? drawableRuleset)
|
||||||
{
|
{
|
||||||
if (drawableRuleset != null)
|
if (drawableRuleset != null)
|
||||||
{
|
{
|
||||||
Objects = drawableRuleset.Objects;
|
Objects = drawableRuleset.Objects;
|
||||||
referenceClock = drawableRuleset.FrameStableClock;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,9 +78,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
if (objects == null)
|
if (objects == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// The reference clock is used to accurately tell the playfield's time. This is obtained from the drawable ruleset.
|
double currentTime = FrameStableClock.CurrentTime;
|
||||||
// However, if no drawable ruleset is available (i.e. used in tests), we fall back to the gameplay clock.
|
|
||||||
double currentTime = referenceClock?.CurrentTime ?? GameplayClock.CurrentTime;
|
|
||||||
|
|
||||||
bool isInIntro = currentTime < FirstHitTime;
|
bool isInIntro = currentTime < FirstHitTime;
|
||||||
|
|
||||||
|
@ -225,6 +225,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, gameplayMods);
|
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, gameplayMods);
|
||||||
dependencies.CacheAs(DrawableRuleset);
|
dependencies.CacheAs(DrawableRuleset);
|
||||||
|
dependencies.CacheAs(DrawableRuleset.FrameStableClock);
|
||||||
|
|
||||||
ScoreProcessor = ruleset.CreateScoreProcessor();
|
ScoreProcessor = ruleset.CreateScoreProcessor();
|
||||||
ScoreProcessor.Mods.Value = gameplayMods;
|
ScoreProcessor.Mods.Value = gameplayMods;
|
||||||
|
Loading…
Reference in New Issue
Block a user