1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

Move all usage of GameplayClock to IGameplayClock

This commit is contained in:
Dean Herbert 2022-08-15 17:11:22 +09:00
parent 6d78218142
commit c8764cb333
14 changed files with 53 additions and 31 deletions

View File

@ -59,7 +59,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
private bool rotationTransferred;
[Resolved(canBeNull: true)]
private GameplayClock gameplayClock { get; set; }
private IGameplayClock gameplayClock { get; set; }
protected override void Update()
{

View File

@ -80,7 +80,7 @@ namespace osu.Game.Tests.Visual.Gameplay
(typeof(ScoreProcessor), actualComponentsContainer.Dependencies.Get<ScoreProcessor>()),
(typeof(HealthProcessor), actualComponentsContainer.Dependencies.Get<HealthProcessor>()),
(typeof(GameplayState), actualComponentsContainer.Dependencies.Get<GameplayState>()),
(typeof(GameplayClock), actualComponentsContainer.Dependencies.Get<GameplayClock>())
(typeof(IGameplayClock), actualComponentsContainer.Dependencies.Get<IGameplayClock>())
},
};

View File

@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private GameplayState gameplayState = TestGameplayState.Create(new OsuRuleset());
[Cached]
private readonly GameplayClock gameplayClock = new GameplayClock(new FramedClock());
private readonly IGameplayClock gameplayClock = new GameplayClock(new FramedClock());
// best way to check without exposing.
private Drawable hideTarget => hudOverlay.KeyCounter;

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private GameplayState gameplayState = TestGameplayState.Create(new OsuRuleset());
[Cached]
private readonly GameplayClock gameplayClock = new GameplayClock(new FramedClock());
private readonly IGameplayClock gameplayClock = new GameplayClock(new FramedClock());
[SetUpSteps]
public void SetUpSteps()

View File

@ -37,7 +37,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private GameplayState gameplayState = TestGameplayState.Create(new OsuRuleset());
[Cached]
private readonly GameplayClock gameplayClock = new GameplayClock(new FramedClock());
private readonly IGameplayClock gameplayClock = new GameplayClock(new FramedClock());
private IEnumerable<HUDOverlay> hudOverlays => CreatedDrawables.OfType<HUDOverlay>();

View File

