Skip to content

Commit

Permalink
Various changes to ensure GameInput games do not read from the same m…
Browse files Browse the repository at this point in the history
…emory that SK's input I/O threads are actively writing to, lockless of course.
  • Loading branch information
Kaldaien committed Dec 2, 2024
1 parent 07b6037 commit c499d1d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
24.12.2.1
24.12.3
=======
+ Various changes to ensure GameInput games do not read from the same memory
that SK's input I/O threads are actively writing to, lockless of course.

24.12.2.1
=========
+ Fixed internal deadzone on PlayStation controller input used to determine
which gamepad has the most recent input (i.e. if the same controller is
Expand Down
6 changes: 3 additions & 3 deletions include/SpecialK/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#define SK_YEAR 24
#define SK_MONTH 12
#define SK_DATE 2
#define SK_REV_N 1
#define SK_REV 1
#define SK_DATE 3
#define SK_REV_N 0
#define SK_REV 0

#ifndef _A2
#define _A2(a) #a
Expand Down
40 changes: 20 additions & 20 deletions src/input/game_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,38 +1873,38 @@ SK_IPlayStationGameInputReading::GetGamepadState (GameInputGamepadState *state)
if (! SK_ImGui_WantGamepadCapture ())
{
state->leftThumbstickX =
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.report.Gamepad.sThumbLX) / 32767.0);
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.prev_report.Gamepad.sThumbLX) / 32767.0);
state->leftThumbstickY =
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.report.Gamepad.sThumbLY) / 32767.0);
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.prev_report.Gamepad.sThumbLY) / 32767.0);

state->rightThumbstickX =
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.report.Gamepad.sThumbRX) / 32767.0);
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.prev_report.Gamepad.sThumbRX) / 32767.0);
state->rightThumbstickY =
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.report.Gamepad.sThumbRY) / 32767.0);
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.prev_report.Gamepad.sThumbRY) / 32767.0);

state->leftTrigger =
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.report.Gamepad.bLeftTrigger) / 255.0);
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.prev_report.Gamepad.bLeftTrigger) / 255.0);
state->rightTrigger =
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.report.Gamepad.bRightTrigger) / 255.0);
static_cast <float> (static_cast <double> (pNewestInputDevice->xinput.prev_report.Gamepad.bRightTrigger) / 255.0);

state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0 ? GameInputGamepadA : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0 ? GameInputGamepadB : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0 ? GameInputGamepadX : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0 ? GameInputGamepadY : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_A) != 0 ? GameInputGamepadA : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_B) != 0 ? GameInputGamepadB : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_X) != 0 ? GameInputGamepadX : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_Y) != 0 ? GameInputGamepadY : GameInputGamepadNone;

state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_START) != 0 ? GameInputGamepadMenu : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) != 0 ? GameInputGamepadView : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_START) != 0 ? GameInputGamepadMenu : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) != 0 ? GameInputGamepadView : GameInputGamepadNone;

state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) != 0 ? GameInputGamepadDPadUp : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) != 0 ? GameInputGamepadDPadDown : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) != 0 ? GameInputGamepadDPadLeft : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) != 0 ? GameInputGamepadDPadRight : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) != 0 ? GameInputGamepadDPadUp : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) != 0 ? GameInputGamepadDPadDown : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) != 0 ? GameInputGamepadDPadLeft : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) != 0 ? GameInputGamepadDPadRight : GameInputGamepadNone;

state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) != 0 ? GameInputGamepadLeftShoulder : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) != 0 ? GameInputGamepadRightShoulder : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) != 0 ? GameInputGamepadLeftShoulder : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) != 0 ? GameInputGamepadRightShoulder : GameInputGamepadNone;

state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0 ? GameInputGamepadLeftThumbstick : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.report.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0 ? GameInputGamepadRightThumbstick : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) != 0 ? GameInputGamepadLeftThumbstick : GameInputGamepadNone;
state->buttons |= (pNewestInputDevice->xinput.prev_report.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) != 0 ? GameInputGamepadRightThumbstick : GameInputGamepadNone;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/input/hid_reports/playstation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,13 @@ SK_HID_PlayStationDevice::request_input_report (void)
else if (bIsInputNew)
{
WriteULong64Release (&pDevice->xinput.last_active, SK_QueryPerf ().QuadPart);

if (bIsDeviceMostRecentlyActive)
{ // Need interlock
auto last_active =
ReadULong64Acquire (&pDevice->xinput.last_active) + (SK_PerfFreq / 13);
WriteULong64Release (&pDevice->xinput.last_active, last_active);
}
}

const bool bAllowSpecialButtons =
Expand Down

0 comments on commit c499d1d

Please sign in to comment.