mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 17:13:06 +08:00
Reduce overhead of ApplyState
by tracking previous values
Even with pooling applied, there are overheads involved with transforms when quickly cycling through the carousel. The main goal here is to reduce the transforms in cases the reuse is still in the same state. Avoiding firing `FadeIn` and `FadeOut` are the main areas of saving.
This commit is contained in:
parent
a06287e76a
commit
c3e3b2019d
@ -71,6 +71,9 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
beatmapInfo = panel.BeatmapInfo;
|
||||
Item = panel;
|
||||
|
||||
// Difficulty panels should start hidden for a better initial effect.
|
||||
Hide();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
|
@ -64,8 +64,6 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
Alpha = 0;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
MovementContainer = new Container
|
||||
@ -119,29 +117,56 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
|
||||
private void onStateChange(ValueChangedEvent<bool> _) => Scheduler.AddOnce(ApplyState);
|
||||
|
||||
private CarouselItemState? lastAppliedState;
|
||||
|
||||
protected virtual void ApplyState()
|
||||
{
|
||||
// Use the fact that we know the precise height of the item from the model to avoid the need for AutoSize overhead.
|
||||
// Additionally, AutoSize doesn't work well due to content starting off-screen and being masked away.
|
||||
Height = Item.TotalHeight;
|
||||
|
||||
Debug.Assert(Item != null);
|
||||
|
||||
switch (Item.State.Value)
|
||||
if (lastAppliedState != Item.State.Value)
|
||||
{
|
||||
case CarouselItemState.NotSelected:
|
||||
Deselected();
|
||||
break;
|
||||
lastAppliedState = Item.State.Value;
|
||||
|
||||
case CarouselItemState.Selected:
|
||||
Selected();
|
||||
break;
|
||||
// Use the fact that we know the precise height of the item from the model to avoid the need for AutoSize overhead.
|
||||
// Additionally, AutoSize doesn't work well due to content starting off-screen and being masked away.
|
||||
Height = Item.TotalHeight;
|
||||
|
||||
switch (lastAppliedState)
|
||||
{
|
||||
case CarouselItemState.NotSelected:
|
||||
Deselected();
|
||||
break;
|
||||
|
||||
case CarouselItemState.Selected:
|
||||
Selected();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Item.Visible)
|
||||
this.FadeOut(300, Easing.OutQuint);
|
||||
Hide();
|
||||
else
|
||||
this.FadeIn(250);
|
||||
Show();
|
||||
}
|
||||
|
||||
private bool isVisible = true;
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
if (isVisible)
|
||||
return;
|
||||
|
||||
isVisible = true;
|
||||
this.FadeIn(250);
|
||||
}
|
||||
|
||||
public override void Hide()
|
||||
{
|
||||
if (!isVisible)
|
||||
return;
|
||||
|
||||
isVisible = false;
|
||||
this.FadeOut(300, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected virtual void Selected()
|
||||
|
Loading…
Reference in New Issue
Block a user