Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use double in ScrollContainer for scroll tracking #6467

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

peppy
Copy link
Member

@peppy peppy commented Dec 20, 2024

This is the first step towards supporting scrolling over very large amounts of content. With this along, the animation already becomes somewhat smoother (no longer "locking" into place too early) but scroll content will still look jagged when scrolled too far down.

Fixing actual content requires a small amount of extra implementation on top of this. To keep things simple this would be up to the consumer to implement and maintain.

Intended to help fix osu! song select from becoming weird when hundreds of thousands of beatmaps are loaded.

A sample implementation is provided in TestSceneScrollContainerDoublePrecision.

master with a BasicScrollContainer:

osu.Framework.Tests.2024-12-20.at.09.12.41.mp4

This PR with a BasicScrollContainer:

osu.Framework.Tests.2024-12-20.at.09.09.57.mp4

This PR with the custom double implementation:

osu.Framework.Tests.2024-12-20.at.09.11.43.mp4

This is the first step towards supporting scrolling over very large
amounts of content. With this along, the animation already becomes
somewhat smoother (no longer "locking" into place too early) but scroll
content will still look jagged when scrolled too far down.

Fixing actual content requires a small amount of extra implementation on
top of this. To keep things simple this would be up to the consumer to
implement and maintain.

Intended to help fix osu! song select from becoming weird when hundreds
of thousands of beatmaps are loaded.
… to content

This allows a point of intercept to distribute `double` values to
children and bypass floating point precision issues.
@@ -515,14 +515,14 @@ public void ScrollIntoView(Drawable d, bool animated = true)
/// <param name="d">The child to get the position from.</param>
/// <param name="offset">Positional offset in the child's space.</param>
/// <returns>The position of the child.</returns>
public float GetChildPosInContent(Drawable d, Vector2 offset) => d.ToSpaceOfOtherDrawable(offset, ScrollContent)[ScrollDim];
public virtual double GetChildPosInContent(Drawable d, Vector2 offset) => d.ToSpaceOfOtherDrawable(offset, ScrollContent)[ScrollDim];
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to confirm my understanding: this is virtual because positions everywhere else in framework are floats and without overriding this there is no way to recover precision lost on coordinates, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's basically allowing the few places which require double to be double. This one is important for accurate scrolling.

ApplyCurrentToContent();
}

protected virtual void ApplyCurrentToContent()
Copy link
Collaborator

Choose a reason for hiding this comment

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

method needs xmldoc explaining when it's called and what work is expected of consumers when overriding it, it's not exactly clear from the name alone

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

}
}

public partial class DoubleScrollContainer : BasicScrollContainer
Copy link
Collaborator

Choose a reason for hiding this comment

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

the fact that this has to exist is unfortunate but i don't see any better way either. at least not if i correctly understand why this has to exist (see preceding comments about how coords everywhere else are floats)

Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW this will only be implemented by usages in osu! for instance. I moved this class inside the test scene to make it very clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants