Skip to content

Commit 5b92fe7

Browse files
cleanup
1 parent df8c990 commit 5b92fe7

4 files changed

Lines changed: 15 additions & 37 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,8 +1524,7 @@ public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus()
15241524

15251525
// Loose focus.
15261526
ScheduleFocusEvent(false);
1527-
InputSystem.Update(InputUpdateType.Dynamic);
1528-
//InputSystem.Update();
1527+
InputSystem.Update();
15291528

15301529
// Disconnect.
15311530
var inputEvent = DeviceRemoveEvent.Create(deviceId, runtime.currentTime);
@@ -1537,8 +1536,7 @@ public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus()
15371536

15381537
// Regain focus.
15391538
ScheduleFocusEvent(true);
1540-
InputSystem.Update(InputUpdateType.Dynamic);
1541-
//InputSystem.Update();
1539+
InputSystem.Update();
15421540

15431541
var newDeviceId = runtime.ReportNewInputDevice(deviceDesc);
15441542
InputSystem.Update();
@@ -5288,7 +5286,7 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change)
52885286
"Sync Mouse", "Sync Mouse2", "Sync Mouse3",
52895287
"Sync Keyboard"
52905288
}));
5291-
// Enabled devices that don't support syncs dont get reset for Ignore Forcus as we do not want to cancel any actions.
5289+
// Enabled devices that don't support syncs dont get reset for Ignore Focus as we do not want to cancel any actions.
52925290
Assert.That(changes, Is.Empty);
52935291
break;
52945292
}