@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.UI
public IFrameStableClock FrameStableClock => frameStableClock;
[Cached(typeof(GameplayClock))]
[Cached(typeof(IGameplayClock))]
private readonly FrameStabilityClock frameStableClock;
public FrameStabilityContainer(double gameplayStartTime = double.MinValue)
@ -64,12 +64,12 @@ namespace osu.Game.Rulesets.UI
private int direction = 1;
[BackgroundDependencyLoader(true)]
private void load(GameplayClock clock)
private void load(IGameplayClock clock)
{
if (clock != null)
{
parentGameplayClock = frameStableClock.ParentGameplayClock = clock;
frameStableClock.IsPaused.BindTo(clock.IsPaused);
((IBindable<bool>)frameStableClock.IsPaused).BindTo(clock.IsPaused);
}
}
@ -272,7 +272,7 @@ namespace osu.Game.Rulesets.UI
private class FrameStabilityClock : GameplayClock, IFrameStableClock
{
public GameplayClock ParentGameplayClock;
public IGameplayClock ParentGameplayClock;
public readonly Bindable<bool> IsCatchingUp = new Bindable<bool>();

View File

@ -45,7 +45,7 @@ namespace osu.Game.Screens.Play
private ISamplePlaybackDisabler samplePlaybackDisabler { get; set; }
[Resolved]
private GameplayClock gameplayClock { get; set; }
private IGameplayClock gameplayClock { get; set; }
private void onComboChange(ValueChangedEvent<int> combo)
{

View File

@ -19,15 +19,14 @@ namespace osu.Game.Screens.Play
/// <see cref="IFrameBasedClock"/>, as this should only be done once to ensure accuracy.
/// </remarks>
/// </summary>
public class GameplayClock : IFrameBasedClock
public class GameplayClock : IGameplayClock
{
internal readonly IFrameBasedClock UnderlyingClock;
public readonly BindableBool IsPaused = new BindableBool();
/// <summary>
/// All adjustments applied to this clock which don't come from gameplay or mods.
/// </summary>
IBindable<bool> IGameplayClock.IsPaused => IsPaused;
public virtual IEnumerable<Bindable<double>> NonGameplayAdjustments => Enumerable.Empty<Bindable<double>>();
public GameplayClock(IFrameBasedClock underlyingClock)
@ -35,23 +34,12 @@ namespace osu.Game.Screens.Play
UnderlyingClock = underlyingClock;
}
/// <summary>
/// The time from which the clock should start. Will be seeked to on calling <see cref="GameplayClockContainer.Reset"/>.
/// </summary>
/// <remarks>
/// If not set, a value of zero will be used.
/// Importantly, the value will be inferred from the current ruleset in <see cref="MasterGameplayClockContainer"/> unless specified.
/// </remarks>
public double? StartTime { get; internal set; }
public double CurrentTime => UnderlyingClock.CurrentTime;
public double Rate => UnderlyingClock.Rate;
/// <summary>
/// The rate of gameplay when playback is at 100%.
/// This excludes any seeking / user adjustments.
/// </summary>
public double TrueGameplayRate
{
get

View File

@ -81,7 +81,7 @@ namespace osu.Game.Screens.Play
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(GameplayClock = CreateGameplayClock(AdjustableSource));
dependencies.CacheAs<IGameplayClock>(GameplayClock = CreateGameplayClock(AdjustableSource));
GameplayClock.StartTime = StartTime;
GameplayClock.IsPaused.BindTo(IsPaused);

View File

@ -23,7 +23,7 @@ namespace osu.Game.Screens.Play.HUD
public bool UsesFixedAnchor { get; set; }
[Resolved]
protected GameplayClock GameplayClock { get; private set; } = null!;
protected IGameplayClock GameplayClock { get; private set; } = null!;
[Resolved(canBeNull: true)]
private DrawableRuleset? drawableRuleset { get; set; }

View File

@ -38,10 +38,10 @@ namespace osu.Game.Screens.Play.HUD
set => endTime = value;
}
private GameplayClock gameplayClock;
private IGameplayClock gameplayClock;
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, GameplayClock clock)
private void load(OsuColour colours, IGameplayClock clock)
{
if (clock != null)
gameplayClock = clock;

View File

@ -0,0 +1,34 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Framework.Timing;
namespace osu.Game.Screens.Play
{
public interface IGameplayClock : IFrameBasedClock
{
/// <summary>
/// The rate of gameplay when playback is at 100%.
/// This excludes any seeking / user adjustments.
/// </summary>
double TrueGameplayRate { get; }
/// <summary>
/// The time from which the clock should start. Will be seeked to on calling <see cref="GameplayClockContainer.Reset"/>.
/// </summary>
/// <remarks>
/// If not set, a value of zero will be used.
/// Importantly, the value will be inferred from the current ruleset in <see cref="MasterGameplayClockContainer"/> unless specified.
/// </remarks>
double? StartTime { get; }
/// <summary>
/// All adjustments applied to this clock which don't come from gameplay or mods.
/// </summary>
IEnumerable<Bindable<double>> NonGameplayAdjustments { get; }
IBindable<bool> IsPaused { get; }
}
}

View File

@ -41,7 +41,7 @@ namespace osu.Game.Screens.Play
private bool isClickable;
[Resolved]
private GameplayClock gameplayClock { get; set; }
private IGameplayClock gameplayClock { get; set; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;

View File

@ -85,7 +85,7 @@ namespace osu.Game.Storyboards.Drawables
}
[BackgroundDependencyLoader(true)]
private void load(GameplayClock clock, CancellationToken? cancellationToken, GameHost host, RealmAccess realm)
private void load(IGameplayClock clock, CancellationToken? cancellationToken, GameHost host, RealmAccess realm)
{
if (clock != null)
Clock = clock;