1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 04:22:55 +08:00

Merge pull request #29688 from peppy/fix-song-select-allocs

Fix per-frame allocations in `BeatmapCarousel`
This commit is contained in:
Dan Balasescu 2024-09-04 17:16:10 +09:00 committed by GitHub
commit 337a30f3b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 7 deletions

View File

@ -153,8 +153,22 @@ namespace osu.Game.Overlays
{
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);

View File

@ -857,8 +857,9 @@ namespace osu.Game.Screens.Select
// 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);
@ -900,8 +901,8 @@ namespace osu.Game.Screens.Select
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);
}
}
}
@ -1101,7 +1102,7 @@ namespace osu.Game.Screens.Select
}
/// <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>

View File

@ -51,7 +51,7 @@ namespace osu.Game.Screens.Select.Carousel
[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;
private Container<DrawableCarouselItem>? beatmapContainer;