2021-04-15 18:12:52 +08: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.
|
|
|
|
|
2021-04-26 16:30:27 +08:00
|
|
|
#nullable enable
|
|
|
|
|
2021-04-15 18:12:52 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
2021-05-03 12:38:53 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
2021-04-15 18:12:52 +08:00
|
|
|
{
|
2021-04-15 18:35:57 +08:00
|
|
|
/// <summary>
|
2021-04-26 16:19:44 +08:00
|
|
|
/// A <see cref="ISpectatorPlayerClock"/> which catches up using rate adjustment.
|
2021-04-15 18:35:57 +08:00
|
|
|
/// </summary>
|
2021-04-26 16:19:44 +08:00
|
|
|
public class CatchUpSpectatorPlayerClock : ISpectatorPlayerClock
|
2021-04-15 18:12:52 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2021-04-15 18:35:57 +08:00
|
|
|
/// The catch up rate.
|
2021-04-15 18:12:52 +08:00
|
|
|
/// </summary>
|
|
|
|
public const double CATCHUP_RATE = 2;
|
|
|
|
|
2021-04-26 16:30:27 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The source clock.
|
|
|
|
/// </summary>
|
|
|
|
public IFrameBasedClock? Source { get; set; }
|
2021-04-15 18:12:52 +08:00
|
|
|
|
|
|
|
public double CurrentTime { get; private set; }
|
|
|
|
|
|
|
|
public bool IsRunning { get; private set; }
|
|
|
|
|
|
|
|
public void Reset() => CurrentTime = 0;
|
|
|
|
|
|
|
|
public void Start() => IsRunning = true;
|
|
|
|
|
|
|
|
public void Stop() => IsRunning = false;
|
|
|
|
|
2021-06-11 15:23:59 +08:00
|
|
|
public bool Seek(double position)
|
|
|
|
{
|
|
|
|
CurrentTime = position;
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-15 18:12:52 +08:00
|
|
|
|
|
|
|
public void ResetSpeedAdjustments()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public double Rate => IsCatchingUp ? CATCHUP_RATE : 1;
|
|
|
|
|
|
|
|
double IAdjustableClock.Rate
|
|
|
|
{
|
|
|
|
get => Rate;
|
|
|
|
set => throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
double IClock.Rate => Rate;
|
|
|
|
|
|
|
|
public void ProcessFrame()
|
|
|
|
{
|
|
|
|
ElapsedFrameTime = 0;
|
|
|
|
FramesPerSecond = 0;
|
|
|
|
|
2021-04-26 16:30:27 +08:00
|
|
|
if (Source == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Source.ProcessFrame();
|
|
|
|
|
2021-04-15 18:12:52 +08:00
|
|
|
if (IsRunning)
|
|
|
|
{
|
2021-04-26 16:30:27 +08:00
|
|
|
double elapsedSource = Source.ElapsedFrameTime;
|
2021-04-15 18:12:52 +08:00
|
|
|
double elapsed = elapsedSource * Rate;
|
|
|
|
|
|
|
|
CurrentTime += elapsed;
|
|
|
|
ElapsedFrameTime = elapsed;
|
2021-04-26 16:30:27 +08:00
|
|
|
FramesPerSecond = Source.FramesPerSecond;
|
2021-04-15 18:12:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public double ElapsedFrameTime { get; private set; }
|
|
|
|
|
|
|
|
public double FramesPerSecond { get; private set; }
|
|
|
|
|
|
|
|
public FrameTimeInfo TimeInfo => new FrameTimeInfo { Elapsed = ElapsedFrameTime, Current = CurrentTime };
|
|
|
|
|
2021-04-23 18:11:47 +08:00
|
|
|
public Bindable<bool> WaitingOnFrames { get; } = new Bindable<bool>(true);
|
2021-04-15 18:12:52 +08:00
|
|
|
|
|
|
|
public bool IsCatchingUp { get; set; }
|
|
|
|
}
|
|
|
|
}
|