1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Merge pull request #19775 from peppy/less-gameplay-clock

Move all usage of `GameplayClock` to `IGameplayClock`
This commit is contained in:
Bartłomiej Dach 2022-08-15 13:23:04 +02:00 committed by GitHub
commit c334a84139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 141 additions and 113 deletions

View File

@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
{
Mod = mod,
PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2 &&
Precision.AlmostEquals(Player.GameplayClockContainer.GameplayClock.Rate, mod.SpeedChange.Value)
Precision.AlmostEquals(Player.GameplayClockContainer.Rate, mod.SpeedChange.Value)
});
}
}

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

@ -45,7 +45,7 @@ namespace osu.Game.Tests.Gameplay
});
AddStep("start clock", () => gameplayClockContainer.Start());
AddUntilStep("elapsed greater than zero", () => gameplayClockContainer.GameplayClock.ElapsedFrameTime > 0);
AddUntilStep("elapsed greater than zero", () => gameplayClockContainer.ElapsedFrameTime > 0);
}
[Test]
@ -60,16 +60,16 @@ namespace osu.Game.Tests.Gameplay
});
AddStep("start clock", () => gameplayClockContainer.Start());
AddUntilStep("current time greater 2000", () => gameplayClockContainer.GameplayClock.CurrentTime > 2000);
AddUntilStep("current time greater 2000", () => gameplayClockContainer.CurrentTime > 2000);
double timeAtReset = 0;
AddStep("reset clock", () =>
{
timeAtReset = gameplayClockContainer.GameplayClock.CurrentTime;
timeAtReset = gameplayClockContainer.CurrentTime;
gameplayClockContainer.Reset();
});
AddAssert("current time < time at reset", () => gameplayClockContainer.GameplayClock.CurrentTime < timeAtReset);
AddAssert("current time < time at reset", () => gameplayClockContainer.CurrentTime < timeAtReset);
}
[Test]

View File

@ -77,7 +77,6 @@ namespace osu.Game.Tests.Gameplay
Add(gameplayContainer = new MasterGameplayClockContainer(working, 0)
{
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
@ -106,7 +105,6 @@ namespace osu.Game.Tests.Gameplay
Add(gameplayContainer = new MasterGameplayClockContainer(working, start_time)
{
StartTime = start_time,
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
@ -141,7 +139,7 @@ namespace osu.Game.Tests.Gameplay
beatmapSkinSourceContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
{
Clock = gameplayContainer.GameplayClock
Clock = gameplayContainer
});
});

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

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

View File

@ -130,7 +130,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public double FirstHitObjectTime => DrawableRuleset.Objects.First().StartTime;
public double GameplayClockTime => GameplayClockContainer.GameplayClock.CurrentTime;
public double GameplayClockTime => GameplayClockContainer.CurrentTime;
protected override void UpdateAfterChildren()
{
@ -138,7 +138,7 @@ namespace osu.Game.Tests.Visual.Gameplay
if (!FirstFrameClockTime.HasValue)
{
FirstFrameClockTime = GameplayClockContainer.GameplayClock.CurrentTime;
FirstFrameClockTime = GameplayClockContainer.CurrentTime;
AddInternal(new OsuSpriteText
{
Text = $"GameplayStartTime: {DrawableRuleset.GameplayStartTime} "

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual.Gameplay
base.SetUpSteps();
AddUntilStep("gameplay has started",
() => Player.GameplayClockContainer.GameplayClock.CurrentTime > Player.DrawableRuleset.GameplayStartTime);
() => Player.GameplayClockContainer.CurrentTime > Player.DrawableRuleset.GameplayStartTime);
}
[Test]

View File

@ -313,7 +313,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("pause again", () =>
{
Player.Pause();
return !Player.GameplayClockContainer.GameplayClock.IsRunning;
return !Player.GameplayClockContainer.IsRunning;
});
AddAssert("loop is playing", () => getLoop().IsPlaying);
@ -378,7 +378,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("pause overlay " + (isShown ? "shown" : "hidden"), () => Player.PauseOverlayVisible == isShown);
private void confirmClockRunning(bool isRunning) =>
AddUntilStep("clock " + (isRunning ? "running" : "stopped"), () => Player.GameplayClockContainer.GameplayClock.IsRunning == isRunning);
AddUntilStep("clock " + (isRunning ? "running" : "stopped"), () => Player.GameplayClockContainer.IsRunning == isRunning);
protected override bool AllowFail => true;

View File

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

View File

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

View File

@ -6,6 +6,7 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osuTK;
@ -22,7 +23,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private double increment;
private GameplayClockContainer gameplayClockContainer;
private GameplayClock gameplayClock;
private IFrameBasedClock gameplayClock;
private const double skip_time = 6000;
@ -51,7 +52,7 @@ namespace osu.Game.Tests.Visual.Gameplay
};
gameplayClockContainer.Start();
gameplayClock = gameplayClockContainer.GameplayClock;
gameplayClock = gameplayClockContainer;
});
[Test]

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.Gameplay
Add(gameplayClockContainer = new MasterGameplayClockContainer(Beatmap.Value, skip_target_time));
Dependencies.CacheAs(gameplayClockContainer.GameplayClock);
Dependencies.CacheAs<IGameplayClock>(gameplayClockContainer);
}
[SetUpSteps]

