Skip to content

Commit 18a234c

Browse files
Cleanup tests & remove the need for the shortcutkeysconsume input setting.
1 parent 6640bde commit 18a234c

2 files changed

Lines changed: 14 additions & 35 deletions

File tree

Assets/Tests/InputSystem/CoreTests_ActionsPriority.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ private void ReleaseBindingsForActions(Keyboard keyboard, InputAction action1, I
112112
[TestCaseSource(nameof(TwoInputActionTestCases))]
113113
public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOther(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
114114
{
115-
InputSystem.settings.shortcutKeysConsumeInput = true;
116115
var keyboard = InputSystem.AddDevice<Keyboard>();
117116

118-
//var map = new InputActionMap("map");
119117
var action1 = twoInputActions.Action1;
120118
var action2 = twoInputActions.Action2;
121119

@@ -137,9 +135,6 @@ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOth
137135
// Cleanup key presses
138136
ReleaseBindingsForActions(keyboard, action1, action2);
139137

140-
// Update again to be sure released is true.
141-
InputSystem.Update();
142-
143138
Assert.That(action1.WasPerformedThisFrame(), Is.False);
144139
Assert.That(action2.WasPerformedThisFrame(), Is.False);
145140
}
@@ -149,7 +144,6 @@ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOth
149144
[TestCaseSource(nameof(TwoInputActionTestCases))]
150145
public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOtherInversePriorityOrder(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
151146
{
152-
InputSystem.settings.shortcutKeysConsumeInput = true;
153147
var keyboard = InputSystem.AddDevice<Keyboard>();
154148

155149
var action1 = twoInputActions.Action1;
@@ -166,10 +160,11 @@ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOth
166160

167161
PressBindingsForInputActions(keyboard, action1, action2);
168162

169-
// action2 is performed because action1 has a higher priority than action2.
163+
// action2 is performed because action2 has a higher priority than action1.
170164
Assert.That(action1.WasPerformedThisFrame(), Is.False);
171165
Assert.That(action2.WasPerformedThisFrame(), Is.True);
172166

167+
// Cleanup key presses
173168
ReleaseBindingsForActions(keyboard, action1, action2);
174169

175170
Assert.That(action1.WasPerformedThisFrame(), Is.False);
@@ -181,7 +176,6 @@ public void Actions_Priority_OnlyOneActionIsFired_WhenOnePriorityIsHigherThanOth
181176
[TestCaseSource(nameof(TwoInputActionTestCases))] // TODO: Darren, Should both actions be performed this frame here??
182177
public void Actions_Priority_BothActionsArePerformed_DueToKeyPressOrderForShortcut(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
183178
{
184-
InputSystem.settings.shortcutKeysConsumeInput = true;
185179
var keyboard = InputSystem.AddDevice<Keyboard>();
186180

187181
// We swap the order here of Action1 & Action2 so key presses are done backwards, binding before modifiers.
@@ -219,7 +213,6 @@ public void Actions_Priority_BothActionsArePerformed_DueToKeyPressOrderForShortc
219213
[TestCaseSource(nameof(TwoInputActionTestCases))]
220214
public void Actions_Priority_BothActionFires_WhenPriorityIsEqual(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
221215
{
222-
InputSystem.settings.shortcutKeysConsumeInput = true;
223216
var keyboard = InputSystem.AddDevice<Keyboard>();
224217

225218
var action1 = twoInputActions.Action1;
@@ -241,7 +234,6 @@ public void Actions_Priority_BothActionFires_WhenPriorityIsEqual(TwoInputActionD
241234
[TestCaseSource(nameof(TwoInputActionTestCases))]
242235
public void Actions_Priority_BothActionsFire_WhenPriorityIsZero(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
243236
{
244-
InputSystem.settings.shortcutKeysConsumeInput = true;
245237
var keyboard = InputSystem.AddDevice<Keyboard>();
246238

247239
var action1 = twoInputActions.Action1;
@@ -293,7 +285,6 @@ private static IEnumerable<TwoInputActionDataWrapper<InputAction, InputAction>>
293285
[TestCaseSource(nameof(TwoInputActionNoConflictingBindingTestCases))]
294286
public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoConflictingBinding(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
295287
{
296-
InputSystem.settings.shortcutKeysConsumeInput = true;
297288
var keyboard = InputSystem.AddDevice<Keyboard>();
298289

299290
var action1 = twoInputActions.Action1;
@@ -303,8 +294,7 @@ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoC
303294
action2.Priority = 1;
304295

305296
action1.m_ActionMap.Enable();
306-
action2.m_ActionMap.Enable();
307-
//
297+
308298
var action1WasPerformed = false;
309299
action1.performed += _ => action1WasPerformed = true;
310300

@@ -323,7 +313,6 @@ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoC
323313
[TestCaseSource(nameof(TwoInputActionNoConflictingBindingTestCases))]
324314
public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoConflictingBindingInverseOrder(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
325315
{
326-
InputSystem.settings.shortcutKeysConsumeInput = true;
327316
var keyboard = InputSystem.AddDevice<Keyboard>();
328317

329318
var action1 = twoInputActions.Action1;
@@ -333,8 +322,7 @@ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoC
333322
action2.Priority = 5;
334323

335324
action1.m_ActionMap.Enable();
336-
action2.m_ActionMap.Enable();
337-
//
325+
338326
var action1WasPerformed = false;
339327
action1.performed += _ => action1WasPerformed = true;
340328

@@ -353,7 +341,6 @@ public void Actions_Priority_BothActionsWithDifferentPriorityFire_WhenThereIsNoC
353341
[TestCaseSource(nameof(TwoInputActionNoConflictingBindingTestCases))]
354342
public void Actions_Priority_BothActionsWithEqualPriorityFire_WhenThereIsNoConflictingBinding(TwoInputActionDataWrapper<InputAction, InputAction> twoInputActions)
355343
{
356-
InputSystem.settings.shortcutKeysConsumeInput = true;
357344
var keyboard = InputSystem.AddDevice<Keyboard>();
358345

359346
var action1 = twoInputActions.Action1;
@@ -363,7 +350,6 @@ public void Actions_Priority_BothActionsWithEqualPriorityFire_WhenThereIsNoConfl
363350
action2.Priority = 5;
364351

365352
action1.m_ActionMap.Enable();
366-
action2.m_ActionMap.Enable();
367353

368354
var action1WasPerformed = false;
369355
action1.performed += _ => action1WasPerformed = true;

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ private void ComputeControlGroupingIfNecessary()
146146
if (memory.controlGroupingInitialized)
147147
return;
148148

149-
// If shortcut support is disabled, we simply put put all bindings at complexity=1 and
150-
// in their own group.
151-
var disableControlGrouping = !InputSystem.settings.shortcutKeysConsumeInput;
152-
153149
var currentGroup = 1u;
154150

155151
for (var i = 0; i < totalControlCount; ++i)
@@ -162,28 +158,25 @@ private void ComputeControlGroupingIfNecessary()
162158

163159
var action = GetActionOrNull(bindingIndex);
164160

165-
var priority = Math.Clamp(action != null && !disableControlGrouping ? action.Priority : 0, 0, 65536);
161+
var priority = Math.Clamp(action != null ? action.Priority : 0, 0, 65535);
166162

167163
controlGroupingAndPriority[i * 2 + 1] = (ushort)priority;
168164

169165
// Compute grouping. If already set, skip.
170166
if (controlGroupingAndPriority[i * 2] == 0)
171167
{
172-
if (!disableControlGrouping)
168+
for (var n = 0; n < totalControlCount; ++n)
173169
{
174-
for (var n = 0; n < totalControlCount; ++n)
175-
{
176-
// NOTE: We could compute group numbers based on device index + control offsets
177-
// and thus make them work globally in a stable way. But we'd need a mechanism
178-
// to then determine ordering of actions globally such that it is clear which
179-
// action gets a first shot at an input.
170+
// NOTE: We could compute group numbers based on device index + control offsets
171+
// and thus make them work globally in a stable way. But we'd need a mechanism
172+
// to then determine ordering of actions globally such that it is clear which
173+
// action gets a first shot at an input.
180174

181-
var otherControl = controls[n];
182-
if (control != otherControl)
183-
continue;
175+
var otherControl = controls[n];
176+
if (control != otherControl)
177+
continue;
184178

185-
controlGroupingAndPriority[n * 2] = (ushort)currentGroup;
186-
}
179+
controlGroupingAndPriority[n * 2] = (ushort)currentGroup;
187180
}
188181

189182
controlGroupingAndPriority[i * 2] = (ushort)currentGroup;

0 commit comments

Comments
 (0)