1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 13:22:55 +08:00

Add testing setup to get a better visual idea of how scoreboard will work

fixup! Add method to ScoreProcessor to calculate score and accuracy from statistics
This commit is contained in:
Dean Herbert 2020-12-16 15:26:03 +09:00
parent d009a0be51
commit 09d0ceb766
2 changed files with 85 additions and 28 deletions

View File

@ -2,14 +2,18 @@
// 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;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Database; using osu.Framework.Utils;
using osu.Game.Online.API;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
@ -17,7 +21,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestSceneSpectatorDrivenLeaderboard : OsuTestScene public class TestSceneSpectatorDrivenLeaderboard : OsuTestScene
{ {
[Cached(typeof(SpectatorStreamingClient))] [Cached(typeof(SpectatorStreamingClient))]
private TestSceneSpectator.TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSceneSpectator.TestSpectatorStreamingClient(); private TestMultiplayerStreaming streamingClient = new TestMultiplayerStreaming(16);
// used just to show beatmap card for the time being. // used just to show beatmap card for the time being.
protected override bool UseOnlineAPI => true; protected override bool UseOnlineAPI => true;
@ -27,7 +31,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
OsuScoreProcessor scoreProcessor; OsuScoreProcessor scoreProcessor;
testSpectatorStreamingClient.StartPlay(55); streamingClient.Start(Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
Children = new Drawable[] Children = new Drawable[]
{ {
@ -38,37 +42,90 @@ namespace osu.Game.Tests.Visual.Gameplay
Origin = Anchor.Centre, Origin = Anchor.Centre,
} }
}; };
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
scoreProcessor.ApplyBeatmap(playable);
});
[Test]
public void TestScoreUpdates()
{
AddRepeatStep("update state", () => streamingClient.RandomlyUpdateState(), 100);
}
public class TestMultiplayerStreaming : SpectatorStreamingClient
{
public new BindableList<int> PlayingUsers => (BindableList<int>)base.PlayingUsers;
private readonly int totalUsers;
public TestMultiplayerStreaming(int totalUsers)
{
this.totalUsers = totalUsers;
}
public void Start(int beatmapId)
{
for (int i = 0; i < totalUsers; i++)
{
((ISpectatorClient)this).UserBeganPlaying(i, new SpectatorState
{
BeatmapID = beatmapId,
RulesetID = 0,
});
}
}
private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>();
public void RandomlyUpdateState()
{
foreach (var userId in PlayingUsers)
{
if (RNG.Next(0, 1) == 1)
continue;
if (!lastHeaders.TryGetValue(userId, out var header))
{
lastHeaders[userId] = header = new FrameHeader(new ScoreInfo
{
Statistics = new Dictionary<HitResult, int>(new[]
{
new KeyValuePair<HitResult, int>(HitResult.Miss, 0),
new KeyValuePair<HitResult, int>(HitResult.Meh, 0),
new KeyValuePair<HitResult, int>(HitResult.Great, 0)
})
}); });
} }
public class MultiplayerGameplayLeaderboard : GameplayLeaderboard switch (RNG.Next(0, 3))
{ {
private readonly OsuScoreProcessor scoreProcessor; case 0:
header.Combo = 0;
header.Statistics[HitResult.Miss]++;
break;
public MultiplayerGameplayLeaderboard(OsuScoreProcessor scoreProcessor) case 1:
{ header.Combo++;
this.scoreProcessor = scoreProcessor; header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
header.Statistics[HitResult.Meh]++;
break;
AddPlayer(new BindableDouble(), new GuestUser()); default:
header.Combo++;
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
header.Statistics[HitResult.Great]++;
break;
} }
[Resolved] ((ISpectatorClient)this).UserSentFrames(userId, new FrameDataBundle(header, Array.Empty<LegacyReplayFrame>()));
private SpectatorStreamingClient streamingClient { get; set; }
[Resolved]
private UserLookupCache userLookupCache { get; set; }
[BackgroundDependencyLoader]
private void load()
{
Console.WriteLine("got here");
foreach (var user in streamingClient.PlayingUsers)
{
streamingClient.WatchUser(user);
var resolvedUser = userLookupCache.GetUserAsync(user).Result;
AddPlayer(new BindableDouble(), resolvedUser);
} }
} }
protected override Task Connect() => Task.CompletedTask;
}
} }
} }

View File

@ -2,7 +2,6 @@
// 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -90,7 +89,8 @@ namespace osu.Game.Screens.Play.HUD
if (LastHeader == null) if (LastHeader == null)
return; return;
(Score.Value, Accuracy.Value) = processor.GetScoreAndAccuracy(mode, LastHeader.MaxCombo, LastHeader.Statistics.ToDictionary(s => s.Result, s => s.Count)); (Score.Value, Accuracy.Value) = processor.GetScoreAndAccuracy(mode, LastHeader.MaxCombo, LastHeader.Statistics);
CurrentCombo.Value = LastHeader.Combo; CurrentCombo.Value = LastHeader.Combo;
} }
} }