View File

@ -64,7 +64,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestStoryboardNoSkipOutro()
{
CreateTest();
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.CurrentTime >= currentStoryboardDuration);
AddUntilStep("wait for score shown", () => Player.IsScoreShown);
}
@ -100,7 +100,7 @@ namespace osu.Game.Tests.Visual.Gameplay
});
AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.CurrentTime >= currentStoryboardDuration);
AddUntilStep("wait for fail overlay", () => Player.FailOverlay.State.Value == Visibility.Visible);
}
@ -111,7 +111,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
AddStep("set ShowResults = false", () => showResults = false);
});
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.CurrentTime >= currentStoryboardDuration);
AddWaitStep("wait", 10);
AddAssert("no score shown", () => !Player.IsScoreShown);
}
@ -120,7 +120,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestStoryboardEndsBeforeCompletion()
{
CreateTest(() => AddStep("set storyboard duration to .1s", () => currentStoryboardDuration = 100));
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.CurrentTime >= currentStoryboardDuration);
AddUntilStep("completion set by processor", () => Player.ScoreProcessor.HasCompleted.Value);
AddUntilStep("wait for score shown", () => Player.IsScoreShown);
}
@ -138,7 +138,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("skip overlay content not visible", () => fadeContainer().State == Visibility.Hidden);
AddUntilStep("skip overlay content becomes visible", () => fadeContainer().State == Visibility.Visible);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.CurrentTime >= currentStoryboardDuration);
}
[Test]

View File

@ -451,7 +451,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
}
private void checkPaused(int userId, bool state)
=> AddUntilStep($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType<GameplayClockContainer>().First().GameplayClock.IsRunning != state);
=> AddUntilStep($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType<GameplayClockContainer>().First().IsRunning != state);
private void checkPausedInstant(int userId, bool state)
{

View File

@ -671,7 +671,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
for (double i = 1000; i < TestResources.QUICK_BEATMAP_LENGTH; i += 1000)
{
double time = i;
AddUntilStep($"wait for time > {i}", () => this.ChildrenOfType<GameplayClockContainer>().SingleOrDefault()?.GameplayClock.CurrentTime > time);
AddUntilStep($"wait for time > {i}", () => this.ChildrenOfType<GameplayClockContainer>().SingleOrDefault()?.CurrentTime > time);
}
AddUntilStep("wait for results", () => multiplayerComponents.CurrentScreen is ResultsScreen);

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -36,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)
@ -63,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);
}
}
@ -129,6 +130,8 @@ namespace osu.Game.Rulesets.UI
if (parentGameplayClock == null)
setClock(); // LoadComplete may not be run yet, but we still want the clock.
Debug.Assert(parentGameplayClock != null);
double proposedTime = parentGameplayClock.CurrentTime;
if (FrameStablePlayback)
@ -269,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

@ -1,12 +1,8 @@
// 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.
#nullable disable
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
@ -26,7 +22,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// </summary>
/// <param name="score">The score containing the player's replay.</param>
/// <param name="spectatorPlayerClock">The clock controlling the gameplay running state.</param>
public MultiSpectatorPlayer([NotNull] Score score, [NotNull] ISpectatorPlayerClock spectatorPlayerClock)
public MultiSpectatorPlayer(Score score, ISpectatorPlayerClock spectatorPlayerClock)
: base(score, new PlayerConfiguration { AllowUserInteraction = false })
{
this.spectatorPlayerClock = spectatorPlayerClock;
@ -41,6 +37,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
HUDOverlay.HoldToQuit.Expire();
}
protected override void Update()
{
// The player clock's running state is controlled externally, but the local pausing state needs to be updated to start/stop gameplay.
CatchUpSpectatorPlayerClock catchUpClock = (CatchUpSpectatorPlayerClock)GameplayClockContainer.SourceClock;
if (catchUpClock.IsRunning)
GameplayClockContainer.Start();
else
GameplayClockContainer.Stop();
base.Update();
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
@ -50,28 +59,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
}
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
=> new SpectatorGameplayClockContainer(spectatorPlayerClock);
private class SpectatorGameplayClockContainer : GameplayClockContainer
{
public SpectatorGameplayClockContainer([NotNull] IClock sourceClock)
: base(sourceClock)
{
}
protected override void Update()
{
// The SourceClock here is always a CatchUpSpectatorPlayerClock.
// The player clock's running state is controlled externally, but the local pausing state needs to be updated to stop gameplay.
if (SourceClock.IsRunning)
Start();
else
Stop();
base.Update();
}
protected override GameplayClock CreateGameplayClock(IFrameBasedClock source) => new GameplayClock(source);
}
=> new GameplayClockContainer(spectatorPlayerClock);
}
}

View File

@ -126,7 +126,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
for (int i = 0; i < Users.Count; i++)
{
grid.Add(instances[i] = new PlayerArea(Users[i], masterClockContainer.GameplayClock));
grid.Add(instances[i] = new PlayerArea(Users[i], masterClockContainer));
syncManager.AddPlayerClock(instances[i].GameplayClock);
}

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

@ -1,11 +1,11 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
@ -16,17 +16,14 @@ namespace osu.Game.Screens.Play
/// <summary>
/// Encapsulates gameplay timing logic and provides a <see cref="GameplayClock"/> via DI for gameplay components to use.
/// </summary>
public abstract class GameplayClockContainer : Container, IAdjustableClock
public class GameplayClockContainer : Container, IAdjustableClock, IGameplayClock
{
/// <summary>
/// The final clock which is exposed to gameplay components.
/// </summary>
public GameplayClock GameplayClock { get; private set; }
/// <summary>
/// Whether gameplay is paused.
/// </summary>
public readonly BindableBool IsPaused = new BindableBool(true);
public IBindable<bool> IsPaused => isPaused;
private readonly BindableBool isPaused = new BindableBool(true);
/// <summary>
/// The adjustable source clock used for gameplay. Should be used for seeks and clock control.
@ -36,12 +33,12 @@ namespace osu.Game.Screens.Play
/// <summary>
/// The source clock.
/// </summary>
protected IClock SourceClock { get; private set; }
public IClock SourceClock { get; private set; }
/// <summary>
/// Invoked when a seek has been performed via <see cref="Seek"/>
/// </summary>
public event Action OnSeek;
public event Action? OnSeek;
private double? startTime;
@ -59,16 +56,23 @@ namespace osu.Game.Screens.Play
{
startTime = value;
if (GameplayClock != null)
if (GameplayClock.IsNotNull())
GameplayClock.StartTime = value;
}
}
public IEnumerable<Bindable<double>> NonGameplayAdjustments => GameplayClock.NonGameplayAdjustments;
/// <summary>
/// The final clock which is exposed to gameplay components.
/// </summary>
protected GameplayClock GameplayClock { get; private set; } = null!;
/// <summary>
/// Creates a new <see cref="GameplayClockContainer"/>.
/// </summary>
/// <param name="sourceClock">The source <see cref="IClock"/> used for timing.</param>
protected GameplayClockContainer(IClock sourceClock)
public GameplayClockContainer(IClock sourceClock)
{
SourceClock = sourceClock;
@ -82,10 +86,12 @@ namespace osu.Game.Screens.Play
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(GameplayClock = CreateGameplayClock(AdjustableSource));
GameplayClock = CreateGameplayClock(AdjustableSource);
dependencies.CacheAs<IGameplayClock>(this);
GameplayClock.StartTime = StartTime;
GameplayClock.IsPaused.BindTo(IsPaused);
GameplayClock.IsPaused.BindTo(isPaused);
return dependencies;
}
@ -106,7 +112,7 @@ namespace osu.Game.Screens.Play
AdjustableSource.Start();
}
IsPaused.Value = false;
isPaused.Value = false;
}
/// <summary>
@ -128,7 +134,7 @@ namespace osu.Game.Screens.Play
/// <summary>
/// Stops gameplay.
/// </summary>
public void Stop() => IsPaused.Value = true;
public void Stop() => isPaused.Value = true;
/// <summary>
/// Resets this <see cref="GameplayClockContainer"/> and the source to an initial state ready for gameplay.
@ -193,7 +199,7 @@ namespace osu.Game.Screens.Play
/// </remarks>
/// <param name="source">The <see cref="IFrameBasedClock"/> providing the source time.</param>
/// <returns>The final <see cref="GameplayClock"/>.</returns>
protected abstract GameplayClock CreateGameplayClock(IFrameBasedClock source);
protected virtual GameplayClock CreateGameplayClock(IFrameBasedClock source) => new GameplayClock(source);
#region IAdjustableClock
@ -205,9 +211,7 @@ namespace osu.Game.Screens.Play
void IAdjustableClock.Reset() => Reset();
public void ResetSpeedAdjustments()
{
}
public void ResetSpeedAdjustments() => throw new NotImplementedException();
double IAdjustableClock.Rate
{
@ -215,12 +219,25 @@ namespace osu.Game.Screens.Play
set => throw new NotSupportedException();
}
double IClock.Rate => GameplayClock.Rate;
public double Rate => GameplayClock.Rate;
public double CurrentTime => GameplayClock.CurrentTime;
public bool IsRunning => GameplayClock.IsRunning;
#endregion
public void ProcessFrame()
{
// Handled via update. Don't process here to safeguard from external usages potentially processing frames additional times.
}
public double ElapsedFrameTime => GameplayClock.ElapsedFrameTime;
public double FramesPerSecond => GameplayClock.FramesPerSecond;
public FrameTimeInfo TimeInfo => GameplayClock.TimeInfo;
public double TrueGameplayRate => GameplayClock.TrueGameplayRate;
}
}

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

