Skip to content

Commit 52159c1

Browse files
authored
Merge branch 'develop' into ekcoh/rebinding-issues-events
2 parents 9eeddc2 + 775282e commit 52159c1

File tree

8 files changed

+56
-3
lines changed

8 files changed

+56
-3
lines changed

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4394,6 +4394,15 @@ public void Devices_CanSetPollingFrequency()
43944394
Assert.That(InputSystem.pollingFrequency, Is.EqualTo(120).Within(0.000001));
43954395
}
43964396

4397+
#if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
4398+
[Test]
4399+
[Category("Devices")]
4400+
public void Devices_PollingFrequencyIsAtLeast60HzByDefault()
4401+
{
4402+
Assert.That(InputSystem.pollingFrequency, Is.GreaterThanOrEqualTo(60));
4403+
}
4404+
4405+
#else
43974406
[Test]
43984407
[Category("Devices")]
43994408
public void Devices_PollingFrequencyIs60HzByDefault()
@@ -4403,6 +4412,8 @@ public void Devices_PollingFrequencyIs60HzByDefault()
44034412
Assert.That(runtime.pollingFrequency, Is.EqualTo(60).Within(0.000001));
44044413
}
44054414

4415+
#endif
4416+
44064417
[Test]
44074418
[Category("Devices")]
44084419
public unsafe void Devices_CanInterceptAndHandleDeviceCommands()

Assets/Tests/InputSystem/Unity.InputSystem.Tests.asmdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
"name": "Unity",
6666
"expression": "6000.0.15",
6767
"define": "UNITY_INPUT_SYSTEM_SENDPOINTERHOVERTOPARENT"
68+
},
69+
{
70+
"name": "Unity",
71+
"expression": "6000.3.0a6",
72+
"define": "UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY"
6873
}
6974
],
7075
"noEngineReferences": false

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ however, it has to be formatted properly to pass verification tests.
9494
### Changed
9595
- Changed default input action asset name from New Controls to New Actions.
9696
- Added disabling of action maps in rebinding UI sample.
97+
- `InputSystem.pollingFrequency` is now initialized based on recommended polling frequency by the underlying platform on Unity versions newer than 6000.3.0a1. It can still be customized (set) during run-time as usual. Increasing polling frequency beyond the default 60Hz leads to less probability of input loss and reduces input latency.
9798

9899
### Added
99100
- An alternative way to access if an action state reached a certain phase during this rendering frame (Update()). This can be utilized even if the InputSystem update mode is set to manual or FixedUpdate. It can be used to access the action phase during rendering, eg for perform updates to the UI.

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,28 @@ public InputSettings.ScrollDeltaBehavior scrollDeltaBehavior
197197

198198
public float pollingFrequency
199199
{
200-
get => m_PollingFrequency;
200+
get
201+
{
202+
#if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
203+
return m_Runtime.pollingFrequency;
204+
#else
205+
return m_PollingFrequency;
206+
#endif
207+
}
208+
201209
set
202210
{
203211
////REVIEW: allow setting to zero to turn off polling altogether?
204212
if (value <= 0)
205213
throw new ArgumentException("Polling frequency must be greater than zero", "value");
206214

215+
#if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
216+
m_Runtime.pollingFrequency = value;
217+
#else
207218
m_PollingFrequency = value;
208219
if (m_Runtime != null)
209220
m_Runtime.pollingFrequency = value;
221+
#endif
210222
}
211223
}
212224

@@ -1924,8 +1936,10 @@ internal void InitializeData()
19241936

19251937
m_ScrollDeltaBehavior = InputSettings.ScrollDeltaBehavior.UniformAcrossAllPlatforms;
19261938

1939+
#if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
19271940
// Default polling frequency is 60 Hz.
19281941
m_PollingFrequency = 60;
1942+
#endif
19291943

19301944
// Default input event handled policy.
19311945
m_InputEventHandledPolicy = InputEventHandledPolicy.SuppressStateUpdates;
@@ -2180,7 +2194,9 @@ internal struct AvailableDevice
21802194

