mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 03:33:20 +08:00
Fix per-frame allocations in BeatmapCarousel
This commit is contained in:
parent
1f122ab38d
commit
421f245c31
@ -1405,9 +1405,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
yield return item;
|
yield return item;
|
||||||
|
|
||||||
if (item is DrawableCarouselBeatmapSet set)
|
if (item is DrawableCarouselBeatmapSet set && set.Beatmaps?.IsLoaded == true)
|
||||||
{
|
{
|
||||||
foreach (var difficulty in set.DrawableBeatmaps)
|
foreach (var difficulty in set.Beatmaps)
|
||||||
yield return difficulty;
|
yield return difficulty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -857,8 +857,9 @@ namespace osu.Game.Screens.Select
|
|||||||
// Add those items within the previously found index range that should be displayed.
|
// Add those items within the previously found index range that should be displayed.
|
||||||
foreach (var item in toDisplay)
|
foreach (var item in toDisplay)
|
||||||
{
|
{
|
||||||
var panel = setPool.Get(p => p.Item = item);
|
var panel = setPool.Get();
|
||||||
|
|
||||||
|
panel.Item = item;
|
||||||
panel.Y = item.CarouselYPosition;
|
panel.Y = item.CarouselYPosition;
|
||||||
|
|
||||||
Scroll.Add(panel);
|
Scroll.Add(panel);
|
||||||
@ -898,10 +899,12 @@ namespace osu.Game.Screens.Select
|
|||||||
Scroll.ChangeChildDepth(item, hasPassedSelection ? -item.Item.CarouselYPosition : item.Item.CarouselYPosition);
|
Scroll.ChangeChildDepth(item, hasPassedSelection ? -item.Item.CarouselYPosition : item.Item.CarouselYPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item is DrawableCarouselBeatmapSet set)
|
if (item is DrawableCarouselBeatmapSet set && set.Beatmaps?.IsLoaded == true)
|
||||||
{
|
{
|
||||||
foreach (var diff in set.DrawableBeatmaps)
|
foreach (var diff in set.Beatmaps)
|
||||||
|
{
|
||||||
updateItem(diff, item);
|
updateItem(diff, item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1101,7 +1104,7 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// the current scroll position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item to be updated.</param>
|
/// <param name="item">The item to be updated.</param>
|
||||||
|
@ -51,9 +51,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||||
|
|
||||||
public IEnumerable<DrawableCarouselItem> DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Enumerable.Empty<DrawableCarouselItem>() : beatmapContainer.AliveChildren;
|
public Container<DrawableCarouselItem>? Beatmaps;
|
||||||
|
|
||||||
private Container<DrawableCarouselItem>? beatmapContainer;
|
|
||||||
|
|
||||||
private BeatmapSetInfo beatmapSet = null!;
|
private BeatmapSetInfo beatmapSet = null!;
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
Content.Clear();
|
Content.Clear();
|
||||||
Header.Clear();
|
Header.Clear();
|
||||||
|
|
||||||
beatmapContainer = null;
|
Beatmaps = null;
|
||||||
beatmapsLoadTask = null;
|
beatmapsLoadTask = null;
|
||||||
|
|
||||||
if (Item == null)
|
if (Item == null)
|
||||||
@ -164,7 +162,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
// if we are already displaying all the correct beatmaps, only run animation updates.
|
// if we are already displaying all the correct beatmaps, only run animation updates.
|
||||||
// note that the displayed beatmaps may change due to the applied filter.
|
// note that the displayed beatmaps may change due to the applied filter.
|
||||||
// a future optimisation could add/remove only changed difficulties rather than reinitialise.
|
// a future optimisation could add/remove only changed difficulties rather than reinitialise.
|
||||||
if (beatmapContainer != null && visibleBeatmaps.Length == beatmapContainer.Count && visibleBeatmaps.All(b => beatmapContainer.Any(c => c.Item == b)))
|
if (Beatmaps != null && visibleBeatmaps.Length == Beatmaps.Count && visibleBeatmaps.All(b => Beatmaps.Any(c => c.Item == b)))
|
||||||
{
|
{
|
||||||
updateBeatmapYPositions();
|
updateBeatmapYPositions();
|
||||||
}
|
}
|
||||||
@ -173,17 +171,17 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
// on selection we show our child beatmaps.
|
// on selection we show our child beatmaps.
|
||||||
// for now this is a simple drawable construction each selection.
|
// for now this is a simple drawable construction each selection.
|
||||||
// can be improved in the future.
|
// can be improved in the future.
|
||||||
beatmapContainer = new Container<DrawableCarouselItem>
|
Beatmaps = new Container<DrawableCarouselItem>
|
||||||
{
|
{
|
||||||
X = 100,
|
X = 100,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation()!)
|
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation()!)
|
||||||
};
|
};
|
||||||
|
|
||||||
beatmapsLoadTask = LoadComponentAsync(beatmapContainer, loaded =>
|
beatmapsLoadTask = LoadComponentAsync(Beatmaps, loaded =>
|
||||||
{
|
{
|
||||||
// make sure the pooled target hasn't changed.
|
// make sure the pooled target hasn't changed.
|
||||||
if (beatmapContainer != loaded)
|
if (Beatmaps != loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Content.Child = loaded;
|
Content.Child = loaded;
|
||||||
@ -244,7 +242,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
private void updateBeatmapYPositions()
|
private void updateBeatmapYPositions()
|
||||||
{
|
{
|
||||||
if (beatmapContainer == null)
|
if (Beatmaps == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (beatmapsLoadTask == null || !beatmapsLoadTask.IsCompleted)
|
if (beatmapsLoadTask == null || !beatmapsLoadTask.IsCompleted)
|
||||||
@ -254,7 +252,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
bool isSelected = Item?.State.Value == CarouselItemState.Selected;
|
bool isSelected = Item?.State.Value == CarouselItemState.Selected;
|
||||||
|
|
||||||
foreach (var panel in beatmapContainer)
|
foreach (var panel in Beatmaps)
|
||||||
{
|
{
|
||||||
Debug.Assert(panel.Item != null);
|
Debug.Assert(panel.Item != null);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user