Skip to content

Commit a9edd02

Browse files
Add optimization to ButtonControl
Also updates the mouse test that I believe would be impacted by the change.
1 parent 7bdfc96 commit a9edd02

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Controls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ public void Controls_OptimizedControls_TrivialControlsAreOptimized()
14281428
Assert.That(mouse.position.x.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatFloat));
14291429
Assert.That(mouse.position.y.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatFloat));
14301430
Assert.That(mouse.position.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatVector2));
1431-
Assert.That(mouse.leftButton.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatInvalid));
1431+
Assert.That(mouse.leftButton.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatBit));
14321432

14331433
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kUseOptimizedControls, false);
14341434
Assert.That(mouse.position.x.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatInvalid));

Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/ButtonControl.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,20 @@ internal void UpdateWasPressedEditor()
378378

379379
#endif // UNITY_EDITOR
380380

381+
protected override FourCC CalculateOptimizedControlDataType()
382+
{
383+
if (clamp == Clamp.None &&
384+
invert == false &&
385+
normalize == false &&
386+
scale == false &&
387+
m_StateBlock.format == InputStateBlock.FormatBit &&
388+
m_StateBlock.sizeInBits == 1 &&
389+
m_StateBlock.bitOffset == 0)
390+
return InputStateBlock.FormatBit;
391+
392+
return base.CalculateOptimizedControlDataType();
393+
}
394+
381395
// We make the current global default button press point available as a static so that we don't have to
382396
// constantly make the hop from InputSystem.settings -> InputManager.m_Settings -> defaultButtonPressPoint.
383397
internal static float s_GlobalDefaultButtonPressPoint;

Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/XR/Controls/PoseControl.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,7 @@ protected override FourCC CalculateOptimizedControlDataType()
252252
if (
253253
m_StateBlock.sizeInBits == PoseState.kSizeInBytes * 8 &&
254254
m_StateBlock.bitOffset == 0 &&
255-
isTracked.m_StateBlock.format == InputStateBlock.kFormatBit &&
256-
isTracked.m_StateBlock.sizeInBits == 1 &&
257-
isTracked.m_StateBlock.bitOffset == 0 &&
258-
isTracked.clamp == AxisControl.Clamp.None &&
259-
isTracked.invert == false &&
260-
isTracked.normalize == false &&
261-
isTracked.scale == false &&
255+
isTracked.optimizedControlDataType == InputStateBlock.kFormatBit &&
262256
trackingState.optimizedControlDataType == InputStateBlock.kFormatInt &&
263257
position.optimizedControlDataType == InputStateBlock.kFormatVector3 &&
264258
rotation.optimizedControlDataType == InputStateBlock.kFormatQuaternion &&

0 commit comments

Comments
 (0)