From 9331c8bb0a966d60a13bc8ee6b98f0b0d0ebedd0 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 17 Oct 2023 22:24:35 +0100 Subject: [PATCH] t/common: Add support for new dynamic device roles --- .../targets/common/target_builder_legacy.c | 21 ++++++++------- .../common/target_builder_lighthouse.c | 27 ++++++++++++------- .../common/target_builder_north_star.c | 22 ++++++++------- .../targets/common/target_builder_nreal_air.c | 16 ++++++----- .../targets/common/target_builder_qwerty.c | 17 ++++++------ .../common/target_builder_rgb_tracking.c | 24 ++++++++--------- .../targets/common/target_builder_rift_s.c | 22 ++++++++------- .../targets/common/target_builder_simulated.c | 17 ++++++------ .../targets/common/target_builder_simulavr.c | 15 ++++++----- src/xrt/targets/common/target_builder_wmr.c | 19 +++++++------ 10 files changed, 109 insertions(+), 91 deletions(-) diff --git a/src/xrt/targets/common/target_builder_legacy.c b/src/xrt/targets/common/target_builder_legacy.c index af5df87ab..308a8c303 100644 --- a/src/xrt/targets/common/target_builder_legacy.c +++ b/src/xrt/targets/common/target_builder_legacy.c @@ -133,11 +133,9 @@ legacy_open_system(struct xrt_builder *xb, return xret; } - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - } + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; ret = xrt_prober_select(xp, xsysd->xdevs, ARRAY_SIZE(xsysd->xdevs)); if (ret < 0) { @@ -181,11 +179,14 @@ legacy_open_system(struct xrt_builder *xb, right_ht = u_system_devices_get_ht_device_right(xsysd); // Assign to role(s). - xsysd->roles.head = head; - xsysd->roles.left = left; - xsysd->roles.right = right; - xsysd->roles.hand_tracking.left = left_ht; - xsysd->roles.hand_tracking.right = right_ht; + xsysd->static_roles.head = head; + xsysd->static_roles.hand_tracking.left = left_ht; + xsysd->static_roles.hand_tracking.right = right_ht; + + u_system_devices_static_finalize( // + usysds, // usysds + left, // left + right); // right /* diff --git a/src/xrt/targets/common/target_builder_lighthouse.c b/src/xrt/targets/common/target_builder_lighthouse.c index e94e162d4..1fabfe571 100644 --- a/src/xrt/targets/common/target_builder_lighthouse.c +++ b/src/xrt/targets/common/target_builder_lighthouse.c @@ -118,7 +118,7 @@ enum lighthouse_driver struct lighthouse_system { struct xrt_builder base; - struct u_system_devices *devices; + struct u_system_devices_static *devices; enum lighthouse_driver driver; //!< Which lighthouse implementation we are using bool is_valve_index; //!< Is our HMD a Valve Index? If so, try to set up hand-tracking and SLAM as needed struct vive_tracking_status vive_tstatus; //!< Visual tracking status for Index under Vive driver @@ -164,11 +164,12 @@ on_video_device(struct xrt_prober *xp, void *ptr) { struct lighthouse_system *lhs = (struct lighthouse_system *)ptr; + struct u_system_devices *usysd = &lhs->devices->base; // Hardcoded for the Index. if (product != NULL && manufacturer != NULL) { if ((strcmp(product, "3D Camera") == 0) && (strcmp(manufacturer, "Etron Technology, Inc.") == 0)) { - xrt_prober_open_video_device(xp, pdev, &lhs->devices->xfctx, &lhs->xfs); + xrt_prober_open_video_device(xp, pdev, &usysd->xfctx, &lhs->xfs); return; } } @@ -572,9 +573,12 @@ lighthouse_open_system(struct xrt_builder *xb, struct xrt_space_overseer **out_xso) { struct lighthouse_system *lhs = (struct lighthouse_system *)xb; - lhs->devices = u_system_devices_allocate(); - struct xrt_system_devices *xsysd = &lhs->devices->base; - struct xrt_frame_context *xfctx = &lhs->devices->xfctx; + + // Use the static system devices helper, no dynamic roles. + lhs->devices = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &lhs->devices->base.base; + struct xrt_frame_context *xfctx = &lhs->devices->base.xfctx; + xrt_result_t result = XRT_SUCCESS; @@ -799,11 +803,14 @@ end_valve_index: } // Assign to role(s). - xsysd->roles.head = head; - xsysd->roles.left = left; - xsysd->roles.hand_tracking.left = left_ht; - xsysd->roles.right = right; - xsysd->roles.hand_tracking.right = right_ht; + xsysd->static_roles.head = head; + xsysd->static_roles.hand_tracking.left = left_ht; + xsysd->static_roles.hand_tracking.right = right_ht; + + u_system_devices_static_finalize( // + lhs->devices, // usysds + left, // left + right); // right *out_xsysd = xsysd; u_builder_create_space_overseer_legacy( // diff --git a/src/xrt/targets/common/target_builder_north_star.c b/src/xrt/targets/common/target_builder_north_star.c index 041805c64..394e51796 100644 --- a/src/xrt/targets/common/target_builder_north_star.c +++ b/src/xrt/targets/common/target_builder_north_star.c @@ -442,11 +442,9 @@ ns_open_system(struct xrt_builder *xb, struct ns_builder *nsb = (struct ns_builder *)xb; xrt_result_t result = XRT_SUCCESS; - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysds = u_system_devices_allocate(); - xsysd = &usysds->base; - } + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; if (out_xsysd == NULL || *out_xsysd != NULL) { NS_ERROR("Invalid output system pointer"); @@ -579,11 +577,15 @@ ns_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->roles.head = head_wrap; - xsysd->roles.left = left; - xsysd->roles.right = right; - xsysd->roles.hand_tracking.left = left_ht; - xsysd->roles.hand_tracking.right = right_ht; + xsysd->static_roles.head = head_wrap; + xsysd->static_roles.hand_tracking.left = left_ht; + xsysd->static_roles.hand_tracking.right = right_ht; + + u_system_devices_static_finalize( // + usysds, // usysds + left, // left + right); // right + end: if (result == XRT_SUCCESS) { diff --git a/src/xrt/targets/common/target_builder_nreal_air.c b/src/xrt/targets/common/target_builder_nreal_air.c index 645265a9e..cb3663da8 100644 --- a/src/xrt/targets/common/target_builder_nreal_air.c +++ b/src/xrt/targets/common/target_builder_nreal_air.c @@ -86,11 +86,10 @@ nreal_air_open_system(struct xrt_builder *xb, DRV_TRACE_MARKER(); nreal_air_log_level = debug_get_log_option_nreal_air_log(); - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - } + + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); if (xret != XRT_SUCCESS) { @@ -141,7 +140,12 @@ nreal_air_open_system(struct xrt_builder *xb, xsysd->xdevs[xsysd->xdev_count++] = na_device; // Assign to role(s). - xsysd->roles.head = na_device; + xsysd->static_roles.head = na_device; + + u_system_devices_static_finalize( // + usysds, // usysds + NULL, // left + NULL); // right /* diff --git a/src/xrt/targets/common/target_builder_qwerty.c b/src/xrt/targets/common/target_builder_qwerty.c index 7707219a5..b6757d727 100644 --- a/src/xrt/targets/common/target_builder_qwerty.c +++ b/src/xrt/targets/common/target_builder_qwerty.c @@ -87,11 +87,9 @@ qwerty_open_system(struct xrt_builder *xb, return xret; } - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysds = u_system_devices_allocate(); - xsysd = &usysds->base; - } + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; // Add to device list. xsysd->xdevs[xsysd->xdev_count++] = head; @@ -103,9 +101,12 @@ qwerty_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->roles.head = head; - xsysd->roles.left = left; - xsysd->roles.right = right; + xsysd->static_roles.head = head; + + u_system_devices_static_finalize( // + usysds, // usysds + left, // left + right); // right /* diff --git a/src/xrt/targets/common/target_builder_rgb_tracking.c b/src/xrt/targets/common/target_builder_rgb_tracking.c index 10ef4482d..e5ba912c5 100644 --- a/src/xrt/targets/common/target_builder_rgb_tracking.c +++ b/src/xrt/targets/common/target_builder_rgb_tracking.c @@ -290,16 +290,11 @@ rgb_open_system(struct xrt_builder *xb, assert(out_xsysd != NULL); assert(*out_xsysd == NULL); - struct xrt_tracking_origin *origin = NULL; - struct xrt_system_devices *xsysd = NULL; - struct xrt_frame_context *xfctx = NULL; - - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - xfctx = &usysd->xfctx; - origin = &usysd->origin; - } + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_tracking_origin *origin = &usysds->base.origin; + struct xrt_system_devices *xsysd = &usysds->base.base; + struct xrt_frame_context *xfctx = &usysds->base.xfctx; /* @@ -411,9 +406,12 @@ rgb_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->roles.head = head; - xsysd->roles.left = left; - xsysd->roles.right = right; + xsysd->static_roles.head = head; + + u_system_devices_static_finalize( // + usysds, // usysds + left, // left + right); // right /* diff --git a/src/xrt/targets/common/target_builder_rift_s.c b/src/xrt/targets/common/target_builder_rift_s.c index fa25ad31c..e79244469 100644 --- a/src/xrt/targets/common/target_builder_rift_s.c +++ b/src/xrt/targets/common/target_builder_rift_s.c @@ -98,11 +98,10 @@ rift_s_open_system(struct xrt_builder *xb, DRV_TRACE_MARKER(); rift_s_log_level = debug_get_log_option_rift_s_log(); - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - } + + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); if (xret != XRT_SUCCESS) { @@ -179,8 +178,8 @@ rift_s_open_system(struct xrt_builder *xb, struct xrt_device *two_hands[2]; cemu_devices_create(hmd_xdev, ht_xdev, two_hands); - xsysd->roles.hand_tracking.left = two_hands[0]; - xsysd->roles.hand_tracking.right = two_hands[1]; + xsysd->static_roles.hand_tracking.left = two_hands[0]; + xsysd->static_roles.hand_tracking.right = two_hands[1]; xsysd->xdevs[xsysd->xdev_count++] = two_hands[0]; xsysd->xdevs[xsysd->xdev_count++] = two_hands[1]; @@ -193,9 +192,12 @@ rift_s_open_system(struct xrt_builder *xb, #endif // Assign to role(s). - xsysd->roles.head = hmd_xdev; - xsysd->roles.left = left_xdev; - xsysd->roles.right = right_xdev; + xsysd->static_roles.head = hmd_xdev; + + u_system_devices_static_finalize( // + usysds, // usysds + left_xdev, // left + right_xdev); // right /* diff --git a/src/xrt/targets/common/target_builder_simulated.c b/src/xrt/targets/common/target_builder_simulated.c index 16eb94cf3..6ef131f93 100644 --- a/src/xrt/targets/common/target_builder_simulated.c +++ b/src/xrt/targets/common/target_builder_simulated.c @@ -119,11 +119,9 @@ simulated_open_system(struct xrt_builder *xb, //! @todo Create a shared tracking origin on the system devices struct instead. head->tracking_origin->type = XRT_TRACKING_TYPE_OTHER; // Just anything other then none. - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - } + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; // Add to device list. xsysd->xdevs[xsysd->xdev_count++] = head; @@ -135,9 +133,12 @@ simulated_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->roles.head = head; - xsysd->roles.left = left; - xsysd->roles.right = right; + xsysd->static_roles.head = head; + + u_system_devices_static_finalize( // + usysds, // usysds + left, // left + right); // right /* diff --git a/src/xrt/targets/common/target_builder_simulavr.c b/src/xrt/targets/common/target_builder_simulavr.c index c53350ccf..da3cd4f44 100644 --- a/src/xrt/targets/common/target_builder_simulavr.c +++ b/src/xrt/targets/common/target_builder_simulavr.c @@ -210,21 +210,24 @@ svr_open_system(struct xrt_builder *xb, struct xrt_device *head_device = multi_create_tracking_override( XRT_TRACKING_OVERRIDE_ATTACHED, svr_dev, t265_dev, XRT_INPUT_GENERIC_TRACKER_POSE, &ident); - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - } + // Use the static system devices helper, no dynamic roles. + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; // Add to device list. xsysd->xdevs[xsysd->xdev_count++] = head_device; // Assign to role(s). - xsysd->roles.head = head_device; + xsysd->static_roles.head = head_device; end: if (result == XRT_SUCCESS) { + u_system_devices_static_finalize( // + usysds, // usysds + NULL, // left + NULL); // right + *out_xsysd = xsysd; u_builder_create_space_overseer_legacy( // head_device, // head diff --git a/src/xrt/targets/common/target_builder_wmr.c b/src/xrt/targets/common/target_builder_wmr.c index bd16edf33..636563964 100644 --- a/src/xrt/targets/common/target_builder_wmr.c +++ b/src/xrt/targets/common/target_builder_wmr.c @@ -271,11 +271,8 @@ wmr_open_system(struct xrt_builder *xb, assert(xret_unlock == XRT_SUCCESS); (void)xret_unlock; - struct xrt_system_devices *xsysd = NULL; - { - struct u_system_devices *usysd = u_system_devices_allocate(); - xsysd = &usysd->base; - } + struct u_system_devices_static *usysds = u_system_devices_static_allocate(); + struct xrt_system_devices *xsysd = &usysds->base.base; xsysd->xdevs[xsysd->xdev_count++] = head; if (left != NULL) { @@ -301,12 +298,14 @@ wmr_open_system(struct xrt_builder *xb, // Assign to role(s). - xsysd->roles.head = head; - xsysd->roles.left = left; - xsysd->roles.right = right; - xsysd->roles.hand_tracking.left = ht_left; - xsysd->roles.hand_tracking.right = ht_right; + xsysd->static_roles.head = head; + xsysd->static_roles.hand_tracking.left = ht_left; + xsysd->static_roles.hand_tracking.right = ht_right; + u_system_devices_static_finalize( // + usysds, // usysds + left, // left + right); // right // Create space overseer last once all devices set. struct xrt_space_overseer *xso = NULL;