Clean up __Ctrl button functions.

This commit is contained in:
Henrik Rydgård 2023-04-01 08:55:45 +02:00
parent 2428051f17
commit 04d3d3111c
7 changed files with 25 additions and 54 deletions

View File

@ -155,12 +155,7 @@ void WebSocketInputState::ButtonsSend(DebuggerRequest &req) {
} }
} }
if (downFlags) { __CtrlUpdateButtons(downFlags, upFlags);
__CtrlButtonDown(downFlags);
}
if (upFlags) {
__CtrlButtonUp(upFlags);
}
req.Respond(); req.Respond();
} }
@ -193,7 +188,7 @@ void WebSocketInputState::ButtonsPress(DebuggerRequest &req) {
press.button = info->second; press.button = info->second;
// TODO: Route into the control mapper's PSPKey function instead. // TODO: Route into the control mapper's PSPKey function instead.
__CtrlButtonDown(press.button); __CtrlUpdateButtons(press.button, 0);
pressTickets_.push_back(press); pressTickets_.push_back(press);
} }
@ -207,7 +202,7 @@ void WebSocketInputState::Broadcast(net::WebSocketServer *ws) {
press.duration--; press.duration--;
if (press.duration == -1) { if (press.duration == -1) {
// TODO: Route into the control mapper's PSPKey function instead. // TODO: Route into the control mapper's PSPKey function instead.
__CtrlButtonUp(press.button); __CtrlUpdateButtons(0, press.button);
ws->Send(press.Event()); ws->Send(press.Event());
} }
} }

View File

@ -189,22 +189,7 @@ u32 __CtrlReadLatch()
return ret; return ret;
} }
// Functions so that the rest of the emulator can control what the sceCtrl interface should return void __CtrlUpdateButtons(u32 bitsToSet, u32 bitsToClear)
// to the game:
void __CtrlButtonDown(u32 buttonBit)
{
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.buttons |= buttonBit;
}
void __CtrlButtonUp(u32 buttonBit)
{
std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.buttons &= ~buttonBit;
}
void __CtrlSetAllButtons(u32 bitsToSet, u32 bitsToClear)
{ {
std::lock_guard<std::mutex> guard(ctrlMutex); std::lock_guard<std::mutex> guard(ctrlMutex);
ctrlCurrent.buttons &= ~(bitsToClear & CTRL_MASK_USER); ctrlCurrent.buttons &= ~(bitsToClear & CTRL_MASK_USER);

View File

@ -64,15 +64,8 @@ void __CtrlInit();
void __CtrlDoState(PointerWrap &p); void __CtrlDoState(PointerWrap &p);
void __CtrlShutdown(); void __CtrlShutdown();
// Call this whenever a button is pressed, using the above CTRL_ constants. // Clears and sets selected buttons. NOTE: Clearing happens first.
// Multiple buttons may be sent in one call OR'd together. void __CtrlUpdateButtons(u32 bitsToSet, u32 bitsToClear);
// Resending a currently pressed button is fine but not required.
void __CtrlButtonDown(u32 buttonBit);
// Call this whenever a button is released. Similar to __CtrlButtonDown().
void __CtrlButtonUp(u32 buttonBit);
// Sets the full state. Used by the new control mapper. The above two functions
// should go away over time.
void __CtrlSetAllButtons(u32 bitsToSet, u32 bitsToClear);
// Call this to set the position of an analog stick, ideally when it changes. // Call this to set the position of an analog stick, ideally when it changes.
// X and Y values should be from -1 to 1, inclusive, in a square (no need to force to a circle.) // X and Y values should be from -1 to 1, inclusive, in a square (no need to force to a circle.)

View File

@ -139,12 +139,12 @@ void GenerateDPadEvent(int digitalX, int digitalY) {
static const int dir[4] = { CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP }; static const int dir[4] = { CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP };
if (digitalX == 0) { if (digitalX == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT)); __CtrlUpdateButtons(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT), 0);
tiltButtonsDown &= ~(CTRL_LEFT | CTRL_RIGHT); tiltButtonsDown &= ~(CTRL_LEFT | CTRL_RIGHT);
} }
if (digitalY == 0) { if (digitalY == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_UP | CTRL_DOWN)); __CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_UP | CTRL_DOWN));
tiltButtonsDown &= ~(CTRL_UP | CTRL_DOWN); tiltButtonsDown &= ~(CTRL_UP | CTRL_DOWN);
} }
@ -159,7 +159,7 @@ void GenerateDPadEvent(int digitalX, int digitalY) {
if (digitalY == 1) ctrlMask |= CTRL_UP; if (digitalY == 1) ctrlMask |= CTRL_UP;
ctrlMask &= ~__CtrlPeekButtons(); ctrlMask &= ~__CtrlPeekButtons();
__CtrlButtonDown(ctrlMask); __CtrlUpdateButtons(ctrlMask, 0);
tiltButtonsDown |= ctrlMask; tiltButtonsDown |= ctrlMask;
} }
@ -167,12 +167,12 @@ void GenerateActionButtonEvent(int digitalX, int digitalY) {
static const int buttons[4] = { CTRL_CIRCLE, CTRL_CROSS, CTRL_SQUARE, CTRL_TRIANGLE }; static const int buttons[4] = { CTRL_CIRCLE, CTRL_CROSS, CTRL_SQUARE, CTRL_TRIANGLE };
if (digitalX == 0) { if (digitalX == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE)); __CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE));
tiltButtonsDown &= ~(CTRL_SQUARE | CTRL_CIRCLE); tiltButtonsDown &= ~(CTRL_SQUARE | CTRL_CIRCLE);
} }
if (digitalY == 0) { if (digitalY == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_TRIANGLE | CTRL_CROSS)); __CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_TRIANGLE | CTRL_CROSS));
tiltButtonsDown &= ~(CTRL_TRIANGLE | CTRL_CROSS); tiltButtonsDown &= ~(CTRL_TRIANGLE | CTRL_CROSS);
} }
@ -187,7 +187,7 @@ void GenerateActionButtonEvent(int digitalX, int digitalY) {
if (digitalY == 1) ctrlMask |= CTRL_TRIANGLE; if (digitalY == 1) ctrlMask |= CTRL_TRIANGLE;
ctrlMask &= ~__CtrlPeekButtons(); ctrlMask &= ~__CtrlPeekButtons();
__CtrlButtonDown(ctrlMask); __CtrlUpdateButtons(ctrlMask, 0);
tiltButtonsDown |= ctrlMask; tiltButtonsDown |= ctrlMask;
} }
@ -208,14 +208,13 @@ void GenerateTriggerButtonEvent(int digitalX, int digitalY) {
} }
downButtons &= ~__CtrlPeekButtons(); downButtons &= ~__CtrlPeekButtons();
__CtrlButtonUp(tiltButtonsDown & upButtons); __CtrlUpdateButtons(downButtons, tiltButtonsDown & upButtons);
__CtrlButtonDown(downButtons);
tiltButtonsDown = (tiltButtonsDown & ~upButtons) | downButtons; tiltButtonsDown = (tiltButtonsDown & ~upButtons) | downButtons;
} }
void ResetTiltEvents() { void ResetTiltEvents() {
// Reset the buttons we have marked pressed. // Reset the buttons we have marked pressed.
__CtrlButtonUp(tiltButtonsDown); __CtrlUpdateButtons(0, tiltButtonsDown);
tiltButtonsDown = 0; tiltButtonsDown = 0;
__CtrlSetAnalogXY(CTRL_STICK_LEFT, 0.0f, 0.0f); __CtrlSetAnalogXY(CTRL_STICK_LEFT, 0.0f, 0.0f);
} }

