1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:17:51 +08:00

Make GameplayClockContainer also an IGameplayClock and expose to remaining tests

This commit is contained in:
Dean Herbert 2022-08-15 17:36:18 +09:00
parent c8764cb333
commit f81c7644b4
8 changed files with 18 additions and 13 deletions

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))

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
@ -15,12 +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 class GameplayClockContainer : Container, IAdjustableClock, IFrameBasedClock
public class GameplayClockContainer : Container, IAdjustableClock, IGameplayClock
{
/// <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.
@ -58,6 +61,8 @@ namespace osu.Game.Screens.Play
}
}
public IEnumerable<Bindable<double>> NonGameplayAdjustments => GameplayClock.NonGameplayAdjustments;
/// <summary>
/// The final clock which is exposed to gameplay components.
/// </summary>
@ -84,7 +89,7 @@ namespace osu.Game.Screens.Play
dependencies.CacheAs<IGameplayClock>(GameplayClock = CreateGameplayClock(AdjustableSource));
GameplayClock.StartTime = StartTime;
GameplayClock.IsPaused.BindTo(IsPaused);
GameplayClock.IsPaused.BindTo(isPaused);
return dependencies;
}
@ -105,7 +110,7 @@ namespace osu.Game.Screens.Play
AdjustableSource.Start();
}
IsPaused.Value = false;
isPaused.Value = false;
}
/// <summary>
@ -127,7 +132,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.
@ -232,5 +237,7 @@ namespace osu.Game.Screens.Play
public double FramesPerSecond => GameplayClock.FramesPerSecond;
public FrameTimeInfo TimeInfo => GameplayClock.TimeInfo;
public double TrueGameplayRate => GameplayClock.TrueGameplayRate;
}
}

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 =>
{

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>();