mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
st/oxr: Make sure to clear action state metadata in case input is not active.
Also addresses some review comments on earlier changes.
This commit is contained in:
parent
5443e3a069
commit
726e446421
|
@ -855,12 +855,17 @@ oxr_action_cache_update(struct oxr_logger *log,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last.active && changed) {
|
if (last.active && changed) {
|
||||||
|
// We were active last sync, and we've changed since
|
||||||
|
// then
|
||||||
cache->current.timestamp = timestamp;
|
cache->current.timestamp = timestamp;
|
||||||
cache->current.changed = true;
|
cache->current.changed = true;
|
||||||
} else if (last.active) {
|
} else if (last.active) {
|
||||||
|
// We were active last sync, but we haven't changed
|
||||||
|
// since then.
|
||||||
cache->current.timestamp = last.timestamp;
|
cache->current.timestamp = last.timestamp;
|
||||||
cache->current.changed = false;
|
cache->current.changed = false;
|
||||||
} else {
|
} else {
|
||||||
|
// We are active now but weren't active last time.
|
||||||
cache->current.timestamp = timestamp;
|
cache->current.timestamp = timestamp;
|
||||||
cache->current.changed = false;
|
cache->current.changed = false;
|
||||||
}
|
}
|
||||||
|
@ -1326,64 +1331,81 @@ oxr_action_sync_data(struct oxr_logger *log,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define OXR_ACTION_GET_XR_STATE_FROM_ACTION_STATE_COMMON(ACTION_STATE, DATA) \
|
||||||
|
do { \
|
||||||
|
DATA->lastChangeTime = ACTION_STATE->timestamp; \
|
||||||
|
DATA->changedSinceLastSync = ACTION_STATE->changed; \
|
||||||
|
DATA->isActive = XR_TRUE; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_state_from_state_bool(struct oxr_action_state *state,
|
get_xr_state_from_action_state_bool(struct oxr_action_state *state,
|
||||||
XrActionStateBoolean *data)
|
XrActionStateBoolean *data)
|
||||||
{
|
{
|
||||||
|
/* only get here if the action is active! */
|
||||||
|
assert(state->active);
|
||||||
|
OXR_ACTION_GET_XR_STATE_FROM_ACTION_STATE_COMMON(state, data);
|
||||||
data->currentState = state->value.boolean;
|
data->currentState = state->value.boolean;
|
||||||
data->lastChangeTime = state->timestamp;
|
|
||||||
data->changedSinceLastSync = state->changed;
|
|
||||||
data->isActive = state->active;
|
|
||||||
//! @todo
|
|
||||||
// data->isActive = XR_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_state_from_state_vec1(struct oxr_action_state *state,
|
get_xr_state_from_action_state_vec1(struct oxr_action_state *state,
|
||||||
XrActionStateFloat *data)
|
XrActionStateFloat *data)
|
||||||
{
|
{
|
||||||
|
/* only get here if the action is active! */
|
||||||
|
assert(state->active);
|
||||||
|
OXR_ACTION_GET_XR_STATE_FROM_ACTION_STATE_COMMON(state, data);
|
||||||
data->currentState = state->value.vec1.x;
|
data->currentState = state->value.vec1.x;
|
||||||
data->lastChangeTime = state->timestamp;
|
|
||||||
data->changedSinceLastSync = state->changed;
|
|
||||||
data->isActive = state->active;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_state_from_state_vec2(struct oxr_action_state *state,
|
get_xr_state_from_action_state_vec2(struct oxr_action_state *state,
|
||||||
XrActionStateVector2f *data)
|
XrActionStateVector2f *data)
|
||||||
{
|
{
|
||||||
|
/* only get here if the action is active! */
|
||||||
|
assert(state->active);
|
||||||
|
OXR_ACTION_GET_XR_STATE_FROM_ACTION_STATE_COMMON(state, data);
|
||||||
data->currentState.x = state->value.vec2.x;
|
data->currentState.x = state->value.vec2.x;
|
||||||
data->currentState.y = state->value.vec2.y;
|
data->currentState.y = state->value.vec2.y;
|
||||||
data->lastChangeTime = state->timestamp;
|
|
||||||
data->changedSinceLastSync = state->changed;
|
|
||||||
data->isActive = XR_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OXR_ACTION_GET_FILLER(TYPE) \
|
#define OXR_ACTION_GET_FILLER(TYPE) \
|
||||||
if (sub_paths.any && act_attached->any_state.active) { \
|
if (sub_paths.any && act_attached->any_state.active) { \
|
||||||
get_state_from_state_##TYPE(&act_attached->any_state, data); \
|
get_xr_state_from_action_state_##TYPE( \
|
||||||
|
&act_attached->any_state, data); \
|
||||||
} \
|
} \
|
||||||
if (sub_paths.user && act_attached->user.current.active) { \
|
if (sub_paths.user && act_attached->user.current.active) { \
|
||||||
get_state_from_state_##TYPE(&act_attached->user.current, \
|
get_xr_state_from_action_state_##TYPE( \
|
||||||
data); \
|
&act_attached->user.current, data); \
|
||||||
} \
|
} \
|
||||||
if (sub_paths.head && act_attached->head.current.active) { \
|
if (sub_paths.head && act_attached->head.current.active) { \
|
||||||
get_state_from_state_##TYPE(&act_attached->head.current, \
|
get_xr_state_from_action_state_##TYPE( \
|
||||||
data); \
|
&act_attached->head.current, data); \
|
||||||
} \
|
} \
|
||||||
if (sub_paths.left && act_attached->left.current.active) { \
|
if (sub_paths.left && act_attached->left.current.active) { \
|
||||||
get_state_from_state_##TYPE(&act_attached->left.current, \
|
get_xr_state_from_action_state_##TYPE( \
|
||||||
data); \
|
&act_attached->left.current, data); \
|
||||||
} \
|
} \
|
||||||
if (sub_paths.right && act_attached->right.current.active) { \
|
if (sub_paths.right && act_attached->right.current.active) { \
|
||||||
get_state_from_state_##TYPE(&act_attached->right.current, \
|
get_xr_state_from_action_state_##TYPE( \
|
||||||
data); \
|
&act_attached->right.current, data); \
|
||||||
} \
|
} \
|
||||||
if (sub_paths.gamepad && act_attached->gamepad.current.active) { \
|
if (sub_paths.gamepad && act_attached->gamepad.current.active) { \
|
||||||
get_state_from_state_##TYPE(&act_attached->gamepad.current, \
|
get_xr_state_from_action_state_##TYPE( \
|
||||||
data); \
|
&act_attached->gamepad.current, data); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Clear the actual data members of the XrActionState* types, to have the
|
||||||
|
* correct return value in case of the action being not active
|
||||||
|
*/
|
||||||
|
#define OXR_ACTION_RESET_XR_ACTION_STATE(data) \
|
||||||
|
do { \
|
||||||
|
data->isActive = XR_FALSE; \
|
||||||
|
data->changedSinceLastSync = XR_FALSE; \
|
||||||
|
data->lastChangeTime = 0; \
|
||||||
|
U_ZERO(&data->currentState); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
XrResult
|
XrResult
|
||||||
oxr_action_get_boolean(struct oxr_logger *log,
|
oxr_action_get_boolean(struct oxr_logger *log,
|
||||||
|
@ -1401,9 +1423,7 @@ oxr_action_get_boolean(struct oxr_logger *log,
|
||||||
"Action has not been attached to this session");
|
"Action has not been attached to this session");
|
||||||
}
|
}
|
||||||
|
|
||||||
data->isActive = XR_FALSE;
|
OXR_ACTION_RESET_XR_ACTION_STATE(data);
|
||||||
U_ZERO(&data->currentState);
|
|
||||||
|
|
||||||
|
|
||||||
OXR_ACTION_GET_FILLER(bool);
|
OXR_ACTION_GET_FILLER(bool);
|
||||||
|
|
||||||
|
@ -1426,8 +1446,7 @@ oxr_action_get_vector1f(struct oxr_logger *log,
|
||||||
"Action has not been attached to this session");
|
"Action has not been attached to this session");
|
||||||
}
|
}
|
||||||
|
|
||||||
data->isActive = XR_FALSE;
|
OXR_ACTION_RESET_XR_ACTION_STATE(data);
|
||||||
U_ZERO(&data->currentState);
|
|
||||||
|
|
||||||
OXR_ACTION_GET_FILLER(vec1);
|
OXR_ACTION_GET_FILLER(vec1);
|
||||||
|
|
||||||
|
@ -1450,8 +1469,7 @@ oxr_action_get_vector2f(struct oxr_logger *log,
|
||||||
"Action has not been attached to this session");
|
"Action has not been attached to this session");
|
||||||
}
|
}
|
||||||
|
|
||||||
data->isActive = XR_FALSE;
|
OXR_ACTION_RESET_XR_ACTION_STATE(data);
|
||||||
U_ZERO(&data->currentState);
|
|
||||||
|
|
||||||
OXR_ACTION_GET_FILLER(vec2);
|
OXR_ACTION_GET_FILLER(vec2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue