1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 06:52:55 +08:00

Update usages of GameplayClockContainer.GameplayClock to access properties directly

This commit is contained in:
Dean Herbert 2022-08-15 17:06:24 +09:00
parent 224f3eaa84
commit 6d78218142
14 changed files with 48 additions and 37 deletions

View File

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

View File

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

View File

@ -141,7 +141,7 @@ namespace osu.Game.Tests.Gameplay
beatmapSkinSourceContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1)) beatmapSkinSourceContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
{ {
Clock = gameplayContainer.GameplayClock Clock = gameplayContainer
}); });
}); });

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -451,7 +451,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
private void checkPaused(int userId, bool state) 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) 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) for (double i = 1000; i < TestResources.QUICK_BEATMAP_LENGTH; i += 1000)
{ {
double time = i; 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); AddUntilStep("wait for results", () => multiplayerComponents.CurrentScreen is ResultsScreen);

View File

@ -126,7 +126,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
for (int i = 0; i < Users.Count; i++) 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); syncManager.AddPlayerClock(instances[i].GameplayClock);
} }

View File

@ -1,11 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Logging; using osu.Framework.Logging;
@ -16,13 +15,8 @@ namespace osu.Game.Screens.Play
/// <summary> /// <summary>
/// Encapsulates gameplay timing logic and provides a <see cref="GameplayClock"/> via DI for gameplay components to use. /// Encapsulates gameplay timing logic and provides a <see cref="GameplayClock"/> via DI for gameplay components to use.
/// </summary> /// </summary>
public class GameplayClockContainer : Container, IAdjustableClock public class GameplayClockContainer : Container, IAdjustableClock, IFrameBasedClock
{ {
/// <summary>
/// The final clock which is exposed to gameplay components.
/// </summary>
public GameplayClock GameplayClock { get; private set; }
/// <summary> /// <summary>
/// Whether gameplay is paused. /// Whether gameplay is paused.
/// </summary> /// </summary>
@ -41,7 +35,7 @@ namespace osu.Game.Screens.Play
/// <summary> /// <summary>
/// Invoked when a seek has been performed via <see cref="Seek"/> /// Invoked when a seek has been performed via <see cref="Seek"/>
/// </summary> /// </summary>
public event Action OnSeek; public event Action? OnSeek;
private double? startTime; private double? startTime;
@ -59,11 +53,16 @@ namespace osu.Game.Screens.Play
{ {
startTime = value; startTime = value;
if (GameplayClock != null) if (GameplayClock.IsNotNull())
GameplayClock.StartTime = value; GameplayClock.StartTime = value;
} }
} }
/// <summary>
/// The final clock which is exposed to gameplay components.
/// </summary>
protected GameplayClock GameplayClock { get; private set; } = null!;
/// <summary> /// <summary>
/// Creates a new <see cref="GameplayClockContainer"/>. /// Creates a new <see cref="GameplayClockContainer"/>.
/// </summary> /// </summary>
@ -215,12 +214,23 @@ namespace osu.Game.Screens.Play
set => throw new NotSupportedException(); set => throw new NotSupportedException();
} }
double IClock.Rate => GameplayClock.Rate; public double Rate => GameplayClock.Rate;
public double CurrentTime => GameplayClock.CurrentTime; public double CurrentTime => GameplayClock.CurrentTime;
public bool IsRunning => GameplayClock.IsRunning; public bool IsRunning => GameplayClock.IsRunning;
#endregion #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;
} }
} }

View File

@ -475,7 +475,7 @@ namespace osu.Game.Screens.Play
private void updateSampleDisabledState() 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() private void updatePauseOnFocusLostState()
@ -877,7 +877,7 @@ namespace osu.Game.Screens.Play
private double? lastPauseActionTime; private double? lastPauseActionTime;
protected bool PauseCooldownActive => protected bool PauseCooldownActive =>
lastPauseActionTime.HasValue && GameplayClockContainer.GameplayClock.CurrentTime < lastPauseActionTime + pause_cooldown; lastPauseActionTime.HasValue && GameplayClockContainer.CurrentTime < lastPauseActionTime + pause_cooldown;
/// <summary> /// <summary>
/// A set of conditionals which defines whether the current game state and configuration allows for /// 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(); GameplayClockContainer.Stop();
PauseOverlay.Show(); PauseOverlay.Show();
lastPauseActionTime = GameplayClockContainer.GameplayClock.CurrentTime; lastPauseActionTime = GameplayClockContainer.CurrentTime;
return true; return true;
} }
@ -1005,7 +1005,7 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
protected virtual void StartGameplay() 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"); throw new InvalidOperationException($"{nameof(StartGameplay)} should not be called when the gameplay clock is already running");
GameplayClockContainer.Reset(true); GameplayClockContainer.Reset(true);