Skip to content

Commit

Permalink
Fixed (removed) dynamic casts
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Dec 21, 2024
1 parent 8a58f16 commit 6e8bf81
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions plugin_OpenVR/OpenVR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ public void DisplayToast((string Title, string Text) message)
if (!Initialized || OpenVR.System is null) return true; // Sanity check

// Auto-returns null if the service is null
DriverService?.RequestVrRestart(reason);
if (IsEmulationEnabled)
_00driverService?.RequestVrRestart(reason);
else _driverService?.RequestVrRestart(reason);

return true; // Wait and return
}
catch (Exception)
Expand Down Expand Up @@ -572,7 +575,10 @@ public TrackerBase GetTrackerPose(string contains, bool canBeFromAmethyst = true

var enumTrackerBases = trackerBases.ToList();
foreach (var trackerBase in enumTrackerBases.ToList())
DriverService?.SetTrackerState(trackerBase.ComTracker());
if (IsEmulationEnabled)
_00driverService?.SetTrackerState(trackerBase.ComTracker00());
else
_driverService?.SetTrackerState(trackerBase.ComTracker());

return Task.FromResult(wantReply ? enumTrackerBases.Select(x => (x, true)) : null);
}
Expand All @@ -596,7 +602,10 @@ public TrackerBase GetTrackerPose(string contains, bool canBeFromAmethyst = true

var enumTrackerBases = trackerBases.ToList();
foreach (var trackerBase in enumTrackerBases.ToList())
DriverService?.UpdateTracker(trackerBase.ComTracker());
if (IsEmulationEnabled)
_00driverService?.UpdateTracker(trackerBase.ComTracker00());
else
_driverService?.UpdateTracker(trackerBase.ComTracker());

return Task.FromResult(wantReply ? enumTrackerBases.Select(x => (x, true)) : null);
}
Expand Down Expand Up @@ -631,13 +640,16 @@ public Task ProcessKeyInput(IKeyInputAction action, object data, TrackerType? re
switch (data)
{
case bool boolData:
DriverService?.UpdateInputBoolean((driver_00Amethyst.dTrackerType)trackerType, action.Guid, Convert.ToSByte(boolData));
if (IsEmulationEnabled)
_00driverService?.UpdateInputBoolean((driver_00Amethyst.dTrackerType)trackerType, action.Guid, Convert.ToSByte(boolData));
break;
case float scalarData:
DriverService?.UpdateInputScalar((driver_00Amethyst.dTrackerType)trackerType, action.Guid, scalarData);
if (IsEmulationEnabled)
_00driverService?.UpdateInputScalar((driver_00Amethyst.dTrackerType)trackerType, action.Guid, scalarData);
break;
case double scalarData:
DriverService?.UpdateInputScalar((driver_00Amethyst.dTrackerType)trackerType, action.Guid, (float)scalarData);
if (IsEmulationEnabled)
_00driverService?.UpdateInputScalar((driver_00Amethyst.dTrackerType)trackerType, action.Guid, (float)scalarData);
break;
default:
Host?.Log($"Data {data} with type {data.GetType()} was not processed because its type is not supported.");
Expand Down Expand Up @@ -1084,6 +1096,23 @@ public static driver_Amethyst.dTrackerBase ComTracker(this TrackerBase tracker)
};
}

public static driver_00Amethyst.dTrackerBase ComTracker00(this TrackerBase tracker)
{
return new driver_00Amethyst.dTrackerBase
{
ConnectionState = Convert.ToSByte(tracker.ConnectionState),
TrackingState = Convert.ToSByte(tracker.TrackingState == TrackedJointState.StateTracked),
Serial = tracker.Serial,
Role = (driver_00Amethyst.dTrackerType)tracker.Role,
Position = tracker.Position.ComVector00(),
Orientation = tracker.Orientation.ComQuaternion00(),
Velocity = tracker.Velocity.ComVector00(),
Acceleration = tracker.Acceleration.ComVector00(),
AngularVelocity = tracker.AngularVelocity.ComVector00(),
AngularAcceleration = tracker.AngularAcceleration.ComVector00()
};
}

public static driver_Amethyst.dVector3 ComVector(this Vector3 v)
{
return new driver_Amethyst.dVector3 { X = v.X, Y = v.Y, Z = v.Z };
Expand All @@ -1100,6 +1129,22 @@ public static driver_Amethyst.dQuaternion ComQuaternion(this Quaternion q)
return new driver_Amethyst.dQuaternion { X = q.X, Y = q.Y, Z = q.Z, W = q.W };
}

public static driver_00Amethyst.dVector3 ComVector00(this Vector3 v)
{
return new driver_00Amethyst.dVector3 { X = v.X, Y = v.Y, Z = v.Z };
}

public static driver_00Amethyst.dVector3Nullable ComVector00(this Vector3? v)
{
return new driver_00Amethyst.dVector3Nullable
{ HasValue = Convert.ToSByte(v.HasValue), Value = v?.ComVector00() ?? new driver_00Amethyst.dVector3() };
}

public static driver_00Amethyst.dQuaternion ComQuaternion00(this Quaternion q)
{
return new driver_00Amethyst.dQuaternion { X = q.X, Y = q.Y, Z = q.Z, W = q.W };
}

public static Vector3 GetPosition(this HmdMatrix34_t mat)
{
return new Vector3(mat.m3, mat.m7, mat.m11);
Expand Down

0 comments on commit 6e8bf81

Please sign in to comment.