1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:58:21 +08:00

Add header class and basic flow for propagating data updates

This commit is contained in:
Dean Herbert 2020-12-14 17:33:23 +09:00
parent 1793385e96
commit 64a2526678
5 changed files with 55 additions and 5 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Users;
@ -272,7 +273,7 @@ namespace osu.Game.Tests.Visual.Gameplay
frames.Add(new LegacyReplayFrame(i * 100, RNG.Next(0, 512), RNG.Next(0, 512), buttonState));
}
var bundle = new FrameDataBundle(frames);
var bundle = new FrameDataBundle(new ScoreInfo(), frames);
((ISpectatorClient)this).UserSentFrames(StreamingUser.Id, bundle);
if (!sentState)

View File

@ -1,20 +1,26 @@
// 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 System.Collections.Generic;
using osu.Game.Replays.Legacy;
using osu.Game.Scoring;
namespace osu.Game.Online.Spectator
{
[Serializable]
public class FrameDataBundle
{
public FrameHeader Header { get; set; }
public IEnumerable<LegacyReplayFrame> Frames { get; set; }
public FrameDataBundle(IEnumerable<LegacyReplayFrame> frames)
public FrameDataBundle(ScoreInfo score, IEnumerable<LegacyReplayFrame> frames)
{
Frames = frames;
Header = new FrameHeader(score);
}
}
}

View File

@ -0,0 +1,35 @@
// 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 System.Collections.Generic;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
namespace osu.Game.Online.Spectator
{
[Serializable]
public class FrameHeader
{
public int Combo { get; set; }
public int MaxCombo { get; set; }
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>();
/// <summary>
/// Construct header summary information from a point-in-time reference to a score which is actively being played.
/// </summary>
/// <param name="score">The score for reference.</param>
public FrameHeader(ScoreInfo score)
{
Combo = score.Combo;
MaxCombo = score.MaxCombo;
foreach (var kvp in score.Statistics)
Statistics[kvp.Key] = kvp.Value;
}
}
}

View File

@ -21,6 +21,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
namespace osu.Game.Online.Spectator
@ -52,6 +53,9 @@ namespace osu.Game.Online.Spectator
[CanBeNull]
private IBeatmap currentBeatmap;
[CanBeNull]
private Score currentScore;
[Resolved]
private IBindable<RulesetInfo> currentRuleset { get; set; }
@ -203,7 +207,7 @@ namespace osu.Game.Online.Spectator
return Task.CompletedTask;
}
public void BeginPlaying(GameplayBeatmap beatmap)
public void BeginPlaying(GameplayBeatmap beatmap, Score score)
{
if (isPlaying)
throw new InvalidOperationException($"Cannot invoke {nameof(BeginPlaying)} when already playing");
@ -216,6 +220,8 @@ namespace osu.Game.Online.Spectator
currentState.Mods = currentMods.Value.Select(m => new APIMod(m));
currentBeatmap = beatmap.PlayableBeatmap;
currentScore = score;
beginPlaying();
}
@ -308,7 +314,9 @@ namespace osu.Game.Online.Spectator
pendingFrames.Clear();
SendFrames(new FrameDataBundle(frames));
Debug.Assert(currentScore != null);
SendFrames(new FrameDataBundle(currentScore.ScoreInfo, frames));
lastSendTime = Time.Current;
}

View File

@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.UI
inputManager = GetContainingInputManager();
spectatorStreaming?.BeginPlaying(gameplayBeatmap);
spectatorStreaming?.BeginPlaying(gameplayBeatmap, target);
}
protected override void Dispose(bool isDisposing)