Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix per-frame allocations in BeatmapCarousel #29688

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions osu.Game/Overlays/NotificationOverlayToastTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,22 @@ protected override void Update()
{
base.Update();

float height = toastFlow.Count > 0 ? toastFlow.DrawHeight + 120 : 0;
float alpha = toastFlow.Count > 0 ? MathHelper.Clamp(toastFlow.DrawHeight / 41, 0, 1) * toastFlow.Children.Max(n => n.Alpha) : 0;
float height = 0;
float alpha = 0;

if (toastFlow.Count > 0)
{
float maxNotificationAlpha = 0;

foreach (var t in toastFlow)
{
if (t.Alpha > maxNotificationAlpha)
maxNotificationAlpha = t.Alpha;
}

height = toastFlow.DrawHeight + 120;
alpha = MathHelper.Clamp(toastFlow.DrawHeight / 41, 0, 1) * maxNotificationAlpha;
}

toastContentBackground.Height = (float)Interpolation.DampContinuously(toastContentBackground.Height, height, 10, Clock.ElapsedFrameTime);
toastContentBackground.Alpha = (float)Interpolation.DampContinuously(toastContentBackground.Alpha, alpha, 10, Clock.ElapsedFrameTime);
Expand Down
9 changes: 5 additions & 4 deletions osu.Game/Screens/Select/BeatmapCarousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,9 @@ protected override void Update()
// Add those items within the previously found index range that should be displayed.
foreach (var item in toDisplay)
{
var panel = setPool.Get(p => p.Item = item);
var panel = setPool.Get();

panel.Item = item;
panel.Y = item.CarouselYPosition;

Scroll.Add(panel);
Expand Down Expand Up @@ -900,8 +901,8 @@ protected override void Update()

if (item is DrawableCarouselBeatmapSet set)
{
foreach (var diff in set.DrawableBeatmaps)
updateItem(diff, item);
for (int i = 0; i < set.DrawableBeatmaps.Count; i++)
updateItem(set.DrawableBeatmaps[i], item);
}
}
}
Expand Down Expand Up @@ -1101,7 +1102,7 @@ private static float offsetX(float dist, float halfHeight)
}

/// <summary>
/// Update a item's x position and multiplicative alpha based on its y position and
/// Update an item's x position and multiplicative alpha based on its y position and
/// the current scroll position.
/// </summary>
/// <param name="item">The item to be updated.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public partial class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasCont
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } = null!;

public IEnumerable<DrawableCarouselItem> DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Enumerable.Empty<DrawableCarouselItem>() : beatmapContainer.AliveChildren;
public IReadOnlyList<DrawableCarouselItem> DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Array.Empty<DrawableCarouselItem>() : beatmapContainer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't immediately tell if the AliveChildren to Children swap here is correct but I don't think we do any lifetime games in song select so I think it should be

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it seemed fine. Worst case it's just setting some values when not required, but it's worth the alloc saving.


private Container<DrawableCarouselItem>? beatmapContainer;

Expand Down
Loading