mirror of https://github.com/ppy/osu
Pass in master clock instead of slave clock
This commit is contained in:
parent
5b4cb71cc7
commit
6626e70c95
|
@ -168,6 +168,11 @@ private class TestSpectatorPlayerClock : TestManualClock, ISpectatorPlayerClock
|
|||
|
||||
public bool IsCatchingUp { get; set; }
|
||||
|
||||
public IFrameBasedClock Source
|
||||
{
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public readonly int Id;
|
||||
|
||||
public TestSpectatorPlayerClock(int id)
|
||||
|
|
|
@ -79,7 +79,10 @@ private void load()
|
|||
};
|
||||
|
||||
for (int i = 0; i < UserIds.Length; i++)
|
||||
grid.Add(instances[i] = new PlayerArea(UserIds[i], new CatchUpSpectatorPlayerClock(masterClockContainer.GameplayClock)));
|
||||
{
|
||||
grid.Add(instances[i] = new PlayerArea(UserIds[i], masterClockContainer.GameplayClock));
|
||||
syncManager.AddPlayerClock(instances[i].GameplayClock);
|
||||
}
|
||||
|
||||
// Todo: This is not quite correct - it should be per-user to adjust for other mod combinations.
|
||||
var playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets;
|
||||
|
@ -38,7 +39,7 @@ public class PlayerArea : CompositeDrawable, IAdjustableAudioComponent
|
|||
/// The <see cref="ISpectatorPlayerClock"/> used to control the gameplay running state of a loaded <see cref="Player"/>.
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public readonly ISpectatorPlayerClock GameplayClock;
|
||||
public readonly ISpectatorPlayerClock GameplayClock = new CatchUpSpectatorPlayerClock();
|
||||
|
||||
/// <summary>
|
||||
/// The currently-loaded score.
|
||||
|
@ -54,10 +55,9 @@ public class PlayerArea : CompositeDrawable, IAdjustableAudioComponent
|
|||
private readonly AudioContainer audioContainer;
|
||||
private OsuScreenStack stack;
|
||||
|
||||
public PlayerArea(int userId, [NotNull] ISpectatorPlayerClock gameplayClock)
|
||||
public PlayerArea(int userId, IFrameBasedClock masterClock)
|
||||
{
|
||||
UserId = userId;
|
||||
GameplayClock = gameplayClock;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Masking = true;
|
||||
|
@ -71,6 +71,8 @@ public PlayerArea(int userId, [NotNull] ISpectatorPlayerClock gameplayClock)
|
|||
},
|
||||
loadingLayer = new LoadingLayer(true) { State = { Value = Visibility.Visible } }
|
||||
};
|
||||
|
||||
GameplayClock.Source = masterClock;
|
||||
}
|
||||
|
||||
public void LoadScore([NotNull] Score score)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Timing;
|
||||
|
@ -17,12 +19,10 @@ public class CatchUpSpectatorPlayerClock : ISpectatorPlayerClock
|
|||
/// </summary>
|
||||
public const double CATCHUP_RATE = 2;
|
||||
|
||||
private readonly IFrameBasedClock masterClock;
|
||||
|
||||
public CatchUpSpectatorPlayerClock(IFrameBasedClock masterClock)
|
||||
{
|
||||
this.masterClock = masterClock;
|
||||
}
|
||||
/// <summary>
|
||||
/// The source clock.
|
||||
/// </summary>
|
||||
public IFrameBasedClock? Source { get; set; }
|
||||
|
||||
public double CurrentTime { get; private set; }
|
||||
|
||||
|
@ -52,19 +52,22 @@ double IAdjustableClock.Rate
|
|||
|
||||
public void ProcessFrame()
|
||||
{
|
||||
masterClock.ProcessFrame();
|
||||
|
||||
ElapsedFrameTime = 0;
|
||||
FramesPerSecond = 0;
|
||||
|
||||
if (Source == null)
|
||||
return;
|
||||
|
||||
Source.ProcessFrame();
|
||||
|
||||
if (IsRunning)
|
||||
{
|
||||
double elapsedSource = masterClock.ElapsedFrameTime;
|
||||
double elapsedSource = Source.ElapsedFrameTime;
|
||||
double elapsed = elapsedSource * Rate;
|
||||
|
||||
CurrentTime += elapsed;
|
||||
ElapsedFrameTime = elapsed;
|
||||
FramesPerSecond = masterClock.FramesPerSecond;
|
||||
FramesPerSecond = Source.FramesPerSecond;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,5 +20,10 @@ public interface ISpectatorPlayerClock : IFrameBasedClock, IAdjustableClock
|
|||
/// Whether this clock is resynchronising to the master clock.
|
||||
/// </summary>
|
||||
bool IsCatchingUp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The source clock
|
||||
/// </summary>
|
||||
IFrameBasedClock Source { set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue