mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
st/oxr: Better logging when creating transforms
This commit is contained in:
parent
25c78287a2
commit
1109bc7cfb
|
@ -14,9 +14,42 @@
|
|||
|
||||
#include "util/u_misc.h"
|
||||
|
||||
#include "openxr/openxr_reflection.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
static const char *
|
||||
xr_action_type_to_str(XrActionType type)
|
||||
{
|
||||
// clang-format off
|
||||
switch (type) {
|
||||
#define PRINT(name, value) \
|
||||
case name: return #name;
|
||||
XR_LIST_ENUM_XrActionType(PRINT)
|
||||
#undef PRINT
|
||||
default: return "XR_ACTION_TYPE_UNKNOWN";
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
static const char *
|
||||
xrt_input_type_to_str(enum xrt_input_type type)
|
||||
{
|
||||
// clang-format off
|
||||
switch (type) {
|
||||
case XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE: return "XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE";
|
||||
case XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE: return "XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE";
|
||||
case XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE: return "XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE";
|
||||
case XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE: return "XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE";
|
||||
case XRT_INPUT_TYPE_BOOLEAN: return "XRT_INPUT_TYPE_BOOLEAN";
|
||||
case XRT_INPUT_TYPE_POSE: return "XRT_INPUT_TYPE_POSE";
|
||||
default: return "XRT_INPUT_UNKNOWN";
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/*!
|
||||
* Arbitrary but larger than required.
|
||||
*/
|
||||
|
@ -174,12 +207,14 @@ ends_with(const char *str, const char *suffix)
|
|||
return (len >= suffix_len) &&
|
||||
(0 == strcmp(str + (len - suffix_len), suffix));
|
||||
}
|
||||
|
||||
static inline bool
|
||||
input_is_float(enum xrt_input_type input_type)
|
||||
{
|
||||
return (input_type == XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE) ||
|
||||
(input_type == XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE);
|
||||
}
|
||||
|
||||
static inline uint8_t
|
||||
input_dim(enum xrt_input_type input_type)
|
||||
{
|
||||
|
@ -218,42 +253,53 @@ extend_transform_array(struct oxr_logger *log,
|
|||
result_type != XR_ACTION_TYPE_VECTOR2F_INPUT) {
|
||||
// reduce dimension
|
||||
if (ends_with(bound_path_string, "/x")) {
|
||||
oxr_slog(slog, "Adding transform: get x of Vec2\n");
|
||||
oxr_slog(slog,
|
||||
"\t\t\tAdding transform: get x of Vec2\n");
|
||||
return oxr_input_transform_init_vec2_get_x(transform,
|
||||
parent);
|
||||
}
|
||||
if (ends_with(bound_path_string, "/y")) {
|
||||
oxr_slog(slog, "Adding transform: get y of Vec2\n");
|
||||
oxr_slog(slog,
|
||||
"\t\t\tAdding transform: get y of Vec2\n");
|
||||
return oxr_input_transform_init_vec2_get_y(transform,
|
||||
parent);
|
||||
}
|
||||
oxr_log(log, "No rule to get float from vec2f for binding %s\n",
|
||||
bound_path_string);
|
||||
return NULL;
|
||||
oxr_slog(
|
||||
slog,
|
||||
"\t\t\tNo rule to get float from vec2f for binding %s\n",
|
||||
bound_path_string);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input_type == XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE &&
|
||||
result_type == XR_ACTION_TYPE_BOOLEAN_INPUT) {
|
||||
// 0.2 is for a little deadband around the center.
|
||||
oxr_slog(slog, "Adding transform: threshold [-1, 1] float\n");
|
||||
oxr_slog(slog,
|
||||
"\t\t\tAdding transform: threshold [-1, 1] float\n");
|
||||
return oxr_input_transform_init_threshold(transform, parent,
|
||||
0.2f, false);
|
||||
}
|
||||
|
||||
if (input_type == XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE &&
|
||||
result_type == XR_ACTION_TYPE_BOOLEAN_INPUT) {
|
||||
// Need it pressed nearly all the way
|
||||
oxr_slog(slog, "Adding transform: threshold [0, 1] float\n");
|
||||
oxr_slog(slog,
|
||||
"\t\t\tAdding transform: threshold [0, 1] float\n");
|
||||
return oxr_input_transform_init_threshold(transform, parent,
|
||||
0.7f, false);
|
||||
}
|
||||
|
||||
if (input_type == XRT_INPUT_TYPE_BOOLEAN &&
|
||||
result_type == XR_ACTION_TYPE_FLOAT_INPUT) {
|
||||
// this conversion is in the spec
|
||||
oxr_slog(slog, "Adding transform: bool to float\n");
|
||||
oxr_slog(slog, "\t\t\tAdding transform: bool to float\n");
|
||||
return oxr_input_transform_init_bool_to_vec1(
|
||||
transform, parent, XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE, 1.f,
|
||||
0.f);
|
||||
}
|
||||
|
||||
oxr_slog(slog, "\t\t\tCould not transform!\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -279,6 +325,10 @@ oxr_input_transform_create_chain(struct oxr_logger *log,
|
|||
{
|
||||
struct oxr_input_transform chain[OXR_MAX_INPUT_TRANSFORMS] = {0};
|
||||
|
||||
oxr_slog(slog, "\t\tAdding transform from '%s' to '%s'\n",
|
||||
xr_action_type_to_str(result_type),
|
||||
xrt_input_type_to_str(input_type));
|
||||
|
||||
struct oxr_input_transform *current_xform = &(chain[0]);
|
||||
if (!oxr_input_transform_init_root(current_xform, input_type)) {
|
||||
*out_num_transforms = 0;
|
||||
|
@ -293,37 +343,40 @@ oxr_input_transform_create_chain(struct oxr_logger *log,
|
|||
*out_num_transforms = num_transforms;
|
||||
*out_transforms =
|
||||
oxr_input_transform_clone_chain(chain, num_transforms);
|
||||
oxr_slog(slog, "\t\t\tUsing identity transform for pose.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
while (!oxr_type_matches_xrt(current_xform->result_type, result_type)) {
|
||||
if (num_transforms >= OXR_MAX_INPUT_TRANSFORMS) {
|
||||
// Couldn't finish the transform to the desired type.
|
||||
oxr_log(
|
||||
log,
|
||||
"Seem to have gotten into a loop, trying to make a "
|
||||
"rule to transform action %s, binding %s\n",
|
||||
action_name, bound_path_string);
|
||||
oxr_slog(slog,
|
||||
"\t\t\tSeem to have gotten into a loop, "
|
||||
"trying to make a rule to transform.\n",
|
||||
action_name, bound_path_string);
|
||||
*out_num_transforms = 0;
|
||||
*out_transforms = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct oxr_input_transform *new_xform =
|
||||
&(chain[num_transforms]);
|
||||
if (!extend_transform_array(log, slog, new_xform, current_xform,
|
||||
result_type, bound_path_string)) {
|
||||
// Couldn't finish the transform to the desired type.
|
||||
oxr_log(log,
|
||||
"No rule to transform action %s, binding %s\n",
|
||||
action_name, bound_path_string);
|
||||
// Error has already been logged.
|
||||
|
||||
*out_num_transforms = 0;
|
||||
*out_transforms = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
num_transforms++;
|
||||
current_xform = new_xform;
|
||||
}
|
||||
|
||||
*out_num_transforms = num_transforms;
|
||||
*out_transforms =
|
||||
oxr_input_transform_clone_chain(chain, num_transforms);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue