Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1007 Fixed so that SteamVR.enabled doesn't allocate each frame #1073

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions Assets/SteamVR/Input/SteamVR_ActionSet_Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ public static void SetChanged()
changed = true;
}

private static Dictionary<int, VRActiveActionSet_t[]> pool;
private static VRActiveActionSet_t[] activeActionSetsArray;

private static void UpdateActionSetsArray()
{
List<VRActiveActionSet_t> activeActionSetsList = new List<VRActiveActionSet_t>();

var activeActionSetsCount = 0;
SteamVR_Input_Sources[] sources = SteamVR_Input_Source.GetAllSources();

if (pool == null)
{
pool = new Dictionary<int, VRActiveActionSet_t[]>();
activeActionSetsArray = new VRActiveActionSet_t[SteamVR_Input.actionSets.Length * sources.Length];
}

for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionSets.Length; actionSetIndex++)
{
SteamVR_ActionSet set = SteamVR_Input.actionSets[actionSetIndex];
Expand All @@ -95,20 +103,44 @@ private static void UpdateActionSetsArray()
activeSet.nPriority = set.ReadRawSetPriority(source);
activeSet.ulRestrictedToDevice = SteamVR_Input_Source.GetHandle(source);

int insertionIndex = 0;
for (insertionIndex = 0; insertionIndex < activeActionSetsList.Count; insertionIndex++)
int insertionIndex;
for (insertionIndex = 0; insertionIndex < activeActionSetsCount; insertionIndex++)
{
if (activeActionSetsList[insertionIndex].nPriority > activeSet.nPriority)
if (activeActionSetsArray[insertionIndex].nPriority > activeSet.nPriority)
break;
}
activeActionSetsList.Insert(insertionIndex, activeSet);

for (int i = activeActionSetsCount; i > insertionIndex; i--)
{
activeActionSetsArray[i] = activeActionSetsArray[i - 1];
}
activeActionSetsArray[insertionIndex] = activeSet;
activeActionSetsCount++;
}
}
}

if (rawActiveActionSetArray != null && rawActiveActionSetArray.Length != activeActionSetsCount)
{
pool[rawActiveActionSetArray.Length] = rawActiveActionSetArray;
rawActiveActionSetArray = null;
}

if (rawActiveActionSetArray == null)
{
if (!pool.ContainsKey(activeActionSetsCount))
{
rawActiveActionSetArray = new VRActiveActionSet_t[activeActionSetsCount];
pool[activeActionSetsCount] = rawActiveActionSetArray;
}
else
rawActiveActionSetArray = pool[activeActionSetsCount];
}

changed = false;

rawActiveActionSetArray = activeActionSetsList.ToArray();
for (int i = 0; i < activeActionSetsCount; i++)
rawActiveActionSetArray[i] = activeActionSetsArray[i];

if (Application.isEditor || updateDebugTextInBuilds)
UpdateDebugText();
Expand Down
10 changes: 6 additions & 4 deletions Assets/SteamVR/Scripts/SteamVR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public class SteamVR : System.IDisposable

// Set this to false to keep from auto-initializing when calling SteamVR.instance.
private static bool _enabled = true;
private static readonly string[] SupportedDevices = XRSettings.supportedDevices;

public static bool enabled
{
get
{
#if UNITY_2020_1_OR_NEWER || OPENVR_XR_API
if (XRSettings.supportedDevices.Length == 0)
if (SupportedDevices.Length == 0)
enabled = false;
#else
if (!XRSettings.enabled)
Expand Down Expand Up @@ -127,11 +129,11 @@ private static void ReportGeneralErrors()

if (XRSettings.enabled == false)
errorLog += "VR may be disabled in player settings. Go to player settings in the editor and check the 'Virtual Reality Supported' checkbox'. ";
if (XRSettings.supportedDevices != null && XRSettings.supportedDevices.Length > 0)
if (SupportedDevices != null && SupportedDevices.Length > 0)
{
if (XRSettings.supportedDevices.Contains("OpenVR") == false)
if (SupportedDevices.Contains("OpenVR") == false)
errorLog += "OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in player settings. ";
else if (XRSettings.supportedDevices.First().Contains("OpenVR") == false)
else if (SupportedDevices.First().Contains("OpenVR") == false)
errorLog += "OpenVR is not first in your list of supported virtual reality SDKs. <b>This is okay, but if you have an Oculus device plugged in, and Oculus above OpenVR in this list, it will try and use the Oculus SDK instead of OpenVR.</b> ";
}
else
Expand Down