Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
updated the way we get the current source readings to be more perfrom…
Browse files Browse the repository at this point in the history
…ant (#6)
  • Loading branch information
StephenHodgson authored Apr 20, 2019
1 parent 63cdbfb commit a53def4
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public WindowsMixedRealityDataProvider(string name, uint priority, WindowsMixedR

private readonly WindowsMixedRealityControllerDataProviderProfile profile;

/// <summary>
/// The max expected sources is two - two controllers and/or two hands.
/// We'll set it to 20 just to be certain we can't run out of sources.
/// </summary>
public const int MaxInteractionSourceStates = 20;

/// <summary>
/// Dictionary to capture all active controllers detected
/// </summary>
Expand All @@ -62,7 +68,12 @@ public WindowsMixedRealityDataProvider(string name, uint priority, WindowsMixedR
/// <summary>
/// Cache of the states captured from the Unity InteractionManager for UWP
/// </summary>
private InteractionSourceState[] interactionManagerStates;
InteractionSourceState[] interactionManagerStates = new InteractionSourceState[MaxInteractionSourceStates];

/// <summary>
/// The number of states captured most recently
/// </summary>
private int numInteractionManagerStates;

/// <summary>
/// The current source state reading for the Unity InteractionManager for UWP
Expand Down Expand Up @@ -279,10 +290,10 @@ public override void Enable()
InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected;
InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost;

interactionManagerStates = InteractionManager.GetCurrentReading();
numInteractionManagerStates = InteractionManager.GetCurrentReading(interactionManagerStates);

// NOTE: We update the source state data, in case an app wants to query it on source detected.
for (var i = 0; i < interactionManagerStates?.Length; i++)
for (var i = 0; i < numInteractionManagerStates; i++)
{
var controller = GetController(interactionManagerStates[i].source);

Expand All @@ -306,9 +317,9 @@ public override void Update()
{
base.Update();

interactionManagerStates = InteractionManager.GetCurrentReading();
numInteractionManagerStates = InteractionManager.GetCurrentReading(interactionManagerStates);

for (var i = 0; i < interactionManagerStates?.Length; i++)
for (var i = 0; i < numInteractionManagerStates; i++)
{
GetController(interactionManagerStates[i].source, false)?.UpdateController(interactionManagerStates[i]);
}
Expand Down

0 comments on commit a53def4

Please sign in to comment.