1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02: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.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Database;
using osu.Game.Online.API;
using osu.Framework.Utils;
using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Tests.Visual.Gameplay
@ -17,7 +21,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestSceneSpectatorDrivenLeaderboard : OsuTestScene
{
[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.
protected override bool UseOnlineAPI => true;
@ -27,7 +31,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
OsuScoreProcessor scoreProcessor;
testSpectatorStreamingClient.StartPlay(55);
streamingClient.Start(Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
Children = new Drawable[]
{
@ -38,37 +42,90 @@ namespace osu.Game.Tests.Visual.Gameplay
Origin = Anchor.Centre,
}
};
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
scoreProcessor.ApplyBeatmap(playable);
});
}
public class MultiplayerGameplayLeaderboard : GameplayLeaderboard
{
private readonly OsuScoreProcessor scoreProcessor;
public MultiplayerGameplayLeaderboard(OsuScoreProcessor scoreProcessor)
[Test]
public void TestScoreUpdates()
{
this.scoreProcessor = scoreProcessor;
AddPlayer(new BindableDouble(), new GuestUser());
AddRepeatStep("update state", () => streamingClient.RandomlyUpdateState(), 100);
}
[Resolved]
private SpectatorStreamingClient streamingClient { get; set; }
[Resolved]
private UserLookupCache userLookupCache { get; set; }
[BackgroundDependencyLoader]
private void load()
public class TestMultiplayerStreaming : SpectatorStreamingClient
{
Console.WriteLine("got here");
public new BindableList<int> PlayingUsers => (BindableList<int>)base.PlayingUsers;
foreach (var user in streamingClient.PlayingUsers)
private readonly int totalUsers;
public TestMultiplayerStreaming(int totalUsers)
{
streamingClient.WatchUser(user);
var resolvedUser = userLookupCache.GetUserAsync(user).Result;
AddPlayer(new BindableDouble(), resolvedUser);
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)
})
});
}
switch (RNG.Next(0, 3))
{
case 0:
header.Combo = 0;
header.Statistics[HitResult.Miss]++;
break;
case 1:
header.Combo++;
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
header.Statistics[HitResult.Meh]++;
break;
default:
header.Combo++;
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
header.Statistics[HitResult.Great]++;
break;
}
((ISpectatorClient)this).UserSentFrames(userId, new FrameDataBundle(header, Array.Empty<LegacyReplayFrame>()));
}
}
protected override Task Connect() => Task.CompletedTask;
}
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -90,7 +89,8 @@ namespace osu.Game.Screens.Play.HUD
if (LastHeader == null)
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;
}
}