Skip to content

Commit 42a0646

Browse files
author
David Kline
authored
Merge pull request #2890 from SimonDarksideJ/mrtk_development_UWPPerfFix
Fixed UWP Lag issue, changed from Event Based updates to polling.
2 parents d6ac441 + be853da commit 42a0646

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

Assets/MixedRealityToolkit/_Core/Devices/MixedReality/WindowsMixedRealityDeviceManager.cs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public WindowsMixedRealityDeviceManager(string name, uint priority) : base(name,
3535
/// </summary>
3636
private readonly Dictionary<uint, IMixedRealityController> activeControllers = new Dictionary<uint, IMixedRealityController>();
3737

38+
/// <summary>
39+
/// Cache of the states captured from the Unity InteractionManager for UWP
40+
/// </summary>
41+
InteractionSourceState[] interactionmanagerStates;
42+
43+
/// <summary>
44+
/// The current source state reading for the Unity InteractionManager for UWP
45+
/// </summary>
46+
public InteractionSourceState[] LastInteractionManagerStateReading { get; protected set; }
47+
3848
/// <inheritdoc/>
3949
public override IMixedRealityController[] GetActiveControllers()
4050
{
@@ -243,21 +253,18 @@ public override void Enable()
243253
}
244254

245255
InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected;
246-
InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
247-
InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed;
248-
InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased;
249256
InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost;
250257

251-
InteractionSourceState[] states = InteractionManager.GetCurrentReading();
258+
interactionmanagerStates = InteractionManager.GetCurrentReading();
252259

253260
// NOTE: We update the source state data, in case an app wants to query it on source detected.
254-
for (var i = 0; i < states.Length; i++)
261+
for (var i = 0; i < interactionmanagerStates?.Length; i++)
255262
{
256-
var controller = GetController(states[i].source);
263+
var controller = GetController(interactionmanagerStates[i].source);
257264

258265
if (controller != null)
259266
{
260-
controller.UpdateController(states[i]);
267+
controller.UpdateController(interactionmanagerStates[i]);
261268
MixedRealityManager.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
262269
}
263270
}
@@ -270,6 +277,26 @@ public override void Enable()
270277
}
271278
}
272279

280+
/// <inheritdoc/>
281+
public override void Update()
282+
{
283+
base.Update();
284+
285+
interactionmanagerStates = InteractionManager.GetCurrentReading();
286+
287+
for (var i = 0; i < interactionmanagerStates?.Length; i++)
288+
{
289+
var controller = GetController(interactionmanagerStates[i].source);
290+
291+
if (controller != null)
292+
{
293+
controller.UpdateController(interactionmanagerStates[i]);
294+
}
295+
}
296+
297+
LastInteractionManagerStateReading = interactionmanagerStates;
298+
}
299+
273300
private void RegisterGestureEvents()
274301
{
275302
if (gestureRecognizer == null)
@@ -333,9 +360,6 @@ public override void Disable()
333360
navigationGestureRecognizer?.Dispose();
334361

335362
InteractionManager.InteractionSourceDetected -= InteractionManager_InteractionSourceDetected;
336-
InteractionManager.InteractionSourcePressed -= InteractionManager_InteractionSourcePressed;
337-
InteractionManager.InteractionSourceUpdated -= InteractionManager_InteractionSourceUpdated;
338-
InteractionManager.InteractionSourceReleased -= InteractionManager_InteractionSourceReleased;
339363
InteractionManager.InteractionSourceLost -= InteractionManager_InteractionSourceLost;
340364

341365
InteractionSourceState[] states = InteractionManager.GetCurrentReading();
@@ -438,33 +462,6 @@ private void InteractionManager_InteractionSourceDetected(InteractionSourceDetec
438462
controller?.UpdateController(args.state);
439463
}
440464

441-
/// <summary>
442-
/// SDK Interaction Source Updated Event handler
443-
/// </summary>
444-
/// <param name="args">SDK source updated event arguments</param>
445-
private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs args)
446-
{
447-
GetController(args.state.source)?.UpdateController(args.state);
448-
}
449-
450-
/// <summary>
451-
/// SDK Interaction Source Pressed Event handler
452-
/// </summary>
453-
/// <param name="args">SDK source pressed event arguments</param>
454-
private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs args)
455-
{
456-
GetController(args.state.source)?.UpdateController(args.state);
457-
}
458-
459-
/// <summary>
460-
/// SDK Interaction Source Released Event handler
461-
/// </summary>
462-
/// <param name="args">SDK source released event arguments</param>
463-
private void InteractionManager_InteractionSourceReleased(InteractionSourceReleasedEventArgs args)
464-
{
465-
GetController(args.state.source)?.UpdateController(args.state);
466-
}
467-
468465
/// <summary>
469466
/// SDK Interaction Source Lost Event handler
470467
/// </summary>

0 commit comments

Comments
 (0)