@ -330,7 +330,7 @@ namespace osu.Game.Screens.Play
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateGameplayState());
// bind clock into components that require it
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
((IBindable<bool>)DrawableRuleset.IsPaused).BindTo(GameplayClockContainer.IsPaused);
DrawableRuleset.NewResult += r =>
{
@ -475,7 +475,7 @@ namespace osu.Game.Screens.Play
private void updateSampleDisabledState()
{
samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.IsCatchingUp.Value || GameplayClockContainer.GameplayClock.IsPaused.Value;
samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.IsCatchingUp.Value || GameplayClockContainer.IsPaused.Value;
}
private void updatePauseOnFocusLostState()
@ -877,7 +877,7 @@ namespace osu.Game.Screens.Play
private double? lastPauseActionTime;
protected bool PauseCooldownActive =>
lastPauseActionTime.HasValue && GameplayClockContainer.GameplayClock.CurrentTime < lastPauseActionTime + pause_cooldown;
lastPauseActionTime.HasValue && GameplayClockContainer.CurrentTime < lastPauseActionTime + pause_cooldown;
/// <summary>
/// A set of conditionals which defines whether the current game state and configuration allows for
@ -915,7 +915,7 @@ namespace osu.Game.Screens.Play
GameplayClockContainer.Stop();
PauseOverlay.Show();
lastPauseActionTime = GameplayClockContainer.GameplayClock.CurrentTime;
lastPauseActionTime = GameplayClockContainer.CurrentTime;
return true;
}
@ -1005,7 +1005,7 @@ namespace osu.Game.Screens.Play
/// </summary>
protected virtual void StartGameplay()
{
if (GameplayClockContainer.GameplayClock.IsRunning)
if (GameplayClockContainer.IsRunning)
throw new InvalidOperationException($"{nameof(StartGameplay)} should not be called when the gameplay clock is already running");
GameplayClockContainer.Reset(true);

View File

@ -18,7 +18,7 @@ namespace osu.Game.Screens.Play
public class ScreenSuspensionHandler : Component
{
private readonly GameplayClockContainer gameplayClockContainer;
private Bindable<bool> isPaused;
private IBindable<bool> isPaused;
private readonly Bindable<bool> disableSuspensionBindable = new Bindable<bool>();

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;