Add basic range-based invalidation

This commit is contained in:
Dean Herbert
2020-10-12 14:46:51 +09:00
parent 3143224e5b
commit f17d661c1a

View File

@ -552,70 +552,44 @@ namespace osu.Game.Screens.Select
#endregion #endregion
private (int first, int last) displayedRange;
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
bool revalidateItems = !itemsCache.IsValid;
//todo: this should only refresh items, not everything here //todo: this should only refresh items, not everything here
if (!itemsCache.IsValid) if (revalidateItems)
{
updateItems(); updateItems();
// Remove all items that should no longer be on-screen // Remove all items that should no longer be on-screen
scrollableContent.RemoveAll(p => p.Y < visibleUpperBound - p.DrawHeight || p.Y > visibleBottomBound || !p.IsPresent); scrollableContent.RemoveAll(p => p.Y < visibleUpperBound - p.DrawHeight || p.Y > visibleBottomBound || !p.IsPresent);
// Find index range of all items that should be on-screen // Find index range of all items that should be on-screen
int firstIndex = yPositions.BinarySearch(visibleUpperBound - DrawableCarouselItem.MAX_HEIGHT); int firstIndex = yPositions.BinarySearch(visibleUpperBound - DrawableCarouselItem.MAX_HEIGHT);
if (firstIndex < 0) firstIndex = ~firstIndex; if (firstIndex < 0) firstIndex = ~firstIndex;
int lastIndex = yPositions.BinarySearch(visibleBottomBound); int lastIndex = yPositions.BinarySearch(visibleBottomBound);
if (lastIndex < 0) lastIndex = ~lastIndex; if (lastIndex < 0) lastIndex = ~lastIndex;
scrollableContent.Clear(); if (revalidateItems || firstIndex != displayedRange.first || lastIndex != displayedRange.last)
{
displayedRange = (firstIndex, lastIndex);
// 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.
for (int i = firstIndex; i < lastIndex; ++i) for (int i = firstIndex; i < lastIndex; ++i)
{ {
DrawableCarouselItem item = visibleItems[i].CreateDrawableRepresentation(); var panel = scrollableContent.FirstOrDefault(c => c.Item == visibleItems[i]);
item.Y = yPositions[i]; if (panel == null)
item.Depth = i;
scrollableContent.Add(item);
// if (!item.Item.Visible)
// {
// if (!item.IsPresent)
// notVisibleCount++;
// continue;
// }
// Only add if we're not already part of the content.
/*
if (!scrollableContent.Contains(item))
{ {
// Makes sure headers are always _below_ items, panel = visibleItems[i].CreateDrawableRepresentation();
// and depth flows downward. scrollableContent.Add(panel);
item.Depth = depth;
switch (item.LoadState)
{
case LoadState.NotLoaded:
LoadComponentAsync(item);
break;
case LoadState.Loading:
break;
default:
scrollableContent.Add(item);
break;
}
} }
else
{ panel.Y = yPositions[i];
scrollableContent.ChangeChildDepth(item, depth); scrollableContent.ChangeChildDepth(panel, i);
}
*/
} }
} }