The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

xrt: Move device assignment code to u_device

+82 -38
+65
src/xrt/auxiliary/util/u_device.c
··· 294 294 295 295 free(xdev); 296 296 } 297 + 298 + /* 299 + * move the assigned xdev from hand to other_hand if: 300 + * - controller of type "any hand" is assigned to hand 301 + * - other_hand is unassiged 302 + */ 303 + static void 304 + try_move_assignment(struct xrt_device **xdevs, int *hand, int *other_hand) 305 + { 306 + if (*hand != XRT_DEVICE_ROLE_UNASSIGNED && 307 + xdevs[*hand]->device_type == XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER && 308 + *other_hand == XRT_DEVICE_ROLE_UNASSIGNED) { 309 + 310 + *other_hand = *hand; 311 + *hand = XRT_DEVICE_ROLE_UNASSIGNED; 312 + } 313 + } 314 + 315 + void 316 + u_device_assign_xdev_roles(struct xrt_device **xdevs, 317 + size_t num_xdevs, 318 + int *head, 319 + int *left, 320 + int *right) 321 + { 322 + *head = XRT_DEVICE_ROLE_UNASSIGNED; 323 + *left = XRT_DEVICE_ROLE_UNASSIGNED; 324 + *right = XRT_DEVICE_ROLE_UNASSIGNED; 325 + 326 + for (size_t i = 0; i < num_xdevs; i++) { 327 + if (xdevs[i] == NULL) { 328 + continue; 329 + } 330 + 331 + switch (xdevs[i]->device_type) { 332 + case XRT_DEVICE_TYPE_HMD: 333 + if (*head == XRT_DEVICE_ROLE_UNASSIGNED) { 334 + *head = i; 335 + } 336 + break; 337 + case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: 338 + try_move_assignment(xdevs, left, right); 339 + if (*left == XRT_DEVICE_ROLE_UNASSIGNED) { 340 + *left = i; 341 + } 342 + break; 343 + case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: 344 + try_move_assignment(xdevs, right, left); 345 + if (*right == XRT_DEVICE_ROLE_UNASSIGNED) { 346 + *right = i; 347 + } 348 + break; 349 + case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER: 350 + if (*left == XRT_DEVICE_ROLE_UNASSIGNED) { 351 + *left = i; 352 + } else if (*right == XRT_DEVICE_ROLE_UNASSIGNED) { 353 + *right = i; 354 + } else { 355 + //! @todo: do something with unassigend devices? 356 + } 357 + break; 358 + default: break; 359 + } 360 + } 361 + }
+14
src/xrt/auxiliary/util/u_device.h
··· 98 98 u_device_free(struct xrt_device *xdev); 99 99 100 100 101 + #define XRT_DEVICE_ROLE_UNASSIGNED (-1) 102 + 103 + /*! 104 + * Helper function to assign head, left hand and right hand roles. 105 + * 106 + * @ingroup aux_util 107 + */ 108 + void 109 + u_device_assign_xdev_roles(struct xrt_device **xdevs, 110 + size_t num_xdevs, 111 + int *head, 112 + int *left, 113 + int *right); 114 + 101 115 #ifdef __cplusplus 102 116 } 103 117 #endif
+2 -36
src/xrt/state_trackers/oxr/oxr_instance.c
··· 114 114 115 115 #define NUM_XDEVS 16 116 116 117 - static void 118 - assign_xdev_roles(struct oxr_instance *inst) 119 - { 120 - struct oxr_system *sys = &inst->system; 121 - for (size_t i = 0; i < NUM_XDEVS; i++) { 122 - if (sys->xdevs[i] == NULL) { 123 - continue; 124 - } 125 - 126 - if (sys->xdevs[i]->device_type == XRT_DEVICE_TYPE_HMD) { 127 - sys->role.head = i; 128 - } else if (sys->xdevs[i]->device_type == 129 - XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER) { 130 - if (sys->role.left == XRT_DEVICE_ROLE_UNASSIGNED) { 131 - sys->role.left = i; 132 - } 133 - } else if (sys->xdevs[i]->device_type == 134 - XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER) { 135 - if (sys->role.right == XRT_DEVICE_ROLE_UNASSIGNED) { 136 - sys->role.right = i; 137 - } 138 - } else if (sys->xdevs[i]->device_type == 139 - XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER) { 140 - if (sys->role.left == XRT_DEVICE_ROLE_UNASSIGNED) { 141 - sys->role.left = i; 142 - } else if (sys->role.right == 143 - XRT_DEVICE_ROLE_UNASSIGNED) { 144 - sys->role.right = i; 145 - } else { 146 - //! @todo: do something with unassigend devices? 147 - } 148 - } 149 - } 150 - } 151 - 152 117 static inline size_t 153 118 min_size_t(size_t a, size_t b) 154 119 { ··· 277 242 oxr_xdev_destroy(&xdevs[i]); 278 243 } 279 244 280 - assign_xdev_roles(inst); 245 + u_device_assign_xdev_roles(xdevs, NUM_XDEVS, &sys->role.head, 246 + &sys->role.left, &sys->role.right); 281 247 282 248 // Did we find any HMD 283 249 // @todo Headless with only controllers?
+1 -2
src/xrt/state_trackers/oxr/oxr_objects.h
··· 20 20 #include "util/u_index_fifo.h" 21 21 #include "util/u_hashset.h" 22 22 #include "util/u_hashmap.h" 23 + #include "util/u_device.h" 23 24 24 25 #include "oxr_extension_support.h" 25 26 #include "oxr_subaction.h" ··· 1088 1089 */ 1089 1090 oxr_handle_destroyer destroy; 1090 1091 }; 1091 - 1092 - #define XRT_DEVICE_ROLE_UNASSIGNED (-1) 1093 1092 1094 1093 /*! 1095 1094 * Single or multiple devices grouped together to form a system that sessions