mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 05:13:21 +08:00
Seek master clock on multi-spectator start
This commit is contained in:
parent
75d825c85c
commit
a99cb79738
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -33,6 +34,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IAdjustableClock MasterClock { get; }
|
public IAdjustableClock MasterClock { get; }
|
||||||
|
|
||||||
|
public event Action ReadyToStart;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The player clocks.
|
/// The player clocks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -80,13 +83,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
int readyCount = playerClocks.Count(s => !s.WaitingOnFrames.Value);
|
int readyCount = playerClocks.Count(s => !s.WaitingOnFrames.Value);
|
||||||
|
|
||||||
if (readyCount == playerClocks.Count)
|
if (readyCount == playerClocks.Count)
|
||||||
return hasStarted = true;
|
return performStart();
|
||||||
|
|
||||||
if (readyCount > 0)
|
if (readyCount > 0)
|
||||||
{
|
{
|
||||||
firstStartAttemptTime ??= Time.Current;
|
firstStartAttemptTime ??= Time.Current;
|
||||||
|
|
||||||
if (Time.Current - firstStartAttemptTime > MAXIMUM_START_DELAY)
|
if (Time.Current - firstStartAttemptTime > MAXIMUM_START_DELAY)
|
||||||
|
return performStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool performStart()
|
||||||
|
{
|
||||||
|
ReadyToStart?.Invoke();
|
||||||
return hasStarted = true;
|
return hasStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||||
@ -15,6 +16,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IAdjustableClock MasterClock { get; }
|
IAdjustableClock MasterClock { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An event which is invoked when gameplay is ready to start.
|
||||||
|
/// </summary>
|
||||||
|
event Action ReadyToStart;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds an <see cref="ISpectatorPlayerClock"/> to manage.
|
/// Adds an <see cref="ISpectatorPlayerClock"/> to manage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -101,6 +101,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
}, leaderboardContainer.Add);
|
}, leaderboardContainer.Add);
|
||||||
|
|
||||||
|
syncManager.ReadyToStart += onReadyToStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -129,6 +131,18 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
private bool isCandidateAudioSource([CanBeNull] ISpectatorPlayerClock clock)
|
private bool isCandidateAudioSource([CanBeNull] ISpectatorPlayerClock clock)
|
||||||
=> clock?.IsRunning == true && !clock.IsCatchingUp && !clock.WaitingOnFrames.Value;
|
=> clock?.IsRunning == true && !clock.IsCatchingUp && !clock.WaitingOnFrames.Value;
|
||||||
|
|
||||||
|
private void onReadyToStart()
|
||||||
|
{
|
||||||
|
var startTime = instances.Where(i => i.Score != null)
|
||||||
|
.SelectMany(i => i.Score.Replay.Frames)
|
||||||
|
.Select(f => f.Time)
|
||||||
|
.DefaultIfEmpty(0)
|
||||||
|
.Max();
|
||||||
|
|
||||||
|
masterClockContainer.Seek(startTime);
|
||||||
|
masterClockContainer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnUserStateChanged(int userId, SpectatorState spectatorState)
|
protected override void OnUserStateChanged(int userId, SpectatorState spectatorState)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user