Conversation
Kryptos-FR
left a comment
There was a problem hiding this comment.
A few remarks on a pure technical/language side. I'll let @xen2 do the proper review.
| // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. | ||
| namespace Xenko.VirtualReality | ||
| { | ||
| public enum DeviceState |
There was a problem hiding this comment.
Why moving the enum into a different file?
There was a problem hiding this comment.
before, it was one enum in a file with the same name as the enum (DeviceState). since i added a second enum concerning the Device i thought, instead of adding a second file, i'd put them both in the same file and renaming the file to a more generic name, ie. DeviceEnums.cs.
please let me know if you prefer one file per enum and i'll change it accordingly.
There was a problem hiding this comment.
Don't mind so much with so small enums, but so far most of the code is one file per enum, so might be better to keep consistency.
|
|
||
| public override TouchController RightHand => null; | ||
|
|
||
| public override TrackedDevice[] TrackedDevices => null; |
There was a problem hiding this comment.
I personally prefer collection properties to return empty rather than null.
There was a problem hiding this comment.
done. now returns new ..[0]
| } | ||
| } | ||
|
|
||
| public class TrackedDevice |
There was a problem hiding this comment.
Not a fan of having classes with the same name in different namespaces. Can cause confusion and makes it harder to find/navigate the code.
There was a problem hiding this comment.
renamed the Xenko.VirtualReality one to TrackedItem so the one in OpenVR can keep the name of its original api.
|
I assume this is ready for review? I will take a look and merge it soon. |
…uctor since it doesn't change at runtime (cherry picked from commit b6a8f4912637b7f89b0017da07df3ae6efc53a57)
|
@tebjan i put the SerialNumber and DeviceClass getters in Update instead of the constructor because i wasn't sure if they couldn't actually change at runtime: see, the TrackedDevice is only an index in to OpenVRs list of devices. to my understandings controllers and trackers can be added/removed (ie. paired/unpaired) at runtime which i'd assume can change their order in the list. therefore i thought putting those in update is the saver option. if we are certain it can not happen, then of course it should go to the constructor. but then not only SerialNumber but also DeviceClass. @xen2 otherwise yes, please. |
|
@joreg ah you are right, if the index of the same physical device changes during runtime, it would create confusion. we could test that with the vive trackers and the controllers. |
|
@xen2 i just checked, and indeed, devices can be added at runtime, so i moved the serialnumber check back to update. interestingly though it seems they cannot be removed at runtime. once a slot is occupied it is occupied for runtime, even if the device is turned off. also i allowed myself to expose another feature we need: VRDevice.SetTrackingSpace() |
|
added a slight improvement by re-using the same string builder in every frame. |
| serialNumberStringBuilder.Clear(); | ||
| Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); | ||
| if (error == ETrackedPropertyError.TrackedProp_Success) | ||
| SerialNumber = serialNumberStringBuilder.ToString(); |
There was a problem hiding this comment.
Does that mean it will allocate every frame? (something we are trying to avoid)
There was a problem hiding this comment.
what do you mean by "allocate every frame"? what those lines do, is accessing the serialnumber property of the trackeddevice with the index TrackerIndex. i don't see anything getting allocated there.
There was a problem hiding this comment.
StringBuilder.ToString() will allocate a new string at every update.
There was a problem hiding this comment.
ok, any idea to improve that?
There was a problem hiding this comment.
maybe we could check somehow whether the device slot has changed? that and create is the only moment when the serial number needs reading...
There was a problem hiding this comment.
another idea would be to place the code into the getter of the property or a method of the TrackedDevice, then it would only be read and allocated if someone asks for it...
| { | ||
| var error = ETrackedPropertyError.TrackedProp_Success; | ||
| var result = new System.Text.StringBuilder((int)64); | ||
| Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); |
There was a problem hiding this comment.
this is expensive and only needs to be called once. you can check whether the SerialNumber is null and only then update it.
| serialNumberStringBuilder.Clear(); | ||
| Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); | ||
| if (error == ETrackedPropertyError.TrackedProp_Success) | ||
| SerialNumber = serialNumberStringBuilder.ToString(); |
There was a problem hiding this comment.
maybe we could check somehow whether the device slot has changed? that and create is the only moment when the serial number needs reading...
| serialNumberStringBuilder.Clear(); | ||
| Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); | ||
| if (error == ETrackedPropertyError.TrackedProp_Success) | ||
| SerialNumber = serialNumberStringBuilder.ToString(); |
There was a problem hiding this comment.
another idea would be to place the code into the getter of the property or a method of the TrackedDevice, then it would only be read and allocated if someone asks for it...
|
ouright, will move SerialNumber, DeviceClass and Batteries into getters. |
|
Seems like there is some line ending issues in most edited files (I see the warning when opening https://github.com/vvvv/xenko/edit/VRTrackerSupport/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs) your CRLF setting should be set to "auto" ( |
|
indeed, i've just moved to a new PC where this wasn't set correctly. i checked all files this PR modifies and only found an inconsistency in this one mentioned file though.. |
|
hei @xen2 do you see any further issues with this? |
|
@joreg sorry for the delay... |
| Controller, //The device is a controller | ||
| GenericTracker, //The device is a tracker | ||
| TrackingReference, //The device is a camera, Lighthouse base station, or other device that supplies tracking ground truth. | ||
| DisplayRedirect //Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices |
There was a problem hiding this comment.
Can you put those comments following the /// <summary>My summary here.</summary> xml convention?
Since you bothered adding them, better make them visible to API users as well 😄
…l files and added xml comments
sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs
Outdated
Show resolved
Hide resolved
|
LGTM, merging |
# Conflicts: # sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs # sources/engine/Xenko.VirtualReality/TrackedItem.cs
Uh oh!
There was an error while loading. Please reload this page.