1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Fix multiplayer leaderboard not working

This commit is contained in:
Dan Balasescu 2023-05-19 13:16:57 +09:00
parent 8b56a3f87d
commit 035d0d5c9c
2 changed files with 14 additions and 12 deletions

View File

@ -14,6 +14,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Scoring.Legacy;
namespace osu.Game.Online.Spectator
{
@ -46,7 +47,9 @@ namespace osu.Game.Online.Spectator
/// <summary>
/// The applied <see cref="Mod"/>s.
/// </summary>
public IReadOnlyList<Mod> Mods => scoreProcessor?.Mods.Value ?? Array.Empty<Mod>();
public IReadOnlyList<Mod> Mods => scoreInfo?.Mods ?? Array.Empty<Mod>();
public Func<ScoringMode, long> GetDisplayScore => mode => scoreInfo?.GetDisplayScore(mode) ?? 0;
private IClock? referenceClock;
@ -70,7 +73,6 @@ namespace osu.Game.Online.Spectator
private readonly int userId;
private SpectatorState? spectatorState;
private ScoreProcessor? scoreProcessor;
private ScoreInfo? scoreInfo;
public SpectatorScoreProcessor(int userId)
@ -94,19 +96,15 @@ namespace osu.Game.Online.Spectator
{
if (!spectatorStates.TryGetValue(userId, out var userState) || userState.BeatmapID == null || userState.RulesetID == null)
{
scoreProcessor?.RemoveAndDisposeImmediately();
scoreProcessor = null;
scoreInfo = null;
spectatorState = null;
replayFrames.Clear();
return;
}
if (scoreProcessor != null)
if (scoreInfo != null)
return;
Debug.Assert(scoreInfo == null);
RulesetInfo? rulesetInfo = rulesetStore.GetRuleset(userState.RulesetID.Value);
if (rulesetInfo == null)
return;
@ -114,9 +112,11 @@ namespace osu.Game.Online.Spectator
Ruleset ruleset = rulesetInfo.CreateInstance();
spectatorState = userState;
scoreInfo = new ScoreInfo { Ruleset = rulesetInfo };
scoreProcessor = ruleset.CreateScoreProcessor();
scoreProcessor.Mods.Value = userState.Mods.Select(m => m.ToMod(ruleset)).ToArray();
scoreInfo = new ScoreInfo
{
Ruleset = rulesetInfo,
Mods = userState.Mods.Select(m => m.ToMod(ruleset)).ToArray()
};
}
private void onNewFrames(int incomingUserId, FrameDataBundle bundle)
@ -126,7 +126,7 @@ namespace osu.Game.Online.Spectator
Schedule(() =>
{
if (scoreProcessor == null)
if (scoreInfo == null)
return;
replayFrames.Add(new TimedFrame(bundle.Frames.First().Time, bundle.Header));
@ -140,7 +140,6 @@ namespace osu.Game.Online.Spectator
return;
Debug.Assert(spectatorState != null);
Debug.Assert(scoreProcessor != null);
int frameIndex = replayFrames.BinarySearch(new TimedFrame(ReferenceClock.CurrentTime));
if (frameIndex < 0)
@ -150,6 +149,7 @@ namespace osu.Game.Online.Spectator
TimedFrame frame = replayFrames[frameIndex];
Debug.Assert(frame.Header != null);
scoreInfo.Accuracy = frame.Header.Accuracy;
scoreInfo.MaxCombo = frame.Header.MaxCombo;
scoreInfo.Statistics = frame.Header.Statistics;
scoreInfo.MaximumStatistics = spectatorState.MaximumStatistics;
@ -157,6 +157,7 @@ namespace osu.Game.Online.Spectator
Accuracy.Value = frame.Header.Accuracy;
Combo.Value = frame.Header.Combo;
TotalScore.Value = frame.Header.TotalScore;
}
protected override void Dispose(bool isDisposing)

View File

@ -98,6 +98,7 @@ namespace osu.Game.Screens.Play.HUD
var trackedUser = UserScores[user.Id];
var leaderboardScore = Add(user, user.Id == api.LocalUser.Value.Id);
leaderboardScore.GetDisplayScore = trackedUser.ScoreProcessor.GetDisplayScore;
leaderboardScore.Accuracy.BindTo(trackedUser.ScoreProcessor.Accuracy);
leaderboardScore.TotalScore.BindTo(trackedUser.ScoreProcessor.TotalScore);
leaderboardScore.Combo.BindTo(trackedUser.ScoreProcessor.Combo);