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

Fix bulbs on Catmull sliders #27734

Merged
merged 3 commits into from Apr 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 64 additions & 4 deletions osu.Game/Rulesets/Objects/SliderPath.cs
Expand Up @@ -42,6 +42,17 @@ public class SliderPath
private readonly List<double> cumulativeLength = new List<double>();
private readonly Cached pathCache = new Cached();

/// <summary>
/// Any additional length of the path which was optimised out during piecewise approximation, but should still be considered as part of <see cref="calculatedLength"/>.
/// </summary>
/// <remarks>
/// This is a hack for Catmull paths.
/// </remarks>
private double optimisedLength;

/// <summary>
/// The final calculated length of the path.
/// </summary>
private double calculatedLength;

private readonly List<int> segmentEnds = new List<int>();
Expand Down Expand Up @@ -244,6 +255,7 @@ private void calculatePath()
{
calculatedPath.Clear();
segmentEnds.Clear();
optimisedLength = 0;

if (ControlPoints.Count == 0)
return;
Expand All @@ -268,7 +280,8 @@ private void calculatePath()
calculatedPath.Add(segmentVertices[0]);
else if (segmentVertices.Length > 1)
{
List<Vector2> subPath = calculateSubPath(segmentVertices, segmentType);
List<Vector2> subPath = calculateSubPath(segmentVertices, segmentType, ref optimisedLength);

// Skip the first vertex if it is the same as the last vertex from the previous segment
bool skipFirst = calculatedPath.Count > 0 && subPath.Count > 0 && calculatedPath.Last() == subPath[0];

Expand All @@ -287,14 +300,15 @@ private void calculatePath()
}
}

