@@ -15,16 +15,32 @@ namespace Valve.VR
1515 /// </summary>
1616 public static class SteamVR_ActionSet_Manager
1717 {
18- public static VRActiveActionSet_t [ ] rawActiveActionSetArray ;
18+ public static VRActiveActionSet_t [ ] rawActiveActionSetArray
19+ {
20+ get
21+ {
22+ if ( currentArraySize <= 0 )
23+ return null ;
24+ else
25+ return poolActiveActionSetArrays [ currentArraySize ] ;
26+ }
27+ }
1928
2029 [ NonSerialized ]
2130 private static uint activeActionSetSize ;
2231
32+ [ NonSerialized ]
2333 private static bool changed = false ;
2434
35+ [ NonSerialized ]
36+ private static int currentArraySize ;
37+ [ NonSerialized ]
38+ private static Dictionary < int , VRActiveActionSet_t [ ] > poolActiveActionSetArrays ;
39+
2540 public static void Initialize ( )
2641 {
2742 activeActionSetSize = ( uint ) ( Marshal . SizeOf ( typeof ( VRActiveActionSet_t ) ) ) ;
43+ poolActiveActionSetArrays = new Dictionary < int , VRActiveActionSet_t [ ] > ( ) ;
2844 }
2945
3046 /// <summary>
@@ -74,10 +90,38 @@ public static void SetChanged()
7490 changed = true ;
7591 }
7692
93+ private static int GetNewArraySize ( )
94+ {
95+ int size = 0 ;
96+
97+ SteamVR_Input_Sources [ ] sources = SteamVR_Input_Source . GetAllSources ( ) ;
98+ for ( int actionSetIndex = 0 ; actionSetIndex < SteamVR_Input . actionSets . Length ; actionSetIndex ++ )
99+ {
100+ SteamVR_ActionSet set = SteamVR_Input . actionSets [ actionSetIndex ] ;
101+
102+ for ( int sourceIndex = 0 ; sourceIndex < sources . Length ; sourceIndex ++ )
103+ {
104+ SteamVR_Input_Sources source = sources [ sourceIndex ] ;
105+
106+ if ( set . ReadRawSetActive ( source ) )
107+ {
108+ size ++ ;
109+ }
110+ }
111+ }
112+
113+ return size ;
114+ }
115+
77116 private static void UpdateActionSetsArray ( )
78117 {
79- List < VRActiveActionSet_t > activeActionSetsList = new List < VRActiveActionSet_t > ( ) ;
118+ int newArraySize = GetNewArraySize ( ) ;
119+ if ( poolActiveActionSetArrays . ContainsKey ( newArraySize ) == false )
120+ {
121+ poolActiveActionSetArrays [ newArraySize ] = new VRActiveActionSet_t [ newArraySize ] ;
122+ }
80123
124+ int arrayIndex = 0 ;
81125 SteamVR_Input_Sources [ ] sources = SteamVR_Input_Source . GetAllSources ( ) ;
82126
83127 for ( int actionSetIndex = 0 ; actionSetIndex < SteamVR_Input . actionSets . Length ; actionSetIndex ++ )
@@ -90,25 +134,17 @@ private static void UpdateActionSetsArray()
90134
91135 if ( set . ReadRawSetActive ( source ) )
92136 {
93- VRActiveActionSet_t activeSet = new VRActiveActionSet_t ( ) ;
94- activeSet . ulActionSet = set . handle ;
95- activeSet . nPriority = set . ReadRawSetPriority ( source ) ;
96- activeSet . ulRestrictedToDevice = SteamVR_Input_Source . GetHandle ( source ) ;
97-
98- int insertionIndex = 0 ;
99- for ( insertionIndex = 0 ; insertionIndex < activeActionSetsList . Count ; insertionIndex ++ )
100- {
101- if ( activeActionSetsList [ insertionIndex ] . nPriority > activeSet . nPriority )
102- break ;
103- }
104- activeActionSetsList . Insert ( insertionIndex , activeSet ) ;
137+ poolActiveActionSetArrays [ newArraySize ] [ arrayIndex ] . ulActionSet = set . handle ;
138+ poolActiveActionSetArrays [ newArraySize ] [ arrayIndex ] . nPriority = set . ReadRawSetPriority ( source ) ;
139+ poolActiveActionSetArrays [ newArraySize ] [ arrayIndex ] . ulRestrictedToDevice = SteamVR_Input_Source . GetHandle ( source ) ;
140+
141+ arrayIndex ++ ;
105142 }
106143 }
107144 }
108145
109146 changed = false ;
110-
111- rawActiveActionSetArray = activeActionSetsList . ToArray ( ) ;
147+ currentArraySize = newArraySize ;
112148
113149 if ( Application . isEditor || updateDebugTextInBuilds )
114150 UpdateDebugText ( ) ;
0 commit comments