Skip to content
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
21 changes: 17 additions & 4 deletions osu.Game/Graphics/Carousel/Carousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,26 @@ private void refreshAfterSelection()
{
var item = carouselItems[i];

bool isKeyboardSelection = CheckModelEquality(item.Model, currentKeyboardSelection.Model!);
Copy link
Member

Choose a reason for hiding this comment

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

A bit awkward but worth it for the huge performance boost.

bool isSelection = CheckModelEquality(item.Model, currentSelection.Model!);

// while we don't know the Y position of the item yet, as it's about to be updated,
// consumers (specifically `BeatmapCarousel.GetSpacingBetweenPanels()`) benefit from `CurrentSelectionItem` already pointing
// at the correct item to avoid redundant local equality checks.
// the Y positions will be filled in after they're computed.
if (isKeyboardSelection)
currentKeyboardSelection = new Selection(currentKeyboardSelection.Model, item, null, i);

if (isSelection)
currentSelection = new Selection(currentSelection.Model, item, null, i);

updateItemYPosition(item, ref lastVisible, ref yPos);

if (CheckModelEquality(item.Model, currentKeyboardSelection.Model!))
currentKeyboardSelection = new Selection(currentKeyboardSelection.Model, item, item.CarouselYPosition + item.DrawHeight / 2, i);
if (isKeyboardSelection)
currentKeyboardSelection = currentKeyboardSelection with { YPosition = item.CarouselYPosition + item.DrawHeight / 2 };

if (CheckModelEquality(item.Model, currentSelection.Model!))
currentSelection = new Selection(currentSelection.Model, item, item.CarouselYPosition + item.DrawHeight / 2, i);
if (isSelection)
currentSelection = currentSelection with { YPosition = item.CarouselYPosition + item.DrawHeight / 2 };
}

// Update the total height of all items (to make the scroll container scrollable through the full height even though
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Screens/SelectV2/BeatmapCarousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ protected override float GetSpacingBetweenPanels(CarouselItem top, CarouselItem
}
else
{
// `CurrentSelectionItem` cannot be used here because it may not be correctly set yet.
if (CurrentSelection != null && (CheckModelEquality(top.Model, CurrentSelection) || CheckModelEquality(bottom.Model, CurrentSelection)))
if (CurrentSelection != null && (top == CurrentSelectionItem || bottom == CurrentSelectionItem))
return SPACING * 2;
}

Expand Down
6 changes: 5 additions & 1 deletion osu.Game/Screens/SelectV2/PanelBeatmapSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Collections;
Expand All @@ -38,6 +39,7 @@ public partial class PanelBeatmapSet : Panel

private Box chevronBackground = null!;
private PanelSetBackground setBackground = null!;
private ScheduledDelegate? scheduledBackgroundRetrieval;

private OsuSpriteText titleText = null!;
private OsuSpriteText artistText = null!;
Expand Down Expand Up @@ -191,7 +193,7 @@ protected override void PrepareForUse()
var beatmapSet = groupedBeatmapSet.BeatmapSet;

// Choice of background image matches BSS implementation (always uses the lowest `beatmap_id` from the set).
setBackground.Beatmap = beatmaps.GetWorkingBeatmap(beatmapSet.Beatmaps.MinBy(b => b.OnlineID));
scheduledBackgroundRetrieval = Scheduler.AddDelayed(s => setBackground.Beatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps.MinBy(b => b.OnlineID)), beatmapSet, 50);

titleText.Text = new RomanisableString(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title);
artistText.Text = new RomanisableString(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist);
Expand All @@ -204,6 +206,8 @@ protected override void FreeAfterUse()
{
base.FreeAfterUse();

scheduledBackgroundRetrieval?.Cancel();
scheduledBackgroundRetrieval = null;
setBackground.Beatmap = null;
updateButton.BeatmapSet = null;
difficultiesDisplay.BeatmapSet = null;
Expand Down
6 changes: 5 additions & 1 deletion osu.Game/Screens/SelectV2/PanelBeatmapStandalone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
Expand Down Expand Up @@ -55,6 +56,7 @@ public partial class PanelBeatmapStandalone : Panel
private CancellationTokenSource? starDifficultyCancellationSource;

private PanelSetBackground beatmapBackground = null!;
private ScheduledDelegate? scheduledBackgroundRetrieval;

private OsuSpriteText titleText = null!;
private OsuSpriteText artistText = null!;
Expand Down Expand Up @@ -222,7 +224,7 @@ protected override void PrepareForUse()

var beatmapSet = beatmap.BeatmapSet!;

beatmapBackground.Beatmap = beatmaps.GetWorkingBeatmap(beatmap);
scheduledBackgroundRetrieval = Scheduler.AddDelayed(b => beatmapBackground.Beatmap = beatmaps.GetWorkingBeatmap(b), beatmap, 50);
Copy link
Member

Choose a reason for hiding this comment

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

I remember testing this during original implementation but I couldn't see the overhead. I may have been incorrectly testing though, as working beatmaps do get cached after first load.

(And I guess that's one thing to note here – this is delayed the load even when they are cached already. Shouldn't change anything since you've just moved the delay from elsewhere, though.)


titleText.Text = new RomanisableString(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title);
artistText.Text = new RomanisableString(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist);
Expand All @@ -244,6 +246,8 @@ protected override void FreeAfterUse()
{
base.FreeAfterUse();

scheduledBackgroundRetrieval?.Cancel();
scheduledBackgroundRetrieval = null;
beatmapBackground.Beatmap = null;
updateButton.BeatmapSet = null;
localRank.Beatmap = null;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/SelectV2/PanelSetBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void loadContentIfRequired()
// - By using a slightly customised formula to decide when to start the load, we can coerce the loading of backgrounds into an order that
// prioritises panels which are closest to the centre of the screen. Basically, we want to load backgrounds "outwards" from the visual
// centre to give the user the best experience possible.
float timeUpdatingBeforeLoad = 50 + Math.Abs(containingSsdq.Centre.Y - ScreenSpaceDrawQuad.Centre.Y) / containingSsdq.Height * 100;
float timeUpdatingBeforeLoad = Math.Abs(containingSsdq.Centre.Y - ScreenSpaceDrawQuad.Centre.Y) / containingSsdq.Height * 100;

timeSinceUnpool += Time.Elapsed;

Expand Down
Loading