From 008ff9d2f92eb97204038bb3f764e4c48d6d6c86 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 3 May 2017 18:33:42 +0200 Subject: [PATCH 1/4] InputResample CursorTrail --- osu.Game/Graphics/Cursor/CursorTrail.cs | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorTrail.cs b/osu.Game/Graphics/Cursor/CursorTrail.cs index 09d1b99d13..362a235bca 100644 --- a/osu.Game/Graphics/Cursor/CursorTrail.cs +++ b/osu.Game/Graphics/Cursor/CursorTrail.cs @@ -39,6 +39,8 @@ namespace osu.Game.Graphics.Cursor private Vector2? lastPosition; + private InputResampler resampler = new InputResampler(); + protected override DrawNode CreateDrawNode() => new TrailDrawNode(); protected override void ApplyDrawNode(DrawNode node) @@ -116,22 +118,24 @@ namespace osu.Game.Graphics.Cursor if (lastPosition == null) { lastPosition = state.Mouse.NativeState.Position; + resampler.AddPosition(lastPosition.Value); return base.OnMouseMove(state); } Vector2 pos1 = lastPosition.Value; - Vector2 pos2 = state.Mouse.NativeState.Position; - - Vector2 diff = pos2 - pos1; - float distance = diff.Length; - Vector2 direction = diff / distance; - - float interval = size.X / 2 * 0.9f; - - for (float d = interval; d < distance; d += interval) + foreach (Vector2 pos2 in resampler.AddPosition(state.Mouse.NativeState.Position)) { - lastPosition = pos1 + direction * d; - addPosition(lastPosition.Value); + Vector2 diff = pos2 - pos1; + float distance = diff.Length; + Vector2 direction = diff / distance; + + float interval = size.X / 2 * 0.9f; + + for (float d = interval; d < distance; d += interval) + { + lastPosition = pos1 + direction * d; + addPosition(lastPosition.Value); + } } return base.OnMouseMove(state); From 063b606a123b11eff13bacdf8fb8fb2b450df8e1 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 3 May 2017 18:48:17 +0200 Subject: [PATCH 2/4] Fix readonly warning --- osu.Game/Graphics/Cursor/CursorTrail.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Cursor/CursorTrail.cs b/osu.Game/Graphics/Cursor/CursorTrail.cs index 362a235bca..1c640b64d0 100644 --- a/osu.Game/Graphics/Cursor/CursorTrail.cs +++ b/osu.Game/Graphics/Cursor/CursorTrail.cs @@ -39,7 +39,7 @@ namespace osu.Game.Graphics.Cursor private Vector2? lastPosition; - private InputResampler resampler = new InputResampler(); + private readonly InputResampler resampler = new InputResampler(); protected override DrawNode CreateDrawNode() => new TrailDrawNode(); From 5aecc3d76103617ae15aeea0c624d55ac37c979e Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Fri, 5 May 2017 17:44:51 +0200 Subject: [PATCH 3/4] Made cursortrail work with multiple positions --- osu.Game/Graphics/Cursor/CursorTrail.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Cursor/CursorTrail.cs b/osu.Game/Graphics/Cursor/CursorTrail.cs index 1c640b64d0..7022e98978 100644 --- a/osu.Game/Graphics/Cursor/CursorTrail.cs +++ b/osu.Game/Graphics/Cursor/CursorTrail.cs @@ -122,9 +122,9 @@ namespace osu.Game.Graphics.Cursor return base.OnMouseMove(state); } - Vector2 pos1 = lastPosition.Value; foreach (Vector2 pos2 in resampler.AddPosition(state.Mouse.NativeState.Position)) { + Vector2 pos1 = lastPosition.Value; Vector2 diff = pos2 - pos1; float distance = diff.Length; Vector2 direction = diff / distance; From 9f1f9266341458438fdcf9ce80aeeb3eec4c8de6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 8 May 2017 12:05:48 +0900 Subject: [PATCH 4/4] Add non-null assurance. --- osu.Game/Graphics/Cursor/CursorTrail.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Graphics/Cursor/CursorTrail.cs b/osu.Game/Graphics/Cursor/CursorTrail.cs index 7022e98978..1bc1dea04f 100644 --- a/osu.Game/Graphics/Cursor/CursorTrail.cs +++ b/osu.Game/Graphics/Cursor/CursorTrail.cs @@ -14,6 +14,7 @@ using OpenTK.Graphics.ES30; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Colour; using osu.Framework.Timing; +using System.Diagnostics; namespace osu.Game.Graphics.Cursor { @@ -124,6 +125,8 @@ namespace osu.Game.Graphics.Cursor foreach (Vector2 pos2 in resampler.AddPosition(state.Mouse.NativeState.Position)) { + Trace.Assert(lastPosition.HasValue); + Vector2 pos1 = lastPosition.Value; Vector2 diff = pos2 - pos1; float distance = diff.Length;