diff --git a/osu.Framework/Input/PassThroughInputManager.cs b/osu.Framework/Input/PassThroughInputManager.cs index 8c8c014bcb..fbb9b5ddb4 100644 --- a/osu.Framework/Input/PassThroughInputManager.cs +++ b/osu.Framework/Input/PassThroughInputManager.cs @@ -182,8 +182,10 @@ protected virtual void SyncInputState(InputState state) new KeyboardKeyInput(state?.Keyboard?.Keys, CurrentState.Keyboard.Keys).Apply(CurrentState, this); var touchStateDifference = (state?.Touch ?? new TouchState()).EnumerateDifference(CurrentState.Touch); - new TouchInput(touchStateDifference.deactivated, false).Apply(CurrentState, this); - new TouchInput(touchStateDifference.activated, true).Apply(CurrentState, this); + if (touchStateDifference.deactivated.Length > 0) + new TouchInput(touchStateDifference.deactivated, false).Apply(CurrentState, this); + if (touchStateDifference.activated.Length > 0) + new TouchInput(touchStateDifference.activated, true).Apply(CurrentState, this); new JoystickButtonInput(state?.Joystick?.Buttons ?? new ButtonStates(), CurrentState.Joystick.Buttons).Apply(CurrentState, this); new JoystickAxisInput(state?.Joystick?.GetAxes() ?? Array.Empty()).Apply(CurrentState, this); diff --git a/osu.Framework/Input/States/TouchState.cs b/osu.Framework/Input/States/TouchState.cs index 8a26e4d401..e99f9022ad 100644 --- a/osu.Framework/Input/States/TouchState.cs +++ b/osu.Framework/Input/States/TouchState.cs @@ -2,8 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; -using System.Linq; using osuTK; namespace osu.Framework.Input.States @@ -46,15 +44,33 @@ public class TouchState /// Enumerates the difference between this state and a state. /// /// The previous state. - public (IEnumerable deactivated, IEnumerable activated) EnumerateDifference(TouchState previous) + public (Touch[] deactivated, Touch[] activated) EnumerateDifference(TouchState previous) { - var activityDifference = ActiveSources.EnumerateDifference(previous.ActiveSources); + var diff = ActiveSources.EnumerateDifference(previous.ActiveSources); - return - ( - activityDifference.Released.Select(s => new Touch(s, previous.TouchPositions[(int)s])), - activityDifference.Pressed.Select(s => new Touch(s, TouchPositions[(int)s])) - ); + int pressedCount = diff.Pressed.Length; + int releasedCount = diff.Released.Length; + + if (pressedCount == 0 && releasedCount == 0) + return (Array.Empty(), Array.Empty()); + + Touch[] pressedTouches = new Touch[pressedCount]; + + for (int i = 0; i < pressedCount; i++) + { + var s = diff.Pressed[i]; + pressedTouches[i] = new Touch(s, TouchPositions[(int)s]); + } + + Touch[] releasedTouches = new Touch[releasedCount]; + + for (int i = 0; i < releasedCount; i++) + { + var s = diff.Released[i]; + releasedTouches[i] = new Touch(s, previous.TouchPositions[(int)s]); + } + + return (releasedTouches, pressedTouches); } } }