Skip to content

Commit

Permalink
Double Trigger Prevention for POV Hats
Browse files Browse the repository at this point in the history
  • Loading branch information
doczi-dominik committed Jan 28, 2022
1 parent 8854e0f commit 692bbad
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Backends/System/Windows/Sources/kinc/backend/system.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1022,14 +1022,20 @@ bool handleDirectInputPad(int padIndex) {
DWORD *now = &di_padState[padIndex].rgdwPOV[povIndex];
DWORD *last = &di_lastPadState[padIndex].rgdwPOV[povIndex];

if (*now != *last) {
// Maybe this could use fewer conditionals with some clever math
// cardinal press || cardinal + counter-clockwise || cardinal + clockwise
kinc_internal_gamepad_trigger_button(padIndex, 12, (*now == 0 || *now == 31500 || *now == 4500));
kinc_internal_gamepad_trigger_button(padIndex, 13, (*now == 18000 || *now == 13500 || *now == 22500));
kinc_internal_gamepad_trigger_button(padIndex, 14, (*now == 27000 || *now == 22500 || *now == 31500));
kinc_internal_gamepad_trigger_button(padIndex, 15, (*now == 9000 || *now == 4500 || *now == 13500));
}
int up = (*now == 0 || *now == 31500 || *now == 4500);
int down = (*now == 18000 || *now == 13500 || *now == 22500);
int left = (*now == 27000 || *now == 22500 || *now == 31500);
int right = (*now == 9000 || *now == 4500 || *now == 13500);

int lastUp = (*last == 0 || *last == 31500 || *last == 4500);
int lastDown = (*last == 18000 || *last == 13500 || *last == 22500);
int lastLeft = (*last == 27000 || *last == 22500 || *last == 31500);
int lastRight = (*last == 9000 || *last == 4500 || *last == 13500);

if (up != lastUp) kinc_internal_gamepad_trigger_button(padIndex, 12, up);
if (down != lastDown) kinc_internal_gamepad_trigger_button(padIndex, 13, down);
if (left != lastLeft) kinc_internal_gamepad_trigger_button(padIndex, 14, left);
if (right != lastRight) kinc_internal_gamepad_trigger_button(padIndex, 15, right);
}

kinc_memcpy(&di_lastPadState[padIndex], &di_padState[padIndex], sizeof(DIJOYSTATE2));
Expand Down

0 comments on commit 692bbad

Please sign in to comment.