Skip to content

Commit

Permalink
Fixed (?) input actions
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Dec 30, 2024
1 parent 97337a5 commit c37bf0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
31 changes: 22 additions & 9 deletions plugin_OpenVR/EvrInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,27 @@ public EVRInputError Register()
var pHandle = Handle;
var error = OpenVR.Input.GetActionHandle(Name, ref pHandle);

Host?.Log(error is EVRInputError.None
? $"Registered {Name} as {pHandle}"
: $"Error registering {Name}: {error}");

Handle = pHandle;
return error;
}

public bool UpdateState()
public bool UpdateState(bool log = false)
{
var result = Type switch
{
"boolean" => GetDigitalState(),
"vector2" => GetAnalogState(),
"boolean" => GetDigitalState(log),
"vector2" => GetAnalogState(log),
_ => false
};

return result || Requirement is "optional";
}

private bool GetDigitalState()
private bool GetDigitalState(bool log = false)
{
if (!SteamVR.Initialized || OpenVR.Input is null) return false; // Sanity check

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

DataDigital = pData;

if (error == EVRInputError.None) return DataDigital.bState;
if (pData.bChanged) Host?.Log($"{Name} -> {pData.bState}");

if (error == EVRInputError.None) return true;
Host?.Log($"GetDigitalActionData call error: {error}", LogSeverity.Error);
return false;
}

private bool GetAnalogState()
private bool GetAnalogState(bool log = false)
{
if (!SteamVR.Initialized || OpenVR.Input is null) return false; // Sanity check

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

DataAnalog = pData;

if (error == EVRInputError.None) return DataDigital.bState;
if (log && pData.deltaX != 0.0f || pData.deltaY != 0.0f || pData.deltaZ != 0.0f)
Host?.Log($"{Name} -> <{pData.x}, {pData.y}, {pData.z}>");

if (error == EVRInputError.None) return true;
Host?.Log($"GetAnalogActionData call error: {error}", LogSeverity.Error);
return false;
}
Expand All @@ -243,6 +252,8 @@ public class SteamEvrInput(IAmethystHost host, SteamVR parent)
private IAmethystHost Host { get; } = host;
public ActionsManifest RegisteredActions { get; set; } = new();
private SteamVR Parent { get; } = parent;
public bool ActionsInitialized { get; set; }
public bool LogActionDataChanges { get; set; }

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

// Return OK
Host.Log("EVR Input Actions initialized OK");
ActionsInitialized = true;
return true;
}

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

/**********************************************/
// Check if VR controllers are valid
Expand Down Expand Up @@ -402,7 +415,7 @@ public bool UpdateActionStates()
// Here, update the actions and grab data-s
/**********************************************/

return RegisteredActions.Actions.All(x => x.UpdateState());
return RegisteredActions.Actions.All(x => x.UpdateState(LogActionDataChanges));
}

public static FileInfo GetProgramLocation()
Expand Down
7 changes: 7 additions & 0 deletions plugin_OpenVR/OpenVR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,13 @@ private void UpdateBindingTexts()
}
}

public string ToggleActionLogging()
{
if (VrInput is null) return "VR Input was not initialized!";
VrInput.LogActionDataChanges = !VrInput.LogActionDataChanges;
return $"Action data changes logging {(VrInput.LogActionDataChanges ? "enabled" : "disabled")}";
}

#endregion
}

Expand Down

0 comments on commit c37bf0f

Please sign in to comment.