From dac1a32bec47a924cebab2a0e0c7ebe510a42853 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 24 Dec 2023 13:02:03 +0100 Subject: [PATCH 1/5] Fix comment after `// ReSharper disable` breaking R# --- osu.Framework/Platform/Windows/WindowsMouseHandler.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index a3f74e6f6c..e1b725f16c 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -11,8 +11,6 @@ using osuTK; using SDL2; -// ReSharper disable UnusedParameter.Local (Class regularly handles native events where we don't consume all parameters) - namespace osu.Framework.Platform.Windows { /// @@ -35,6 +33,7 @@ public override bool Initialize(GameHost host) return false; window = desktopWindow; + // ReSharper disable once ConvertClosureToMethodGroup callback = (ptr, wnd, u, param, l) => onWndProc(ptr, wnd, u, param, l); Enabled.BindValueChanged(enabled => From ff17d4ab638de0747b8393d97d7a33c95a0bc2a3 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 24 Dec 2023 13:05:02 +0100 Subject: [PATCH 2/5] Fix typo --- osu.Framework/Platform/Windows/WindowsMouseHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index e1b725f16c..47f29f6133 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -77,7 +77,7 @@ private IntPtr onWndProc(IntPtr userData, IntPtr hWnd, uint message, ulong wPara var mouse = data.Mouse; - // `ExtraInformation` doens't have the MI_WP_SIGNATURE set, so we have to rely solely on the touch flag. + // `ExtraInformation` doesn't have the MI_WP_SIGNATURE set, so we have to rely solely on the touch flag. if (Native.Input.HasTouchFlag(mouse.ExtraInformation)) return IntPtr.Zero; From ddd298ad4d91a75b2a735109e9a1173fde402f13 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 24 Dec 2023 13:38:35 +0100 Subject: [PATCH 3/5] Add `InputHandler` helper for statistic group name --- osu.Framework/Input/Handlers/InputHandler.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/osu.Framework/Input/Handlers/InputHandler.cs b/osu.Framework/Input/Handlers/InputHandler.cs index f90382e7f9..752d6cb776 100644 --- a/osu.Framework/Input/Handlers/InputHandler.cs +++ b/osu.Framework/Input/Handlers/InputHandler.cs @@ -7,14 +7,27 @@ using System.Collections.Concurrent; using System.Collections.Generic; using osu.Framework.Bindables; +using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.StateChanges; using osu.Framework.Logging; using osu.Framework.Platform; +using osu.Framework.Statistics; namespace osu.Framework.Input.Handlers { public abstract class InputHandler : IDisposable, IHasDescription { + /// + /// Base category to use for input-related . + /// + public const string STATISTIC_GROUP = "Input"; + + /// + /// Gets the appropriate statistic group for use in . + /// + /// Calling class + protected static string StatisticGroupFor() where T : InputHandler => $"{STATISTIC_GROUP} - {typeof(T).ReadableName()}"; + private static readonly Logger logger = Logger.GetLogger(LoggingTarget.Input); private bool isInitialized; From 3f4f735aca06ce25fef3ca39cf8d4119846f3363 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 24 Dec 2023 13:47:28 +0100 Subject: [PATCH 4/5] Add advanced `WindowsMouseHandler` statistics An example of how specific statistics can use used. --- .../Platform/Windows/WindowsMouseHandler.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index 47f29f6133..ae8070e11e 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -8,6 +8,7 @@ using osu.Framework.Input.Handlers.Mouse; using osu.Framework.Input.StateChanges; using osu.Framework.Platform.Windows.Native; +using osu.Framework.Statistics; using osuTK; using SDL2; @@ -20,6 +21,11 @@ namespace osu.Framework.Platform.Windows [SupportedOSPlatform("windows")] internal unsafe class WindowsMouseHandler : MouseHandler { + private static readonly GlobalStatistic statistic_relative_events = GlobalStatistics.Get(StatisticGroupFor(), "Relative events"); + private static readonly GlobalStatistic statistic_absolute_events = GlobalStatistics.Get(StatisticGroupFor(), "Absolute events"); + private static readonly GlobalStatistic statistic_dropped_touch_inputs = GlobalStatistics.Get(StatisticGroupFor(), "Dropped native touch inputs"); + private static readonly GlobalStatistic statistic_inputs_with_extra_information = GlobalStatistics.Get(StatisticGroupFor(), "Native inputs with ExtraInformation"); + private const int raw_input_coordinate_space = 65535; private SDL.SDL_WindowsMessageHook callback = null!; @@ -64,9 +70,12 @@ private IntPtr onWndProc(IntPtr userData, IntPtr hWnd, uint message, ulong wPara return IntPtr.Zero; if (Native.Input.IsTouchEvent(Native.Input.GetMessageExtraInfo())) + { // sometimes GetMessageExtraInfo returns 0, so additionally, mouse.ExtraInformation is checked below. // touch events are handled by TouchHandler + statistic_dropped_touch_inputs.Value++; return IntPtr.Zero; + } int payloadSize = sizeof(RawInputData); @@ -79,11 +88,16 @@ private IntPtr onWndProc(IntPtr userData, IntPtr hWnd, uint message, ulong wPara // `ExtraInformation` doesn't have the MI_WP_SIGNATURE set, so we have to rely solely on the touch flag. if (Native.Input.HasTouchFlag(mouse.ExtraInformation)) + { + statistic_dropped_touch_inputs.Value++; return IntPtr.Zero; + } //TODO: this isn't correct. if (mouse.ExtraInformation > 0) { + statistic_inputs_with_extra_information.Value++; + // i'm not sure if there is a valid case where we need to handle packets with this present // but the osu!tablet fires noise events with non-zero values, which we want to ignore. // return IntPtr.Zero; @@ -128,10 +142,12 @@ private IntPtr onWndProc(IntPtr userData, IntPtr hWnd, uint message, ulong wPara position *= window.Scale; PendingInputs.Enqueue(new MousePositionAbsoluteInput { Position = position }); + statistic_absolute_events.Value++; } else { PendingInputs.Enqueue(new MousePositionRelativeInput { Delta = new Vector2(mouse.LastX, mouse.LastY) * sensitivity }); + statistic_relative_events.Value++; } return IntPtr.Zero; From b5aaa346f6ed3bee0b3cbf7b7826e6a5e32856ce Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 24 Dec 2023 13:49:39 +0100 Subject: [PATCH 5/5] Add basic total event statistics for all handlers --- osu.Framework.Android/Input/AndroidJoystickHandler.cs | 3 +++ osu.Framework.Android/Input/AndroidKeyboardHandler.cs | 3 +++ osu.Framework.Android/Input/AndroidMouseHandler.cs | 3 +++ osu.Framework.Android/Input/AndroidTouchHandler.cs | 9 +++++++++ osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs | 3 +++ osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs | 3 +++ osu.Framework/Input/Handlers/Midi/MidiHandler.cs | 4 ++++ osu.Framework/Input/Handlers/Mouse/MouseHandler.cs | 3 +++ .../Input/Handlers/Tablet/OpenTabletDriverHandler.cs | 3 +++ osu.Framework/Input/Handlers/Touch/TouchHandler.cs | 3 +++ 10 files changed, 37 insertions(+) diff --git a/osu.Framework.Android/Input/AndroidJoystickHandler.cs b/osu.Framework.Android/Input/AndroidJoystickHandler.cs index c8375f0460..af7b63ddb4 100644 --- a/osu.Framework.Android/Input/AndroidJoystickHandler.cs +++ b/osu.Framework.Android/Input/AndroidJoystickHandler.cs @@ -15,6 +15,8 @@ namespace osu.Framework.Android.Input { public class AndroidJoystickHandler : AndroidInputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + public BindableFloat DeadzoneThreshold { get; } = new BindableFloat(0.1f) { MinValue = 0, @@ -223,6 +225,7 @@ private void enqueueInput(IInput input) { PendingInputs.Enqueue(input); FrameStatistics.Increment(StatisticsCounterType.JoystickEvents); + statistic_total_events.Value++; } } } diff --git a/osu.Framework.Android/Input/AndroidKeyboardHandler.cs b/osu.Framework.Android/Input/AndroidKeyboardHandler.cs index 163bbe8cd9..9eebefdb24 100644 --- a/osu.Framework.Android/Input/AndroidKeyboardHandler.cs +++ b/osu.Framework.Android/Input/AndroidKeyboardHandler.cs @@ -13,6 +13,8 @@ namespace osu.Framework.Android.Input { public class AndroidKeyboardHandler : AndroidInputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + protected override IEnumerable HandledEventSources => new[] { InputSourceType.Keyboard, @@ -209,6 +211,7 @@ private void enqueueInput(IInput input) { PendingInputs.Enqueue(input); FrameStatistics.Increment(StatisticsCounterType.KeyEvents); + statistic_total_events.Value++; } } } diff --git a/osu.Framework.Android/Input/AndroidMouseHandler.cs b/osu.Framework.Android/Input/AndroidMouseHandler.cs index 0eaf7e1b4b..1bd454357a 100644 --- a/osu.Framework.Android/Input/AndroidMouseHandler.cs +++ b/osu.Framework.Android/Input/AndroidMouseHandler.cs @@ -20,6 +20,8 @@ namespace osu.Framework.Android.Input /// public class AndroidMouseHandler : AndroidInputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + /// /// Whether relative mode should be preferred when the window has focus, the cursor is contained and the OS cursor is not visible. /// @@ -308,6 +310,7 @@ private void enqueueInput(IInput input) { PendingInputs.Enqueue(input); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); + statistic_total_events.Value++; } } } diff --git a/osu.Framework.Android/Input/AndroidTouchHandler.cs b/osu.Framework.Android/Input/AndroidTouchHandler.cs index d7aaf32b56..15eb6631d2 100644 --- a/osu.Framework.Android/Input/AndroidTouchHandler.cs +++ b/osu.Framework.Android/Input/AndroidTouchHandler.cs @@ -14,6 +14,9 @@ namespace osu.Framework.Android.Input { public class AndroidTouchHandler : AndroidInputHandler { + private static readonly GlobalStatistic statistic_touch_events = GlobalStatistics.Get(StatisticGroupFor(), "Touch events"); + private static readonly GlobalStatistic statistic_hover_events = GlobalStatistics.Get(StatisticGroupFor(), "Hover events"); + public override bool IsActive => true; protected override IEnumerable HandledEventSources => new[] { InputSourceType.BluetoothStylus, InputSourceType.Stylus, InputSourceType.Touchscreen }; @@ -87,14 +90,20 @@ protected override bool OnHover(MotionEvent hoverEvent) void apply(MotionEvent e, int historyPosition) { if (tryGetEventPosition(e, historyPosition, 0, out var position)) + { enqueueInput(new MousePositionAbsoluteInput { Position = position }); + statistic_hover_events.Value++; + } } } private void applyTouchInput(MotionEvent touchEvent, int historyPosition, int pointerIndex) { if (tryGetEventTouch(touchEvent, historyPosition, pointerIndex, out var touch)) + { enqueueInput(new TouchInput(touch, touchEvent.ActionMasked.IsTouchDownAction())); + statistic_touch_events.Value++; + } } private bool tryGetEventTouch(MotionEvent motionEvent, int historyPosition, int pointerIndex, out Touch touch) diff --git a/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs b/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs index 75fdfe08ec..997475bfa1 100644 --- a/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs +++ b/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs @@ -11,6 +11,8 @@ namespace osu.Framework.Input.Handlers.Joystick { public class JoystickHandler : InputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + public BindableFloat DeadzoneThreshold { get; } = new BindableFloat(0.1f) { MinValue = 0, @@ -53,6 +55,7 @@ private void enqueueJoystickEvent(IInput evt) { PendingInputs.Enqueue(evt); FrameStatistics.Increment(StatisticsCounterType.JoystickEvents); + statistic_total_events.Value++; } private void enqueueJoystickButtonDown(JoystickButton button) => enqueueJoystickEvent(new JoystickButtonInput(button, true)); diff --git a/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs b/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs index 44eafeda59..169cc4543c 100644 --- a/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs +++ b/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs @@ -10,6 +10,8 @@ namespace osu.Framework.Input.Handlers.Keyboard { public class KeyboardHandler : InputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + public override string Description => "Keyboard"; public override bool IsActive => true; @@ -43,6 +45,7 @@ private void enqueueInput(IInput input) { PendingInputs.Enqueue(input); FrameStatistics.Increment(StatisticsCounterType.KeyEvents); + statistic_total_events.Value++; } private void handleKeyDown(TKKey key) => enqueueInput(new KeyboardKeyInput(key, true)); diff --git a/osu.Framework/Input/Handlers/Midi/MidiHandler.cs b/osu.Framework/Input/Handlers/Midi/MidiHandler.cs index ac850e6cdf..9518062514 100644 --- a/osu.Framework/Input/Handlers/Midi/MidiHandler.cs +++ b/osu.Framework/Input/Handlers/Midi/MidiHandler.cs @@ -21,6 +21,8 @@ namespace osu.Framework.Input.Handlers.Midi { public class MidiHandler : InputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + public override string Description => "MIDI"; public override bool IsActive => inGoodState; @@ -251,12 +253,14 @@ void noteOn() { PendingInputs.Enqueue(new MidiKeyInput((MidiKey)key, velocity, true)); FrameStatistics.Increment(StatisticsCounterType.MidiEvents); + statistic_total_events.Value++; } void noteOff() { PendingInputs.Enqueue(new MidiKeyInput((MidiKey)key, 0, false)); FrameStatistics.Increment(StatisticsCounterType.MidiEvents); + statistic_total_events.Value++; } } } diff --git a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs index 1de0a31c74..9b2c6bff5d 100644 --- a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs +++ b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs @@ -20,6 +20,8 @@ namespace osu.Framework.Input.Handlers.Mouse /// public class MouseHandler : InputHandler, IHasCursorSensitivity, INeedsMousePositionFeedback { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + /// /// Whether relative mode should be preferred when the window has focus, the cursor is contained and the OS cursor is not visible. /// @@ -219,6 +221,7 @@ private void enqueueInput(IInput input) { PendingInputs.Enqueue(input); FrameStatistics.Increment(StatisticsCounterType.MouseEvents); + statistic_total_events.Value++; } private void transferLastPositionToHostCursor() diff --git a/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs b/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs index ff73859cf3..2f3b442139 100644 --- a/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs +++ b/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs @@ -20,6 +20,8 @@ namespace osu.Framework.Input.Handlers.Tablet { public class OpenTabletDriverHandler : InputHandler, IAbsolutePointer, IRelativePointer, IPressureHandler, ITabletHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + private TabletDriver? tabletDriver; private InputDeviceTree? device; @@ -203,6 +205,7 @@ private void enqueueInput(IInput input) { PendingInputs.Enqueue(input); FrameStatistics.Increment(StatisticsCounterType.TabletEvents); + statistic_total_events.Value++; } } } diff --git a/osu.Framework/Input/Handlers/Touch/TouchHandler.cs b/osu.Framework/Input/Handlers/Touch/TouchHandler.cs index 138010aac1..7d19eda1c9 100644 --- a/osu.Framework/Input/Handlers/Touch/TouchHandler.cs +++ b/osu.Framework/Input/Handlers/Touch/TouchHandler.cs @@ -9,6 +9,8 @@ namespace osu.Framework.Input.Handlers.Touch { public class TouchHandler : InputHandler { + private static readonly GlobalStatistic statistic_total_events = GlobalStatistics.Get(StatisticGroupFor(), "Total events"); + public override bool IsActive => true; public override bool Initialize(GameHost host) @@ -50,6 +52,7 @@ private void enqueueTouch(Input.Touch touch, bool activate) { PendingInputs.Enqueue(new TouchInput(touch, activate)); FrameStatistics.Increment(StatisticsCounterType.TouchEvents); + statistic_total_events.Value++; } } }