Skip to content

Commit

Permalink
Fix too many event rows displaying after spending a long time in game…
Browse files Browse the repository at this point in the history
…play/results
  • Loading branch information
peppy committed Jul 25, 2024
1 parent 40e43c1 commit 1b9b84e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -40,6 +41,7 @@ public void TestBasicAppearance()
Origin = Anchor.Centre,
}
});

AddSliderStep("adjust width", 0.1f, 1, 1, width =>
{
if (feed.IsNotNull())
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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];
Expand Down

0 comments on commit 1b9b84e

Please sign in to comment.