Skip to content

Commit c37bf0f

Browse files
committed
Fixed (?) input actions
1 parent 97337a5 commit c37bf0f

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

plugin_OpenVR/EvrInput.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,27 @@ public EVRInputError Register()
184184
var pHandle = Handle;
185185
var error = OpenVR.Input.GetActionHandle(Name, ref pHandle);
186186

187+
Host?.Log(error is EVRInputError.None
188+
? $"Registered {Name} as {pHandle}"
189+
: $"Error registering {Name}: {error}");
190+
187191
Handle = pHandle;
188192
return error;
189193
}
190194

191-
public bool UpdateState()
195+
public bool UpdateState(bool log = false)
192196
{
193197
var result = Type switch
194198
{
195-
"boolean" => GetDigitalState(),
196-
"vector2" => GetAnalogState(),
199+
"boolean" => GetDigitalState(log),
200+
"vector2" => GetAnalogState(log),
197201
_ => false
198202
};
199203

200204
return result || Requirement is "optional";
201205
}
202206

203-
private bool GetDigitalState()
207+
private bool GetDigitalState(bool log = false)
204208
{
205209
if (!SteamVR.Initialized || OpenVR.Input is null) return false; // Sanity check
206210

@@ -212,12 +216,14 @@ private bool GetDigitalState()
212216

213217
DataDigital = pData;
214218

215-
if (error == EVRInputError.None) return DataDigital.bState;
219+
if (pData.bChanged) Host?.Log($"{Name} -> {pData.bState}");
220+
221+
if (error == EVRInputError.None) return true;
216222
Host?.Log($"GetDigitalActionData call error: {error}", LogSeverity.Error);
217223
return false;
218224
}
219225

220-
private bool GetAnalogState()
226+
private bool GetAnalogState(bool log = false)
221227
{
222228
if (!SteamVR.Initialized || OpenVR.Input is null) return false; // Sanity check
223229

@@ -229,7 +235,10 @@ private bool GetAnalogState()
229235

230236
DataAnalog = pData;
231237

232-
if (error == EVRInputError.None) return DataDigital.bState;
238+
if (log && pData.deltaX != 0.0f || pData.deltaY != 0.0f || pData.deltaZ != 0.0f)
239+
Host?.Log($"{Name} -> <{pData.x}, {pData.y}, {pData.z}>");
240+
241+
if (error == EVRInputError.None) return true;
233242
Host?.Log($"GetAnalogActionData call error: {error}", LogSeverity.Error);
234243
return false;
235244
}
@@ -243,6 +252,8 @@ public class SteamEvrInput(IAmethystHost host, SteamVR parent)
243252
private IAmethystHost Host { get; } = host;
244253
public ActionsManifest RegisteredActions { get; set; } = new();
245254
private SteamVR Parent { get; } = parent;
255+
public bool ActionsInitialized { get; set; }
256+
public bool LogActionDataChanges { get; set; }
246257

247258
public bool TrackerFreezeActionData => RegisteredActions["/actions/default/in/TrackerFreeze"]?.Data ?? false;
248259
public bool TrackerFlipToggleData => RegisteredActions["/actions/default/in/FlipToggle"]?.Data ?? false;
@@ -362,17 +373,19 @@ public bool InitInputActions()
362373
catch (Exception e)
363374
{
364375
Host.Log($"EVR Input Actions init error: {e.Message} at {e.StackTrace}");
365-
return true;
376+
return false;
366377
}
367378

368379
// Return OK
369380
Host.Log("EVR Input Actions initialized OK");
381+
ActionsInitialized = true;
370382
return true;
371383
}
372384

373385
public bool UpdateActionStates()
374386
{
375387
if (!SteamVR.Initialized || OpenVR.Input is null) return false; // Sanity check
388+
if (!ActionsInitialized) return true;
376389

377390
/**********************************************/
378391
// Check if VR controllers are valid
@@ -402,7 +415,7 @@ public bool UpdateActionStates()
402415
// Here, update the actions and grab data-s
403416
/**********************************************/
404417

405-
return RegisteredActions.Actions.All(x => x.UpdateState());
418+
return RegisteredActions.Actions.All(x => x.UpdateState(LogActionDataChanges));
406419
}
407420

408421
public static FileInfo GetProgramLocation()

plugin_OpenVR/OpenVR.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,13 @@ private void UpdateBindingTexts()
11271127
}
11281128
}
11291129

1130+
public string ToggleActionLogging()
1131+
{
1132+
if (VrInput is null) return "VR Input was not initialized!";
1133+
VrInput.LogActionDataChanges = !VrInput.LogActionDataChanges;
1134+
return $"Action data changes logging {(VrInput.LogActionDataChanges ? "enabled" : "disabled")}";
1135+
}
1136+
11301137
#endregion
11311138
}
11321139

0 commit comments

Comments
 (0)