View File

@ -179,13 +179,13 @@ EmuScreen::EmuScreen(const Path &filename)
std::bind(&EmuScreen::onVKey, this, _1, _2), std::bind(&EmuScreen::onVKey, this, _1, _2),
std::bind(&EmuScreen::onVKeyAnalog, this, _1, _2), std::bind(&EmuScreen::onVKeyAnalog, this, _1, _2),
[](uint32_t bitsToSet, uint32_t bitsToClear) { [](uint32_t bitsToSet, uint32_t bitsToClear) {
__CtrlSetAllButtons(bitsToSet, bitsToClear); __CtrlUpdateButtons(bitsToSet, bitsToClear);
}, },
[](int pspButton, bool down) { [](int pspButton, bool down) {
if (down) { if (down) {
__CtrlButtonDown(pspButton); __CtrlUpdateButtons(pspButton, 0);
} else { } else {
__CtrlButtonUp(pspButton); __CtrlUpdateButtons(0, pspButton);
} }
}, },
&SetPSPAnalog, &SetPSPAnalog,

View File

@ -182,9 +182,9 @@ bool PSPButton::Touch(const TouchInput &input) {
if (g_Config.bHapticFeedback) { if (g_Config.bHapticFeedback) {
System_Vibrate(HAPTIC_VIRTUAL_KEY); System_Vibrate(HAPTIC_VIRTUAL_KEY);
} }
__CtrlButtonDown(pspButtonBit_); __CtrlUpdateButtons(pspButtonBit_, 0);
} else if (lastDown && !down) { } else if (lastDown && !down) {
__CtrlButtonUp(pspButtonBit_); __CtrlUpdateButtons(0, pspButtonBit_);
} }
return retval; return retval;
} }
@ -361,10 +361,10 @@ void PSPDpad::ProcessTouch(float x, float y, bool down) {
if (g_Config.bHapticFeedback) { if (g_Config.bHapticFeedback) {
System_Vibrate(HAPTIC_VIRTUAL_KEY); System_Vibrate(HAPTIC_VIRTUAL_KEY);
} }
__CtrlButtonDown(dir[i]); __CtrlUpdateButtons(dir[i], 0);
} }
if (released & dir[i]) { if (released & dir[i]) {
__CtrlButtonUp(dir[i]); __CtrlUpdateButtons(0, dir[i]);
} }
} }
} }
@ -652,10 +652,9 @@ void PSPCustomStick::ProcessTouch(float x, float y, bool down) {
posY_ = 0.0f; posY_ = 0.0f;
} }
if (release != 0) if (release || press) {
__CtrlButtonUp(release); __CtrlUpdateButtons(press, release);
if (press != 0) }
__CtrlButtonDown(press);
} }
void InitPadLayout(float xres, float yres, float globalScale) { void InitPadLayout(float xres, float yres, float globalScale) {

@ -1 +1 @@
Subproject commit 46065027500cd781ce7c15c051c8b0c4751ad1fa Subproject commit 2e02c4a7c075f1a7cf28ec1add000ecd7077cd09