Skip to content

Commit

Permalink
Add basic total event statistics for all handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Susko3 committed Dec 24, 2023
1 parent 3f4f735 commit b5aaa34
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions osu.Framework.Android/Input/AndroidJoystickHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace osu.Framework.Android.Input
{
public class AndroidJoystickHandler : AndroidInputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<AndroidJoystickHandler>(), "Total events");

public BindableFloat DeadzoneThreshold { get; } = new BindableFloat(0.1f)
{
MinValue = 0,
Expand Down Expand Up @@ -223,6 +225,7 @@ private void enqueueInput(IInput input)
{
PendingInputs.Enqueue(input);
FrameStatistics.Increment(StatisticsCounterType.JoystickEvents);
statistic_total_events.Value++;
}
}
}
3 changes: 3 additions & 0 deletions osu.Framework.Android/Input/AndroidKeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace osu.Framework.Android.Input
{
public class AndroidKeyboardHandler : AndroidInputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<AndroidKeyboardHandler>(), "Total events");

protected override IEnumerable<InputSourceType> HandledEventSources => new[]
{
InputSourceType.Keyboard,
Expand Down Expand Up @@ -209,6 +211,7 @@ private void enqueueInput(IInput input)
{
PendingInputs.Enqueue(input);
FrameStatistics.Increment(StatisticsCounterType.KeyEvents);
statistic_total_events.Value++;
}
}
}
3 changes: 3 additions & 0 deletions osu.Framework.Android/Input/AndroidMouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace osu.Framework.Android.Input
/// </summary>
public class AndroidMouseHandler : AndroidInputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<AndroidMouseHandler>(), "Total events");

/// <summary>
/// Whether relative mode should be preferred when the window has focus, the cursor is contained and the OS cursor is not visible.
/// </summary>
Expand Down Expand Up @@ -308,6 +310,7 @@ private void enqueueInput(IInput input)
{
PendingInputs.Enqueue(input);
FrameStatistics.Increment(StatisticsCounterType.MouseEvents);
statistic_total_events.Value++;
}
}
}
9 changes: 9 additions & 0 deletions osu.Framework.Android/Input/AndroidTouchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace osu.Framework.Android.Input
{
public class AndroidTouchHandler : AndroidInputHandler
{
private static readonly GlobalStatistic<ulong> statistic_touch_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<AndroidTouchHandler>(), "Touch events");
private static readonly GlobalStatistic<ulong> statistic_hover_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<AndroidTouchHandler>(), "Hover events");

public override bool IsActive => true;

protected override IEnumerable<InputSourceType> HandledEventSources => new[] { InputSourceType.BluetoothStylus, InputSourceType.Stylus, InputSourceType.Touchscreen };
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace osu.Framework.Input.Handlers.Joystick
{
public class JoystickHandler : InputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<JoystickHandler>(), "Total events");

public BindableFloat DeadzoneThreshold { get; } = new BindableFloat(0.1f)
{
MinValue = 0,
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace osu.Framework.Input.Handlers.Keyboard
{
public class KeyboardHandler : InputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<KeyboardHandler>(), "Total events");

public override string Description => "Keyboard";

public override bool IsActive => true;
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions osu.Framework/Input/Handlers/Midi/MidiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace osu.Framework.Input.Handlers.Midi
{
public class MidiHandler : InputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<MidiHandler>(), "Total events");

public override string Description => "MIDI";
public override bool IsActive => inGoodState;

Expand Down Expand Up @@ -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++;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions osu.Framework/Input/Handlers/Mouse/MouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace osu.Framework.Input.Handlers.Mouse
/// </summary>
public class MouseHandler : InputHandler, IHasCursorSensitivity, INeedsMousePositionFeedback
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<MouseHandler>(), "Total events");

/// <summary>
/// Whether relative mode should be preferred when the window has focus, the cursor is contained and the OS cursor is not visible.
/// </summary>
Expand Down Expand Up @@ -219,6 +221,7 @@ private void enqueueInput(IInput input)
{
PendingInputs.Enqueue(input);
FrameStatistics.Increment(StatisticsCounterType.MouseEvents);
statistic_total_events.Value++;
}

private void transferLastPositionToHostCursor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace osu.Framework.Input.Handlers.Tablet
{
public class OpenTabletDriverHandler : InputHandler, IAbsolutePointer, IRelativePointer, IPressureHandler, ITabletHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<OpenTabletDriverHandler>(), "Total events");

private TabletDriver? tabletDriver;

private InputDeviceTree? device;
Expand Down Expand Up @@ -203,6 +205,7 @@ private void enqueueInput(IInput input)
{
PendingInputs.Enqueue(input);
FrameStatistics.Increment(StatisticsCounterType.TabletEvents);
statistic_total_events.Value++;
}
}
}
3 changes: 3 additions & 0 deletions osu.Framework/Input/Handlers/Touch/TouchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace osu.Framework.Input.Handlers.Touch
{
public class TouchHandler : InputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<TouchHandler>(), "Total events");

public override bool IsActive => true;

public override bool Initialize(GameHost host)
Expand Down Expand Up @@ -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++;
}
}
}

0 comments on commit b5aaa34

Please sign in to comment.