Fix too many event rows displaying after spending a long time in gameplay/results

This commit is contained in:
Dean Herbert 2024-07-25 14:28:09 +09:00
parent c90d345ff9
commit f1dda4ab1e
No known key found for this signature in database
2 changed files with 46 additions and 11 deletions

View File

@ -6,6 +6,7 @@
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.Overlays;
@ -17,14 +18,14 @@ namespace osu.Game.Tests.Visual.DailyChallenge
{
public partial class TestSceneDailyChallengeEventFeed : OsuTestScene
{
private DailyChallengeEventFeed feed = null!;
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
[Test]
public void TestBasicAppearance()
[SetUpSteps]
public void SetUpSteps()
{
DailyChallengeEventFeed feed = null!;
AddStep("create content", () => Children = new Drawable[]
{
new Box
@ -40,6 +41,7 @@ public void TestBasicAppearance()
Origin = Anchor.Centre,
}
});
AddSliderStep("adjust width", 0.1f, 1, 1, width =>
{
if (feed.IsNotNull())
@ -50,7 +52,11 @@ public void TestBasicAppearance()
if (feed.IsNotNull())
feed.Height = height;
});
}
[Test]
public void TestBasicAppearance()
{
AddRepeatStep("add normal score", () =>
{
var ev = new NewScoreEvent(1, new APIUser
@ -90,5 +96,24 @@ public void TestBasicAppearance()
feed.AddNewScore(ev);
}, 50);
}
[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);
feed.AddNewScore(ev);
}
});
}
}
}

View File

@ -22,6 +22,8 @@ public partial class DailyChallengeEventFeed : CompositeDrawable
public Action<long>? PresentScore { get; init; }
private readonly Queue<NewScoreEvent> newScores = new Queue<NewScoreEvent>();
[BackgroundDependencyLoader]
private void load()
{
@ -47,19 +49,27 @@ private void load()
public void AddNewScore(NewScoreEvent newScoreEvent)
{
var row = new NewScoreEventRow(newScoreEvent)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
PresentScore = PresentScore,
};
flow.Add(row);
newScores.Enqueue(newScoreEvent);
// ensure things don't get too out-of-hand.
if (newScores.Count > 25)
newScores.Dequeue();
}
protected override void Update()
{
base.Update();
while (newScores.TryDequeue(out var newScore))
{
flow.Add(new NewScoreEventRow(newScore)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
PresentScore = PresentScore,
});
}
for (int i = 0; i < flow.Count; ++i)
{
var row = flow[i];