Assets/Tests/InputSystem/Plugins/EnhancedTouchTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void EnhancedTouch_SupportsEditorUpdates(InputSettings.UpdateMode updateM
172172
// Switch back to player.
173173
ScheduleFocusEvent(true);
174174

175-
// We have to schedule the specificic update type that the player is configured to process events in,
175+
// We have to schedule the specific update type that the player is configured to process events in,
176176
// otherwise we will end up using defaultUpdateType, which due to the fact we do not have focus in pre-update yet,
177177
// will be Editor, which means that we will end up swapping buffers to the editor buffer, and retreiving the wrong active touch
178178
// The only way to properly fix this, is to remove defaultUpdateType, and split the player/editor update loops into separate methods, which would be a breaking change.
@@ -1187,7 +1187,6 @@ public void EnhancedTouch_ActiveTouchesGetCanceledOnFocusLoss_WithRunInBackgroun
11871187
else
11881188
{
11891189
// When not running in the background, the same thing happens but only on focus gain.
1190-
//runtime.PlayerFocusGained();
11911190
ScheduleFocusEvent(true);
11921191
InputSystem.Update();
11931192
}

Packages/com.unity.inputsystem/InputSystem/InputManager.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public InputUpdateType defaultUpdateType
165165
return m_CurrentUpdate;
166166

167167
#if UNITY_EDITOR
168-
// We can no longer rely on checking the curent focus state, due to this check being used pre-update
168+
// We can no longer rely on checking the current focus state, due to this check being used pre-update
169169
// to determine in which update type to process input, and focus being updated in Update.
170170
// The solution here would be to make update calls explicitly specify the update type and no longer use this property.
171171
if (!m_RunPlayerUpdatesInEditMode && (!gameIsPlaying || !gameHasFocus))
@@ -2139,8 +2139,9 @@ internal void InstallRuntime(IInputRuntime runtime)
21392139
#endif
21402140
m_Runtime.pollingFrequency = pollingFrequency;
21412141

2142-
focusState = Application.isFocused ? focusState |= FocusFlags.ApplicationFocus
2143-
: focusState &= ~FocusFlags.ApplicationFocus;
2142+
focusState = Application.isFocused
2143+
? focusState | FocusFlags.ApplicationFocus
2144+
: focusState & ~FocusFlags.ApplicationFocus;
21442145

21452146
// We only hook NativeInputSystem.onBeforeUpdate if necessary.
21462147
if (m_BeforeUpdateListeners.length > 0 || m_HaveDevicesWithStateCallbackReceivers)
@@ -3173,7 +3174,6 @@ private unsafe void ProcessEventBuffer(InputUpdateType updateType, ref InputEven
31733174
{
31743175
InputDevice device = null;
31753176
var currentEventReadPtr = m_InputEventStream.currentEventPtr;
3176-
var currentEventType = currentEventReadPtr->type;
31773177

31783178
Debug.Assert(!currentEventReadPtr->handled, "Event in buffer is already marked as handled");
31793179

@@ -3186,6 +3186,7 @@ private unsafe void ProcessEventBuffer(InputUpdateType updateType, ref InputEven
31863186
break;
31873187

31883188
var currentEventTimeInternal = currentEventReadPtr->internalTime;
3189+
var currentEventType = currentEventReadPtr->type;
31893190
#if UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS
31903191
#if UNITY_EDITOR
31913192
if (SkipEventDueToEditorBehaviour(updateType, currentEventType, dropStatusEvents, currentEventTimeInternal))
@@ -3318,7 +3319,7 @@ private unsafe void ProcessEventBuffer(InputUpdateType updateType, ref InputEven
33183319
ProcessEvent(device, updateType, currentEventReadPtr, ref totalEventBytesProcessed);
33193320

33203321
m_InputEventStream.Advance(leaveEventInBuffer: false);
3321-
3322+
33223323
// Discard events in case the maximum event bytes per update has been exceeded
33233324
if (AreMaximumEventBytesPerUpdateExceeded(totalEventBytesProcessed))
33243325
break;
@@ -3366,14 +3367,15 @@ private unsafe void ProcessBeforeRenderStateEvents(out InputDevice device, out I
33663367
}
33673368
}
33683369

3370+
#if UNITY_EDITOR
33693371
// Handles editor-specific focus/background early-out behavior and advances the stream accordingly.
33703372
// Returns true if event should be skipped (stream advanced), false otherwise.
33713373
[MethodImpl(MethodImplOptions.AggressiveInlining)]
33723374
private unsafe bool SkipEventDueToEditorBehaviour(InputUpdateType updateType, FourCC currentEventType, bool dropStatusEvents, double currentEventTimeInternal)
33733375
{
33743376
var focusEventType = new FourCC(FocusConstants.kEventType);
33753377
var possibleFocusEvent = m_InputEventStream.Peek();
3376-
3378+
33773379
if (possibleFocusEvent != null)
33783380
{
33793381
if (possibleFocusEvent->type == focusEventType && !gameShouldGetInputRegardlessOfFocus)
@@ -3432,6 +3434,7 @@ private unsafe bool SkipEventDueToEditorBehaviour(InputUpdateType updateType, Fo
34323434
}
34333435
return false;
34343436
}
3437+
#endif
34353438

34363439
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34373440
private unsafe bool ShouldDeferEventBetweenEditorAndPlayerUpdates(InputUpdateType updateType, FourCC currentEventType, InputDevice device)
@@ -3826,29 +3829,6 @@ private void UpdateDeviceStateOnFocusLost(InputDevice device, bool runInBackgrou
38263829
}
38273830
}
38283831

3829-
/// <summary>
3830-
/// Determines if we should exit early from event processing without handling events.
3831-
/// </summary>
3832-
/// <param name="eventBuffer">The current event buffer</param>
3833-
/// <param name="canFlushBuffer">Whether the buffer can be flushed</param>
3834-
/// <param name="updateType">The current update type</param>
3835-
/// <returns>True if we should exit early, false otherwise.</returns>
3836-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3837-
private bool ShouldExitEarlyFromEventProcessing(FourCC currentEventType, InputUpdateType updateType)
3838-
{
3839-
#if UNITY_EDITOR
3840-
// Check various PlayMode specific early exit conditions
3841-
if (ShouldExitEarlyBasedOnBackgroundBehavior(currentEventType, updateType))
3842-
return true;
3843-
3844-
// When the game is playing and has focus, we never process input in editor updates.
3845-
// All we do is just switch to editor state buffers and then exit.
3846-
if ((gameIsPlaying && gameHasFocus && updateType == InputUpdateType.Editor))
3847-
return true;
3848-
#endif
3849-
return false;
3850-
}
3851-
38523832
/// <summary>
38533833
/// Determines if status events should be dropped and modifies early exit behavior accordingly.
38543834
/// </summary>

Packages/com.unity.inputsystem/InputSystem/LegacyInputManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private bool ShouldExitEarlyFromEventProcessing(InputUpdateType updateType)
170170

171171
return false;
172172
}
173-
173+
#if UNITY_EDITOR
174174
/// <summary>
175175
/// Checks background behavior conditions for early exit from event processing.
176176
/// </summary>
@@ -200,6 +200,7 @@ private bool ShouldExitEarlyBasedOnBackgroundBehavior(InputUpdateType updateType
200200

201201
return false;
202202
}
203+
#endif
203204

204205
[MethodImpl(MethodImplOptions.AggressiveInlining)]
205206
private unsafe bool LegacyEarlyOutFromEventProcessing(InputUpdateType updateType, ref InputEventBuffer eventBuffer, ref bool dropStatusEvents)

0 commit comments

Comments
 (0)