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

Fix potentially too many scores displaying in breakdown while in gameplay

This commit is contained in:
Dean Herbert 2024-07-29 20:58:42 +09:00
parent 05056f0e8a
commit 7afcd72872
No known key found for this signature in database
2 changed files with 62 additions and 10 deletions

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms;
@ -20,11 +21,11 @@ namespace osu.Game.Tests.Visual.DailyChallenge
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
[Test]
public void TestBasicAppearance()
{
DailyChallengeScoreBreakdown breakdown = null!;
private DailyChallengeScoreBreakdown breakdown = null!;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create content", () => Children = new Drawable[]
{
new Box
@ -53,6 +54,11 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AddToggleStep("toggle visible", v => breakdown.Alpha = v ? 1 : 0);
AddStep("set initial data", () => breakdown.SetInitialCounts([1, 4, 9, 16, 25, 36, 49, 36, 25, 16, 9, 4, 1]));
}
[Test]
public void TestBasicAppearance()
{
AddStep("add new score", () =>
{
var ev = new NewScoreEvent(1, new APIUser
@ -67,5 +73,24 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AddStep("set user score", () => breakdown.UserBestScore.Value = new MultiplayerScore { TotalScore = RNG.Next(1_000_000) });
AddStep("unset user score", () => breakdown.UserBestScore.Value = null);
}
[Test]
public void TestMassAdd()
{
AddStep("add 1000 scores at once", () =>
{
for (int i = 0; i < 1000; i++)
{
var ev = new NewScoreEvent(1, new APIUser
{
Id = 2,
Username = "peppy",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
}, RNG.Next(1_000_000), null);
breakdown.AddNewScore(ev);
}
});
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -67,18 +68,39 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
});
}
private readonly Queue<NewScoreEvent> newScores = new Queue<NewScoreEvent>();
public void AddNewScore(NewScoreEvent newScoreEvent)
{
int targetBin = (int)Math.Clamp(Math.Floor((float)newScoreEvent.TotalScore / 100000), 0, bin_count - 1);
bins[targetBin] += 1;
newScores.Enqueue(newScoreEvent);
Scheduler.AddOnce(updateCounts);
if (Alpha > 0)
// ensure things don't get too out-of-hand.
if (newScores.Count > 25)
{
bins[getTargetBin(newScores.Dequeue())] += 1;
Scheduler.AddOnce(updateCounts);
}
}
private double lastScoreDisplay;
protected override void Update()
{
base.Update();
if (Time.Current - lastScoreDisplay > 150 && newScores.TryDequeue(out var newScore))
{
if (lastScoreDisplay < Time.Current)
lastScoreDisplay = Time.Current;
int targetBin = getTargetBin(newScore);
bins[targetBin] += 1;
updateCounts();
var text = new OsuSpriteText
{
Text = newScoreEvent.TotalScore.ToString(@"N0"),
Text = newScore.TotalScore.ToString(@"N0"),
Anchor = Anchor.TopCentre,
Origin = Anchor.BottomCentre,
Font = OsuFont.Default.With(size: 30),
@ -98,6 +120,8 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
.FadeOut(2500, Easing.OutQuint)
.Expire();
}, 150);
lastScoreDisplay = Time.Current;
}
}
@ -110,6 +134,9 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
updateCounts();
}
private static int getTargetBin(NewScoreEvent score) =>
(int)Math.Clamp(Math.Floor((float)score.TotalScore / 100000), 0, bin_count - 1);
private void updateCounts()
{
long max = Math.Max(bins.Max(), 1);