Skip to content

Commit 063ddb9

Browse files
committed
reduce complexity for checking UI interactions in update - frame based approach - track frame of interest in action
1 parent f156ad3 commit 063ddb9

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,7 @@ public unsafe bool WasPressedThisFrame()
12611261
if (state != null)
12621262
{
12631263
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
1264-
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
1265-
return actionStatePtr->pressedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
1264+
return actionStatePtr->pressedInUpdate == ExpectedFrame();
12661265
}
12671266

12681267
return false;
@@ -1310,8 +1309,7 @@ public unsafe bool WasReleasedThisFrame()
13101309
if (state != null)
13111310
{
13121311
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
1313-
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
1314-
return actionStatePtr->releasedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
1312+
return actionStatePtr->releasedInUpdate == ExpectedFrame();
13151313
}
13161314

13171315
return false;
@@ -1369,8 +1367,7 @@ public unsafe bool WasPerformedThisFrame()
13691367
if (state != null)
13701368
{
13711369
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
1372-
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
1373-
return actionStatePtr->lastPerformedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
1370+
return actionStatePtr->lastPerformedInUpdate == ExpectedFrame();
13741371
}
13751372

13761373
return false;
@@ -1449,8 +1446,7 @@ public unsafe bool WasCompletedThisFrame()
14491446
if (state != null)
14501447
{
14511448
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
1452-
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
1453-
return actionStatePtr->lastCompletedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
1449+
return actionStatePtr->lastCompletedInUpdate == ExpectedFrame();
14541450
}
14551451

14561452
return false;

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ private void ProcessButtonState(ref TriggerState trigger, int actionIndex, Bindi
15631563
var actionState = &actionStates[actionIndex];
15641564
if (!actionState->isPressed && actuation >= pressPoint)
15651565
{
1566-
actionState->pressedInUpdate = InputUpdate.s_UpdateStepCount;
1566+
actionState->pressedInUpdate = Time.frameCount;
15671567
actionState->isPressed = true;
15681568
actionState->frame = Time.frameCount;
15691569
}
@@ -1572,7 +1572,7 @@ private void ProcessButtonState(ref TriggerState trigger, int actionIndex, Bindi
15721572
var releasePoint = pressPoint * ButtonControl.s_GlobalDefaultButtonReleaseThreshold;
15731573
if (actuation <= releasePoint)
15741574
{
1575-
actionState->releasedInUpdate = InputUpdate.s_UpdateStepCount;
1575+
actionState->releasedInUpdate = Time.frameCount;
15761576
actionState->isPressed = false;
15771577
actionState->frame = Time.frameCount;
15781578
}
@@ -2436,7 +2436,7 @@ private void ChangePhaseOfActionInternal(int actionIndex, TriggerState* actionSt
24362436
newState.frame = Time.frameCount;
24372437
if (newPhase == InputActionPhase.Performed)
24382438
{
2439-
newState.lastPerformedInUpdate = InputUpdate.s_UpdateStepCount;
2439+
newState.lastPerformedInUpdate = Time.frameCount;
24402440
newState.lastCanceledInUpdate = actionState->lastCanceledInUpdate;
24412441

24422442
// When we perform an action, we mark the event handled such that FireStateChangeNotifications()
@@ -2464,7 +2464,7 @@ private void ChangePhaseOfActionInternal(int actionIndex, TriggerState* actionSt
24642464
// To replicate the behavior of releasedInUpdate where it doesn't get updated when the action is disabled
24652465
// from being performed, we skip updating lastCompletedInUpdate if Disabled is the phase after Canceled.
24662466
if (actionState->phase == InputActionPhase.Performed && newPhase != InputActionPhase.Performed && !isDisablingAction)
2467-
newState.lastCompletedInUpdate = InputUpdate.s_UpdateStepCount;
2467+
newState.lastCompletedInUpdate = Time.frameCount;
24682468
else
24692469
newState.lastCompletedInUpdate = actionState->lastCompletedInUpdate;
24702470

@@ -3635,11 +3635,11 @@ public struct TriggerState
36353635
[FieldOffset(24)] private ushort m_BindingIndex;
36363636
[FieldOffset(26)] private ushort m_InteractionIndex;
36373637
[FieldOffset(28)] private float m_Magnitude;
3638-
[FieldOffset(32)] private uint m_LastPerformedInUpdate;
3638+
[FieldOffset(32)] private int m_LastPerformedInUpdate;
36393639
[FieldOffset(36)] private uint m_LastCanceledInUpdate;
3640-
[FieldOffset(40)] private uint m_PressedInUpdate;
3641-
[FieldOffset(44)] private uint m_ReleasedInUpdate;
3642-
[FieldOffset(48)] private uint m_LastCompletedInUpdate;
3640+
[FieldOffset(40)] private int m_PressedInUpdate;
3641+
[FieldOffset(44)] private int m_ReleasedInUpdate;
3642+
[FieldOffset(48)] private int m_LastCompletedInUpdate;
36433643
[FieldOffset(52)] private int m_Frame;
36443644

36453645
/// <summary>
@@ -3790,7 +3790,7 @@ public int interactionIndex
37903790
/// Update step count (<see cref="InputUpdate.s_UpdateStepCount"/>) in which action triggered/performed last.
37913791
/// Zero if the action did not trigger yet. Also reset to zero when the action is hard reset.
37923792
/// </summary>
3793-
public uint lastPerformedInUpdate
3793+
public int lastPerformedInUpdate
37943794
{
37953795
get => m_LastPerformedInUpdate;
37963796
set => m_LastPerformedInUpdate = value;
@@ -3806,7 +3806,7 @@ internal int frame
38063806
/// Update step count (<see cref="InputUpdate.s_UpdateStepCount"/>) in which action completed last.
38073807
/// Zero if the action did not become completed yet. Also reset to zero when the action is hard reset.
38083808
/// </summary>
3809-
public uint lastCompletedInUpdate
3809+
public int lastCompletedInUpdate
38103810
{
38113811
get => m_LastCompletedInUpdate;
38123812
set => m_LastCompletedInUpdate = value;
@@ -3818,13 +3818,13 @@ public uint lastCanceledInUpdate
38183818
set => m_LastCanceledInUpdate = value;
38193819
}
38203820

3821-
public uint pressedInUpdate
3821+
public int pressedInUpdate
38223822
{
38233823
get => m_PressedInUpdate;
38243824
set => m_PressedInUpdate = value;
38253825
}
38263826

3827-
public uint releasedInUpdate
3827+
public int releasedInUpdate
38283828
{
38293829
get => m_ReleasedInUpdate;
38303830
set => m_ReleasedInUpdate = value;

0 commit comments

Comments
 (0)