Skip to content

Commit 6640bde

Browse files
Add fix for priorites of the same level not both firing.
1 parent 8484453 commit 6640bde

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ private void SplitUpMapAndControlAndBindingIndex(long mapControlAndBindingIndex,
14061406
/// Extract the 'complexity' component from the provided bit packed argument (monitor index).
14071407
/// </summary>
14081408
/// <param name="mapControlAndBindingIndex">Represents a monitor index, which is a bit packed field containing multiple components.</param>
1409-
internal static int GetComplexityFromMonitorIndex(long mapControlAndBindingIndex)
1409+
internal static int GetPriorityFromMonitorIndex(long mapControlAndBindingIndex)
14101410
{
14111411
return (int)((mapControlAndBindingIndex >> 48) & 0xff);
14121412
}
@@ -2467,8 +2467,8 @@ private void ChangePhaseOfActionInternal(int actionIndex, TriggerState* actionSt
24672467
newState.lastCanceledInUpdate = actionState->lastCanceledInUpdate;
24682468

24692469
// When we perform an action, we mark the event handled such that FireStateChangeNotifications()
2470-
// can then reset state monitors in the same group.
2471-
// NOTE: We don't consume for controls at binding complexity 1. Those we fire in unison.
2470+
// can then reset state monitors in the same group (strictly lower binding priority only).
2471+
// NOTE: We don't consume for controls at binding priority 0. Those we fire in unison.
24722472
if (controlGroupingAndPriority[trigger.controlIndex * 2 + 1] > 0 &&
24732473
// we can end up switching to performed state from an interaction with a timeout, at which point
24742474
// the original event will probably have been removed from memory, so make sure to check

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ public void SortMonitorsByIndex()
263263
{
264264
for (var j = i; j > 0; --j)
265265
{
266-
// Sort by complexities only to keep the sort stable
267-
// i.e. don't reverse the order of controls which have the same complexity
268-
var firstComplexity = InputActionState.GetComplexityFromMonitorIndex(listeners[j - 1].monitorIndex);
269-
var secondComplexity = InputActionState.GetComplexityFromMonitorIndex(listeners[j].monitorIndex);
270-
if (firstComplexity >= secondComplexity)
266+
// Sort by priorities only to keep the sort stable
267+
// i.e. don't reverse the order of controls which have the same priority
268+
var firstPriority = InputActionState.GetPriorityFromMonitorIndex(listeners[j - 1].monitorIndex);
269+
var secondPriority = InputActionState.GetPriorityFromMonitorIndex(listeners[j].monitorIndex);
270+
if (firstPriority >= secondPriority)
271271
break;
272272

273273
listeners.SwapElements(j, j - 1);
@@ -408,6 +408,7 @@ internal unsafe void FireStateChangeNotifications(int deviceIndex, double intern
408408
if (!previouslyHandled && eventPtr->handled)
409409
{
410410
var groupIndex = listeners[i].groupIndex;
411+
var handlerPriority = InputActionState.GetPriorityFromMonitorIndex(listener.monitorIndex);
411412
for (var n = i + 1; n < signals.length; ++n)
412413
{
413414
// NOTE: We restrict the preemption logic here to a single monitor. Otherwise,
@@ -419,7 +420,13 @@ internal unsafe void FireStateChangeNotifications(int deviceIndex, double intern
419420
// Note that this implies there there is *NO* preemption between singleton
420421
// InputActions. This isn't intuitive.
421422
if (listeners[n].groupIndex == groupIndex && listeners[n].monitor == listener.monitor)
422-
signals.ClearBit(n);
423+
{
424+
// Only clear strictly lower binding priorities so equal priorities still
425+
// fire in unison (same as priority 0, but with consumption among lower tiers).
426+
var candidatePriority = InputActionState.GetPriorityFromMonitorIndex(listeners[n].monitorIndex);
427+
if (candidatePriority < handlerPriority)
428+
signals.ClearBit(n);
429+
}
423430
}
424431
}
425432

0 commit comments

Comments
 (0)