2020-12-16 12:00:19 +08:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System;
|
2020-12-16 14:26:03 +08:00
|
|
|
using System.Collections.Generic;
|
2020-12-16 15:05:46 +08:00
|
|
|
using System.Linq;
|
2020-12-16 12:00:19 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2020-12-17 15:02:06 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
2020-12-16 14:26:03 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-04-12 21:03:45 +08:00
|
|
|
using osu.Game.Configuration;
|
2020-12-16 14:53:05 +08:00
|
|
|
using osu.Game.Database;
|
2020-12-24 16:58:38 +08:00
|
|
|
using osu.Game.Online;
|
2021-02-19 14:15:31 +08:00
|
|
|
using osu.Game.Online.API;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Game.Online.Spectator;
|
2020-12-16 14:26:03 +08:00
|
|
|
using osu.Game.Replays.Legacy;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Scoring;
|
2020-12-16 14:26:03 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Scoring;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2020-12-16 14:53:05 +08:00
|
|
|
using osu.Game.Tests.Visual.Online;
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-28 19:31:08 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-26 10:34:05 +08:00
|
|
|
public class TestSceneMultiplayerGameplayLeaderboard : MultiplayerTestScene
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-26 11:11:19 +08:00
|
|
|
private const int users = 16;
|
|
|
|
|
2020-12-16 12:00:19 +08:00
|
|
|
[Cached(typeof(SpectatorStreamingClient))]
|
2020-12-26 11:11:19 +08:00
|
|
|
private TestMultiplayerStreaming streamingClient = new TestMultiplayerStreaming(users);
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:53:05 +08:00
|
|
|
[Cached(typeof(UserLookupCache))]
|
|
|
|
private UserLookupCache lookupCache = new TestSceneCurrentlyPlayingDisplay.TestUserLookupCache();
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
private MultiplayerGameplayLeaderboard leaderboard;
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2021-04-12 21:03:45 +08:00
|
|
|
private OsuConfigManager config;
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
public TestSceneMultiplayerGameplayLeaderboard()
|
|
|
|
{
|
|
|
|
base.Content.Children = new Drawable[]
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-16 14:53:05 +08:00
|
|
|
streamingClient,
|
|
|
|
lookupCache,
|
2020-12-17 15:02:06 +08:00
|
|
|
Content
|
2020-12-16 12:00:19 +08:00
|
|
|
};
|
2020-12-17 15:02:06 +08:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:03:45 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Dependencies.Cache(config = new OsuConfigManager(LocalStorage));
|
|
|
|
}
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
[SetUpSteps]
|
2020-12-26 10:34:05 +08:00
|
|
|
public override void SetUpSteps()
|
2020-12-17 15:02:06 +08:00
|
|
|
{
|
2021-02-19 14:15:31 +08:00
|
|
|
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = lookupCache.GetUserAsync(1).Result);
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
AddStep("create leaderboard", () =>
|
|
|
|
{
|
2020-12-26 16:55:24 +08:00
|
|
|
leaderboard?.Expire();
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
OsuScoreProcessor scoreProcessor;
|
|
|
|
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
|
|
|
|
|
|
|
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
2020-12-16 14:26:03 +08:00
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
streamingClient.Start(Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
|
2020-12-16 14:26:03 +08:00
|
|
|
|
2020-12-29 13:27:33 +08:00
|
|
|
Client.CurrentMatchPlayingUserIds.Clear();
|
|
|
|
Client.CurrentMatchPlayingUserIds.AddRange(streamingClient.PlayingUsers);
|
2020-12-26 11:11:19 +08:00
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
scoreProcessor = new OsuScoreProcessor(),
|
|
|
|
};
|
2020-12-16 14:26:03 +08:00
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
scoreProcessor.ApplyBeatmap(playable);
|
|
|
|
|
|
|
|
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(scoreProcessor, streamingClient.PlayingUsers.ToArray())
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
}, Add);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
[Test]
|
|
|
|
public void TestScoreUpdates()
|
|
|
|
{
|
|
|
|
AddRepeatStep("update state", () => streamingClient.RandomlyUpdateState(), 100);
|
2021-02-19 14:09:41 +08:00
|
|
|
AddToggleStep("switch compact mode", expanded => leaderboard.Expanded.Value = expanded);
|
2020-12-16 14:26:03 +08:00
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-26 11:11:19 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUserQuit()
|
|
|
|
{
|
2020-12-29 13:27:33 +08:00
|
|
|
AddRepeatStep("mark user quit", () => Client.CurrentMatchPlayingUserIds.RemoveAt(0), users);
|
2020-12-26 11:11:19 +08:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:03:45 +08:00
|
|
|
[Test]
|
|
|
|
public void TestChangeScoringMode()
|
|
|
|
{
|
|
|
|
AddRepeatStep("update state", () => streamingClient.RandomlyUpdateState(), 5);
|
|
|
|
AddStep("change to classic", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Classic));
|
|
|
|
AddStep("change to standardised", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised));
|
|
|
|
}
|
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
public class TestMultiplayerStreaming : SpectatorStreamingClient
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-16 14:26:03 +08:00
|
|
|
public new BindableList<int> PlayingUsers => (BindableList<int>)base.PlayingUsers;
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
private readonly int totalUsers;
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
public TestMultiplayerStreaming(int totalUsers)
|
2020-12-24 16:58:38 +08:00
|
|
|
: base(new DevelopmentEndpointConfiguration())
|
2020-12-16 14:26:03 +08:00
|
|
|
{
|
|
|
|
this.totalUsers = totalUsers;
|
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
public void Start(int beatmapId)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < totalUsers; i++)
|
|
|
|
{
|
|
|
|
((ISpectatorClient)this).UserBeganPlaying(i, new SpectatorState
|
|
|
|
{
|
|
|
|
BeatmapID = beatmapId,
|
|
|
|
RulesetID = 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>();
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
public void RandomlyUpdateState()
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-16 14:26:03 +08:00
|
|
|
foreach (var userId in PlayingUsers)
|
|
|
|
{
|
2020-12-20 04:25:04 +08:00
|
|
|
if (RNG.NextBool())
|
2020-12-16 14:26:03 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!lastHeaders.TryGetValue(userId, out var header))
|
|
|
|
{
|
|
|
|
lastHeaders[userId] = header = new FrameHeader(new ScoreInfo
|
|
|
|
{
|
2020-12-20 04:26:40 +08:00
|
|
|
Statistics = new Dictionary<HitResult, int>
|
2020-12-16 14:26:03 +08:00
|
|
|
{
|
2020-12-20 04:26:40 +08:00
|
|
|
[HitResult.Miss] = 0,
|
|
|
|
[HitResult.Meh] = 0,
|
|
|
|
[HitResult.Great] = 0
|
|
|
|
}
|
2020-12-16 14:26:03 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
((ISpectatorClient)this).UserSentFrames(userId, new FrameDataBundle(header, new[] { new LegacyReplayFrame(Time.Current, 0, 0, ReplayButtonState.None) }));
|
2020-12-16 14:26:03 +08:00
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|