Esempio n. 1
0
        internal static unsafe bool IsPathSupported(OpenXRHmd hmd, ulong profile, ActionSuggestedBinding *suggested)
        {
            InteractionProfileSuggestedBinding suggested_bindings = new InteractionProfileSuggestedBinding()
            {
                Type = StructureType.TypeInteractionProfileSuggestedBinding,
                InteractionProfile     = profile,
                CountSuggestedBindings = 1,
                SuggestedBindings      = suggested
            };

            return(hmd.Xr.SuggestInteractionProfileBinding(hmd.Instance, &suggested_bindings) == Result.Success);
        }
Esempio n. 2
0
        internal static unsafe void Initialize(OpenXRHmd hmd)
        {
            baseHMD = hmd;

            // make actions
            for (int i = 0; i < HAND_PATH_COUNT; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    ActionCreateInfo action_info = new ActionCreateInfo()
                    {
                        Type       = StructureType.TypeActionCreateInfo,
                        ActionType = GetActionType((HAND_PATHS)i),
                    };

                    Span <byte> aname    = new Span <byte>(action_info.ActionName, 32);
                    Span <byte> lname    = new Span <byte>(action_info.LocalizedActionName, 32);
                    string      fullname = ((HAND_PATHS)i).ToString() + "H" + j.ToString() + '\0';
                    SilkMarshal.StringIntoSpan(fullname.ToLower(), aname);
                    SilkMarshal.StringIntoSpan(fullname, lname);

                    fixed(Silk.NET.OpenXR.Action *aptr = &MappedActions[j, i])
                    hmd.Xr.CreateAction(hmd.globalActionSet, &action_info, aptr);
                }
            }

            string allInputDetected = "";

            // probe bindings for all profiles
            for (int i = 0; i < InteractionProfiles.Length; i++)
            {
                ulong profile = 0;
                hmd.Xr.StringToPath(hmd.Instance, InteractionProfiles[i], ref profile);

                List <ActionSuggestedBinding> bindings = new List <ActionSuggestedBinding>();
                // for each hand...
                for (int hand = 0; hand < 2; hand++)
                {
                    // for each path we want to bind...
                    for (int path = 0; path < HAND_PATH_COUNT; path++)
                    {
                        // list all possible paths that might be valid and pick the first one
                        List <string> possiblePaths = PathPriorities[path];
                        for (int pathattempt = 0; pathattempt < possiblePaths.Count; pathattempt++)
                        {
                            // get the hand at the start, then put in the attempt
                            string final_path = hand == (int)TouchControllerHand.Left ? "/user/hand/left" : "/user/hand/right";
                            final_path += possiblePaths[pathattempt];

                            ulong hp_ulong = 0;
                            hmd.Xr.StringToPath(hmd.Instance, final_path, ref hp_ulong);

                            var suggest = new ActionSuggestedBinding()
                            {
                                Action  = MappedActions[hand, path],
                                Binding = hp_ulong
                            };

                            if (IsPathSupported(hmd, profile, &suggest))
                            {
                                // note that this controller has a touchpad/thumbstick
                                switch ((HAND_PATHS)path)
                                {
                                case HAND_PATHS.ThumbstickX:
                                    HasThumbsticks.Add(profile);
                                    break;

                                case HAND_PATHS.TrackpadX:
                                    HasTouchpads.Add(profile);
                                    break;
                                }

                                if (LogInputDetected)
                                {
                                    allInputDetected += "\nGot " + final_path + " for " + InteractionProfiles[i];
                                }

                                // got one!
                                bindings.Add(suggest);
                                break;
                            }
                        }
                    }
                }

                // ok, we got all supported paths for this profile, lets do the final suggestion with all of them
                if (bindings.Count > 0)
                {
                    ActionSuggestedBinding[] final_bindings = bindings.ToArray();
                    fixed(ActionSuggestedBinding *asbptr = &final_bindings[0])
                    {
                        InteractionProfileSuggestedBinding suggested_bindings = new InteractionProfileSuggestedBinding()
                        {
                            Type = StructureType.TypeInteractionProfileSuggestedBinding,
                            InteractionProfile     = profile,
                            CountSuggestedBindings = (uint)final_bindings.Length,
                            SuggestedBindings      = asbptr
                        };

                        OpenXRHmd.CheckResult(hmd.Xr.SuggestInteractionProfileBinding(hmd.Instance, &suggested_bindings), "SuggestInteractionProfileBinding");
                    }
                }
            }

            if (LogInputDetected)
            {
                ErrorFileLogger.WriteLogToFile(allInputDetected);
            }
        }