Add chiaki_controller_state_or()

This commit is contained in:
Florian Märkl 2019-07-10 11:06:30 +02:00
commit 5c1611b52e
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 18 additions and 2 deletions

View file

@ -223,8 +223,7 @@ void StreamSession::SendFeedbackState()
}
#endif
state.buttons |= keyboard_state.buttons;
chiaki_controller_state_or(&state, &state, &keyboard_state);
chiaki_session_set_controller_state(&session, &state);
}

View file

@ -85,6 +85,8 @@ static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, Chia
&& a->right_y == b->right_y;
}
CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, ChiakiControllerState *a, ChiakiControllerState *b);
#ifdef __cplusplus
}
#endif

View file

@ -25,3 +25,18 @@ CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state
state->right_x = 0;
state->right_y = 0;
}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define MAX_ABS(a, b) (ABS(a) > ABS(b) ? (a) : (b))
CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, ChiakiControllerState *a, ChiakiControllerState *b)
{
out->buttons = a->buttons | b->buttons;
out->l2_state = MAX(a->l2_state, b->l2_state);
out->r2_state = MAX(a->r2_state, b->r2_state);
out->left_x = MAX_ABS(a->left_x, b->left_x);
out->left_y = MAX_ABS(a->left_y, b->left_y);
out->right_x = MAX_ABS(a->right_x, b->right_x);
out->right_y = MAX_ABS(a->right_y, b->right_y);
}