mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 03:22:55 +08:00
Fix multiplayer leaderboard not working
This commit is contained in:
parent
8b56a3f87d
commit
035d0d5c9c
@ -14,6 +14,7 @@ using osu.Game.Rulesets;
|
|||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
using osu.Game.Scoring.Legacy;
|
||||||
|
|
||||||
namespace osu.Game.Online.Spectator
|
namespace osu.Game.Online.Spectator
|
||||||
{
|
{
|
||||||
@ -46,7 +47,9 @@ namespace osu.Game.Online.Spectator
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The applied <see cref="Mod"/>s.
|
/// The applied <see cref="Mod"/>s.
|
||||||
/// </summary>
|
/// </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;
|
private IClock? referenceClock;
|
||||||
|
|
||||||
@ -70,7 +73,6 @@ namespace osu.Game.Online.Spectator
|
|||||||
private readonly int userId;
|
private readonly int userId;
|
||||||
|
|
||||||
private SpectatorState? spectatorState;
|
private SpectatorState? spectatorState;
|
||||||
private ScoreProcessor? scoreProcessor;
|
|
||||||
private ScoreInfo? scoreInfo;
|
private ScoreInfo? scoreInfo;
|
||||||
|
|
||||||
public SpectatorScoreProcessor(int userId)
|
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)
|
if (!spectatorStates.TryGetValue(userId, out var userState) || userState.BeatmapID == null || userState.RulesetID == null)
|
||||||
{
|
{
|
||||||
scoreProcessor?.RemoveAndDisposeImmediately();
|
|
||||||
scoreProcessor = null;
|
|
||||||
scoreInfo = null;
|
scoreInfo = null;
|
||||||
spectatorState = null;
|
spectatorState = null;
|
||||||
replayFrames.Clear();
|
replayFrames.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scoreProcessor != null)
|
if (scoreInfo != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Assert(scoreInfo == null);
|
|
||||||
|
|
||||||
RulesetInfo? rulesetInfo = rulesetStore.GetRuleset(userState.RulesetID.Value);
|
RulesetInfo? rulesetInfo = rulesetStore.GetRuleset(userState.RulesetID.Value);
|
||||||
if (rulesetInfo == null)
|
if (rulesetInfo == null)
|
||||||
return;
|
return;
|
||||||
@ -114,9 +112,11 @@ namespace osu.Game.Online.Spectator
|
|||||||
Ruleset ruleset = rulesetInfo.CreateInstance();
|
Ruleset ruleset = rulesetInfo.CreateInstance();
|
||||||
|
|
||||||
spectatorState = userState;
|
spectatorState = userState;
|
||||||
scoreInfo = new ScoreInfo { Ruleset = rulesetInfo };
|
scoreInfo = new ScoreInfo
|
||||||
scoreProcessor = ruleset.CreateScoreProcessor();
|
{
|
||||||
scoreProcessor.Mods.Value = userState.Mods.Select(m => m.ToMod(ruleset)).ToArray();
|
Ruleset = rulesetInfo,
|
||||||
|
Mods = userState.Mods.Select(m => m.ToMod(ruleset)).ToArray()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onNewFrames(int incomingUserId, FrameDataBundle bundle)
|
private void onNewFrames(int incomingUserId, FrameDataBundle bundle)
|
||||||
@ -126,7 +126,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
|
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
if (scoreProcessor == null)
|
if (scoreInfo == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
replayFrames.Add(new TimedFrame(bundle.Frames.First().Time, bundle.Header));
|
replayFrames.Add(new TimedFrame(bundle.Frames.First().Time, bundle.Header));
|
||||||
@ -140,7 +140,6 @@ namespace osu.Game.Online.Spectator
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Assert(spectatorState != null);
|
Debug.Assert(spectatorState != null);
|
||||||
Debug.Assert(scoreProcessor != null);
|
|
||||||
|
|
||||||
int frameIndex = replayFrames.BinarySearch(new TimedFrame(ReferenceClock.CurrentTime));
|
int frameIndex = replayFrames.BinarySearch(new TimedFrame(ReferenceClock.CurrentTime));
|
||||||
if (frameIndex < 0)
|
if (frameIndex < 0)
|
||||||
@ -150,6 +149,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
TimedFrame frame = replayFrames[frameIndex];
|
TimedFrame frame = replayFrames[frameIndex];
|
||||||
Debug.Assert(frame.Header != null);
|
Debug.Assert(frame.Header != null);
|
||||||
|
|
||||||
|
scoreInfo.Accuracy = frame.Header.Accuracy;
|
||||||
scoreInfo.MaxCombo = frame.Header.MaxCombo;
|
scoreInfo.MaxCombo = frame.Header.MaxCombo;
|
||||||
scoreInfo.Statistics = frame.Header.Statistics;
|
scoreInfo.Statistics = frame.Header.Statistics;
|
||||||
scoreInfo.MaximumStatistics = spectatorState.MaximumStatistics;
|
scoreInfo.MaximumStatistics = spectatorState.MaximumStatistics;
|
||||||
@ -157,6 +157,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
|
|
||||||
Accuracy.Value = frame.Header.Accuracy;
|
Accuracy.Value = frame.Header.Accuracy;
|
||||||
Combo.Value = frame.Header.Combo;
|
Combo.Value = frame.Header.Combo;
|
||||||
|
TotalScore.Value = frame.Header.TotalScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -98,6 +98,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
var trackedUser = UserScores[user.Id];
|
var trackedUser = UserScores[user.Id];
|
||||||
|
|
||||||
var leaderboardScore = Add(user, user.Id == api.LocalUser.Value.Id);
|
var leaderboardScore = Add(user, user.Id == api.LocalUser.Value.Id);
|
||||||
|
leaderboardScore.GetDisplayScore = trackedUser.ScoreProcessor.GetDisplayScore;
|
||||||
leaderboardScore.Accuracy.BindTo(trackedUser.ScoreProcessor.Accuracy);
|
leaderboardScore.Accuracy.BindTo(trackedUser.ScoreProcessor.Accuracy);
|
||||||
leaderboardScore.TotalScore.BindTo(trackedUser.ScoreProcessor.TotalScore);
|
leaderboardScore.TotalScore.BindTo(trackedUser.ScoreProcessor.TotalScore);
|
||||||
leaderboardScore.Combo.BindTo(trackedUser.ScoreProcessor.Combo);
|
leaderboardScore.Combo.BindTo(trackedUser.ScoreProcessor.Combo);
|
||||||
|
Loading…
Reference in New Issue
Block a user