mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 18:42:56 +08:00
More refactoring/xmldocs
This commit is contained in:
parent
6301111fa3
commit
3a78c19f96
@ -9,26 +9,36 @@ using osu.Framework.Timing;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Play
|
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
|
public abstract class GameplayClockContainer : Container
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The final clock which is exposed to underlying components.
|
/// The final clock which is exposed to gameplay components.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GameplayClock GameplayClock { get; private set; }
|
public GameplayClock GameplayClock { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether gameplay is paused.
|
||||||
|
/// </summary>
|
||||||
public readonly BindableBool IsPaused = new BindableBool();
|
public readonly BindableBool IsPaused = new BindableBool();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The decoupled clock used for gameplay. Should be used for seeks and clock control.
|
/// The adjustable source clock used for gameplay. Should be used for seeks and clock control.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly DecoupleableInterpolatingFramedClock AdjustableClock;
|
protected readonly DecoupleableInterpolatingFramedClock AdjustableSource;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="GameplayClockContainer"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sourceClock">The source <see cref="IClock"/> used for timing.</param>
|
||||||
protected GameplayClockContainer(IClock sourceClock)
|
protected GameplayClockContainer(IClock sourceClock)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
AdjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
|
AdjustableSource = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
|
||||||
AdjustableClock.ChangeSource(sourceClock);
|
AdjustableSource.ChangeSource(sourceClock);
|
||||||
|
|
||||||
IsPaused.BindValueChanged(OnIsPausedChanged);
|
IsPaused.BindValueChanged(OnIsPausedChanged);
|
||||||
}
|
}
|
||||||
@ -37,21 +47,24 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
dependencies.CacheAs(GameplayClock = CreateGameplayClock(AdjustableClock));
|
dependencies.CacheAs(GameplayClock = CreateGameplayClock(AdjustableSource));
|
||||||
GameplayClock.IsPaused.BindTo(IsPaused);
|
GameplayClock.IsPaused.BindTo(IsPaused);
|
||||||
|
|
||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts gameplay.
|
||||||
|
/// </summary>
|
||||||
public virtual void Start()
|
public virtual void Start()
|
||||||
{
|
{
|
||||||
if (!AdjustableClock.IsRunning)
|
if (!AdjustableSource.IsRunning)
|
||||||
{
|
{
|
||||||
// Seeking the decoupled clock to its current time ensures that its source clock will be seeked to the same time
|
// Seeking the decoupled clock to its current time ensures that its source clock will be seeked to the same time
|
||||||
// This accounts for the clock source potentially taking time to enter a completely stopped state
|
// This accounts for the clock source potentially taking time to enter a completely stopped state
|
||||||
Seek(GameplayClock.CurrentTime);
|
Seek(GameplayClock.CurrentTime);
|
||||||
|
|
||||||
AdjustableClock.Start();
|
AdjustableSource.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
IsPaused.Value = false;
|
IsPaused.Value = false;
|
||||||
@ -59,19 +72,22 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Seek to a specific time in gameplay.
|
/// Seek to a specific time in gameplay.
|
||||||
/// <remarks>
|
|
||||||
/// Adjusts for any offsets which have been applied (so the seek may not be the expected point in time on the underlying audio track).
|
|
||||||
/// </remarks>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The destination time to seek to.</param>
|
/// <param name="time">The destination time to seek to.</param>
|
||||||
public virtual void Seek(double time) => AdjustableClock.Seek(time);
|
public virtual void Seek(double time) => AdjustableSource.Seek(time);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops gameplay.
|
||||||
|
/// </summary>
|
||||||
public virtual void Stop() => IsPaused.Value = true;
|
public virtual void Stop() => IsPaused.Value = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restarts gameplay.
|
||||||
|
/// </summary>
|
||||||
public virtual void Restart()
|
public virtual void Restart()
|
||||||
{
|
{
|
||||||
AdjustableClock.Seek(0);
|
AdjustableSource.Seek(0);
|
||||||
AdjustableClock.Stop();
|
AdjustableSource.Stop();
|
||||||
|
|
||||||
if (!IsPaused.Value)
|
if (!IsPaused.Value)
|
||||||
Start();
|
Start();
|
||||||
@ -85,8 +101,26 @@ namespace osu.Game.Screens.Play
|
|||||||
base.Update();
|
base.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void OnIsPausedChanged(ValueChangedEvent<bool> isPaused);
|
/// <summary>
|
||||||
|
/// Invoked when the value of <see cref="IsPaused"/> is changed to start or stop the <see cref="AdjustableSource"/> clock.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isPaused">Whether the clock should now be paused.</param>
|
||||||
|
protected virtual void OnIsPausedChanged(ValueChangedEvent<bool> isPaused)
|
||||||
|
{
|
||||||
|
if (isPaused.NewValue)
|
||||||
|
AdjustableSource.Stop();
|
||||||
|
else
|
||||||
|
AdjustableSource.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the final <see cref="GameplayClock"/> which is exposed via DI to be used by gameplay components.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Any intermediate clocks such as platform offsets should be applied here.
|
||||||
|
/// </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 abstract GameplayClock CreateGameplayClock(IFrameBasedClock source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Screens.Play
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const double MINIMUM_SKIP_TIME = 1000;
|
public const double MINIMUM_SKIP_TIME = 1000;
|
||||||
|
|
||||||
protected Track Track => (Track)AdjustableClock.Source;
|
protected Track Track => (Track)AdjustableSource.Source;
|
||||||
|
|
||||||
public readonly BindableNumber<double> UserPlaybackRate = new BindableDouble(1)
|
public readonly BindableNumber<double> UserPlaybackRate = new BindableDouble(1)
|
||||||
{
|
{
|
||||||
@ -84,17 +84,25 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
Seek(startTime);
|
Seek(startTime);
|
||||||
|
|
||||||
AdjustableClock.ProcessFrame();
|
AdjustableSource.ProcessFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnIsPausedChanged(ValueChangedEvent<bool> isPaused)
|
protected override void OnIsPausedChanged(ValueChangedEvent<bool> isPaused)
|
||||||
{
|
{
|
||||||
|
// The source is stopped by a frequency fade first.
|
||||||
if (isPaused.NewValue)
|
if (isPaused.NewValue)
|
||||||
this.TransformBindableTo(pauseFreqAdjust, 0, 200, Easing.Out).OnComplete(_ => AdjustableClock.Stop());
|
this.TransformBindableTo(pauseFreqAdjust, 0, 200, Easing.Out).OnComplete(_ => AdjustableSource.Stop());
|
||||||
else
|
else
|
||||||
this.TransformBindableTo(pauseFreqAdjust, 1, 200, Easing.In);
|
this.TransformBindableTo(pauseFreqAdjust, 1, 200, Easing.In);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seek to a specific time in gameplay.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Adjusts for any offsets which have been applied (so the seek may not be the expected point in time on the underlying audio track).
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="time">The destination time to seek to.</param>
|
||||||
public override void Seek(double time)
|
public override void Seek(double time)
|
||||||
{
|
{
|
||||||
// remove the offset component here because most of the time we want the seek to be aligned to gameplay, not the audio track.
|
// remove the offset component here because most of the time we want the seek to be aligned to gameplay, not the audio track.
|
||||||
@ -146,7 +154,7 @@ namespace osu.Game.Screens.Play
|
|||||||
public void StopUsingBeatmapClock()
|
public void StopUsingBeatmapClock()
|
||||||
{
|
{
|
||||||
removeSourceClockAdjustments();
|
removeSourceClockAdjustments();
|
||||||
AdjustableClock.ChangeSource(new TrackVirtual(beatmap.Track.Length));
|
AdjustableSource.ChangeSource(new TrackVirtual(beatmap.Track.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool speedAdjustmentsApplied;
|
private bool speedAdjustmentsApplied;
|
||||||
|
Loading…
Reference in New Issue
Block a user