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

Interpolate parts in local space to avoid broken cursor trails #29253

Merged
merged 2 commits into from
Aug 2, 2024
Merged
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
17 changes: 5 additions & 12 deletions osu.Game.Rulesets.Osu/UI/Cursor/CursorTrail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Framework.Timing;
using osuTK;
using osuTK.Graphics;
Expand Down Expand Up @@ -63,8 +62,6 @@ public CursorTrail()
// -1 signals that the part is unusable, and should not be drawn
parts[i].InvalidationID = -1;
}

AddLayout(partSizeCache);
}

[BackgroundDependencyLoader]
Expand Down Expand Up @@ -95,12 +92,6 @@ public Texture Texture
}
}

private readonly LayoutValue<Vector2> partSizeCache = new LayoutValue<Vector2>(Invalidation.DrawInfo | Invalidation.RequiredParentSizeToFit | Invalidation.Presence);

private Vector2 partSize => partSizeCache.IsValid
? partSizeCache.Value
: (partSizeCache.Value = new Vector2(Texture.DisplayWidth, Texture.DisplayHeight) * DrawInfo.Matrix.ExtractScale().Xy);

/// <summary>
/// The amount of time to fade the cursor trail pieces.
/// </summary>
Expand Down Expand Up @@ -156,6 +147,8 @@ protected override bool OnMouseMove(MouseMoveEvent e)

protected void AddTrail(Vector2 position)
{
position = ToLocalSpace(position);

if (InterpolateMovements)
{
if (!lastPosition.HasValue)
Expand All @@ -174,7 +167,7 @@ protected void AddTrail(Vector2 position)
float distance = diff.Length;
Vector2 direction = diff / distance;

float interval = partSize.X / 2.5f * IntervalMultiplier;
float interval = Texture.DisplayWidth / 2.5f * IntervalMultiplier;
float stopAt = distance - (AvoidDrawingNearCursor ? interval : 0);

for (float d = interval; d < stopAt; d += interval)
Expand All @@ -191,9 +184,9 @@ protected void AddTrail(Vector2 position)
}
}

private void addPart(Vector2 screenSpacePosition)
private void addPart(Vector2 localSpacePosition)
{
parts[currentIndex].Position = ToLocalSpace(screenSpacePosition);
parts[currentIndex].Position = localSpacePosition;
parts[currentIndex].Time = time + 1;
++parts[currentIndex].InvalidationID;

Expand Down
Loading