2019-03-05 04:53:47 +00:00
|
|
|
// 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.
|
|
|
|
|
2020-09-21 10:39:54 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2019-03-25 11:25:47 +00:00
|
|
|
using osu.Framework.Bindables;
|
2019-03-05 04:53:47 +00:00
|
|
|
using osu.Framework.Timing;
|
2020-10-04 12:51:27 +00:00
|
|
|
using osu.Framework.Utils;
|
2019-03-05 04:53:47 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A clock which is used for gameplay elements that need to follow audio time 1:1.
|
2019-04-25 08:36:17 +00:00
|
|
|
/// Exposed via DI by <see cref="GameplayClockContainer"/>.
|
2019-03-05 04:53:47 +00:00
|
|
|
/// <remarks>
|
2019-03-05 09:50:46 +00:00
|
|
|
/// The main purpose of this clock is to stop components using it from accidentally processing the main
|
2019-03-05 04:53:47 +00:00
|
|
|
/// <see cref="IFrameBasedClock"/>, as this should only be done once to ensure accuracy.
|
|
|
|
/// </remarks>
|
|
|
|
/// </summary>
|
2020-10-14 10:39:48 +00:00
|
|
|
public class GameplayClock : IFrameBasedClock
|
2019-03-05 04:53:47 +00:00
|
|
|
{
|
|
|
|
private readonly IFrameBasedClock underlyingClock;
|
|
|
|
|
2019-03-25 11:25:47 +00:00
|
|
|
public readonly BindableBool IsPaused = new BindableBool();
|
|
|
|
|
2020-09-21 10:39:54 +00:00
|
|
|
/// <summary>
|
|
|
|
/// All adjustments applied to this clock which don't come from gameplay or mods.
|
|
|
|
/// </summary>
|
|
|
|
public virtual IEnumerable<Bindable<double>> NonGameplayAdjustments => Enumerable.Empty<Bindable<double>>();
|
|
|
|
|
2019-03-05 04:53:47 +00:00
|
|
|
public GameplayClock(IFrameBasedClock underlyingClock)
|
|
|
|
{
|
|
|
|
this.underlyingClock = underlyingClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double CurrentTime => underlyingClock.CurrentTime;
|
|
|
|
|
|
|
|
public double Rate => underlyingClock.Rate;
|
|
|
|
|
2020-09-21 10:39:54 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The rate of gameplay when playback is at 100%.
|
|
|
|
/// This excludes any seeking / user adjustments.
|
|
|
|
/// </summary>
|
|
|
|
public double TrueGameplayRate
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
double baseRate = Rate;
|
|
|
|
|
|
|
|
foreach (var adjustment in NonGameplayAdjustments)
|
2020-10-04 12:51:27 +00:00
|
|
|
{
|
|
|
|
if (Precision.AlmostEquals(adjustment.Value, 0))
|
|
|
|
return 0;
|
|
|
|
|
2020-09-21 10:39:54 +00:00
|
|
|
baseRate /= adjustment.Value;
|
2020-10-04 12:51:27 +00:00
|
|
|
}
|
2020-09-21 10:39:54 +00:00
|
|
|
|
|
|
|
return baseRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 04:53:47 +00:00
|
|
|
public bool IsRunning => underlyingClock.IsRunning;
|
|
|
|
|
|
|
|
public void ProcessFrame()
|
|
|
|
{
|
2020-10-05 03:46:15 +00:00
|
|
|
// intentionally not updating the underlying clock (handled externally).
|
2019-03-05 04:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public double ElapsedFrameTime => underlyingClock.ElapsedFrameTime;
|
|
|
|
|
|
|
|
public double FramesPerSecond => underlyingClock.FramesPerSecond;
|
|
|
|
|
|
|
|
public FrameTimeInfo TimeInfo => underlyingClock.TimeInfo;
|
2019-09-17 13:33:27 +00:00
|
|
|
|
|
|
|
public IClock Source => underlyingClock;
|
2019-03-05 04:53:47 +00:00
|
|
|
}
|
2019-03-05 09:50:46 +00:00
|
|
|
}
|