21812195
// Used by EditorInputControlLayoutCache to determine whether its state is outdated.
21822196
internal int m_LayoutRegistrationVersion;
2197+
#if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
21832198
private float m_PollingFrequency;
2199+
#endif
21842200
private InputEventHandledPolicy m_InputEventHandledPolicy;
21852201

21862202
internal InputControlLayout.Collection m_Layouts;
@@ -4134,7 +4150,9 @@ internal SerializedState SaveState()
41344150
return new SerializedState
41354151
{
41364152
layoutRegistrationVersion = m_LayoutRegistrationVersion,
4153+
#if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
41374154
pollingFrequency = m_PollingFrequency,
4155+
#endif
41384156
inputEventHandledPolicy = m_InputEventHandledPolicy,
41394157
devices = deviceArray,
41404158
availableDevices = m_AvailableDevices?.Take(m_AvailableDeviceCount).ToArray(),
@@ -4161,7 +4179,9 @@ internal void RestoreStateWithoutDevices(SerializedState state)
41614179
updateMask = state.updateMask;
41624180
scrollDeltaBehavior = state.scrollDeltaBehavior;
41634181
m_Metrics = state.metrics;
4182+
#if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
41644183
m_PollingFrequency = state.pollingFrequency;
4184+
#endif
41654185
m_InputEventHandledPolicy = state.inputEventHandledPolicy;
41664186

41674187
if (m_Settings != null)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ public static event InputDeviceFindControlLayoutDelegate onFindLayoutForDevice
13641364
/// The unit is Hertz. A value of 120, for example, means that devices are sampled 120 times
13651365
/// per second.
13661366
///
1367-
/// The default polling frequency is 60 Hz.
1367+
/// The default polling frequency is at least 60 Hz or what is suitable for the target device.
13681368
///
13691369
/// For devices that are polled, the frequency setting will directly translate to changes in the
13701370
/// <see cref="InputEvent.time"/> patterns. At 60 Hz, for example, timestamps for a specific,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,16 @@ public Action<bool> onPlayerFocusChanged
211211

212212
public float pollingFrequency
213213
{
214+
#if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
215+
get => NativeInputSystem.GetPollingFrequency();
216+
#else
214217
get => m_PollingFrequency;
218+
#endif
215219
set
216220
{
221+
#if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
217222
m_PollingFrequency = value;
223+
#endif
218224
NativeInputSystem.SetPollingFrequency(value);
219225
}
220226
}
@@ -246,7 +252,12 @@ public bool runInBackground
246252
#if UNITY_EDITOR
247253
private Action m_PlayerLoopInitialization;
248254
#endif
255+
#if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
256+
// From Unity 6000.3.0a2 (TODO Update comment and manifest before landing PR) this is handled by module
257+
// and initial value is suggested by the platform based on its supported device set.
258+
// In older version this is stored here and package override module/platform.
249259
private float m_PollingFrequency = 60.0f;
260+
#endif
250261
private bool m_DidCallOnShutdown = false;
251262
private void OnShutdown()
252263
{

Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
"name": "com.unity.modules.unityanalytics",
112112
"expression": "1",
113113
"define": "UNITY_INPUT_SYSTEM_ENABLE_ANALYTICS"
114+
},
115+
{
116+
"name": "Unity",
117+
"expression": "6000.3.0a6",
118+
"define": "UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY"
114119
}
115120
],
116121
"noEngineReferences": false

Packages/com.unity.inputsystem/Tests/TestFixture/InputTestRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public struct PairedUser
359359
public Action onShutdown { get; set; }
360360
public Action<bool> onPlayerFocusChanged { get; set; }
361361
public bool isPlayerFocused => m_HasFocus;
362-
public float pollingFrequency { get; set; }
362+
public float pollingFrequency { get; set; } = 60.0f; // At least 60 Hz by default
363363
public double currentTime { get; set; }
364364
public double currentTimeForFixedUpdate { get; set; }
365365
public float unscaledGameTime { get; set; } = 1;

0 commit comments

Comments
 (0)