private List<Vector2> calculateSubPath(ReadOnlySpan<Vector2> subControlPoints, PathType type)
private static List<Vector2> calculateSubPath(ReadOnlySpan<Vector2> subControlPoints, PathType type, ref double optimisedLength)
{
switch (type.Type)
{
case SplineType.Linear:
return PathApproximator.LinearToPiecewiseLinear(subControlPoints);

case SplineType.PerfectCurve:
{
if (subControlPoints.Length != 3)
break;

Expand All @@ -305,17 +319,63 @@ private List<Vector2> calculateSubPath(ReadOnlySpan<Vector2> subControlPoints, P
break;

return subPath;
}

case SplineType.Catmull:
return PathApproximator.CatmullToPiecewiseLinear(subControlPoints);
{
List<Vector2> subPath = PathApproximator.CatmullToPiecewiseLinear(subControlPoints);

// At draw time, osu!stable optimises paths by only keeping piecewise segments that are 6px apart.
// For the most part we don't care about this optimisation, and its additional heuristics are hard to reproduce in every implementation.
//
// However, it matters for Catmull paths which form "bulbs" around sequential knots with identical positions,
// so we'll apply a very basic form of the optimisation here and return a length representing the optimised portion.
// The returned length is important so that the optimisation doesn't cause the path to get extended to match the value of ExpectedDistance.
Comment on lines +349 to +354
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that "At draw time" implies that the path normally doesn't have this optimisation applied. This actually has an effect.

In osu!stable the ball behaves like this:

2024-03-27.04-13-34.mp4

Notice how it does the weird loop at the knot, where there is technically still a bulb there. In osu!lazer it behaves like this:

2024-03-27.04-16-47.mp4

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

On a visual pass, it looks like stable is taking longer at the "bulb" points while lazer isn't. So before I dive into the code, can you explain where the extra time is spent in lazer? Or does the slider just get marginally shorter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the extra time is spent at the end of the slider in lazer, going by how it slows down.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

and this is what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to say that this behaves better than stable, but I'm still thinking about it

Technically it's possible to mimic stable's behaviour more closely, but I want to see how the other rulesets work in diffcalc first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is still what we want. Applying the optimisation later on (in GetPathToProgress) would cause it to be applied to non-Catmull segments. This is probably the best that can reasonably be done.

That being said, the diffcalc sheet showed changes in catch which I didn't like. I've changed it to only apply the optimisation in the osu ruleset.

Copy link
Collaborator

@bdach bdach Apr 2, 2024

Choose a reason for hiding this comment

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

So what I'm getting out of this review thread is...

  • Stable approximates the path in the same way that lazer does (in a way that affects all segment types, but catmull particularly as it's prone to these "bulbs"), but then it happens to delete the "bulbs" on catmull sliders as an optimisation, but it only does so at the point of displaying the slider path specifically, so actual input tracking uses the "bulbed" slider path.
  • lazer displays the approximated path as it was given it, i.e. with "bulbs", but the input handling is consistent with the visuals.

Is that understanding correct?

In that case I'm not thoroughly convinced that lazer needs changing here. To use an analogy, to me this is a bit like that "fake slider follow circle radius" thing wherein stable lies with its visuals as to how large the follow circle really is.

Classic mod toggle, maybe...?

Copy link
Contributor Author

@smoogipoo smoogipoo Apr 2, 2024

Choose a reason for hiding this comment

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

but it only does so at the point of displaying visuals, so actual input tracking uses the "bulbed" slider path.

Correct.

but catmull particularly as it's prone to these "bulbs"), but then it happens to delete the "bulbs" on catmull sliders as an optimisation

The optimisation targets every path type and only deletes the bulbs by sheer luck. I'd actually say that the optimisation is more aggressive for other path types, but I digress. You can still bend the sliders to certain degrees and have the bulbs pop out again.

The optimisation traces back to the very beginnings of osu! (2007-09-02) likely targeted at improving performance more-so than visuals, because it was batched along with another that made sliders use AA'd paths (a6fe6288c026a3efc485981bcf2f76b9b29e377e):

(+) Sliders look a LOT nicer. Performance should be considerably higher too - although I still believe I have a bit of work to do in this area.

image
(2007-08-26, credit to osekai)

Classic mod toggle, maybe...?

I don't feel okay with maps looking weird just because they were using an old algorithm. I think for all intents and purposes this should be considered as part of the algorithm. Furthermore, as mentioned in #27711, there are even recent maps using Catmull.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So to sum up, the effect of this change is such that visuals on lazer will now match stable, but the actual input handling will be slightly different (because lazer will still handle input to match what it displays, it doesn't do the dumb games stable does with showing one path and using another for input).

I think I could be fine with that, personally. I definitely don't want to play the stable dumb games, so it's either this PR or nothing as far as I'm concerned. @peppy thoughts?


List<Vector2> optimisedPath = new List<Vector2>(subPath.Count);

Vector2? lastStart = null;
double lengthRemovedSinceStart = 0;

for (int i = 0; i < subPath.Count; i++)
{
if (lastStart == null)
{
optimisedPath.Add(subPath[i]);
lastStart = subPath[i];
continue;
}

Debug.Assert(i > 0);

double distFromStart = Vector2.Distance(lastStart.Value, subPath[i]);
lengthRemovedSinceStart += Vector2.Distance(subPath[i - 1], subPath[i]);

// See PathApproximator.catmull_detail.
const int catmull_detail = 50;
const int catmull_segment_length = catmull_detail * 2;

// Either 6px from the start, the last vertex at every knot, or the end of the path.
if (distFromStart > 6 || (i + 1) % catmull_segment_length == 0 || i == subPath.Count - 1)
{
optimisedPath.Add(subPath[i]);
optimisedLength += lengthRemovedSinceStart - distFromStart;

lastStart = null;
lengthRemovedSinceStart = 0;
}
}

return optimisedPath;
}
}

return PathApproximator.BSplineToPiecewiseLinear(subControlPoints, type.Degree ?? subControlPoints.Length);
}

private void calculateLength()
{
calculatedLength = 0;
calculatedLength = optimisedLength;
cumulativeLength.Clear();
cumulativeLength.Add(0);

Expand Down