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

View File

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

View File

@ -64,15 +64,8 @@ void __CtrlInit();
void __CtrlDoState(PointerWrap &p);
void __CtrlShutdown();
// Call this whenever a button is pressed, using the above CTRL_ constants.
// Multiple buttons may be sent in one call OR'd together.
// 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);
// Clears and sets selected buttons. NOTE: Clearing happens first.
void __CtrlUpdateButtons(u32 bitsToSet, u32 bitsToClear);
// 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.)

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 };
if (digitalX == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT));
__CtrlUpdateButtons(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT), 0);
tiltButtonsDown &= ~(CTRL_LEFT | CTRL_RIGHT);
}
if (digitalY == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_UP | CTRL_DOWN));
__CtrlUpdateButtons(0, 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;
ctrlMask &= ~__CtrlPeekButtons();
__CtrlButtonDown(ctrlMask);
__CtrlUpdateButtons(ctrlMask, 0);
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 };
if (digitalX == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE));
__CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE));
tiltButtonsDown &= ~(CTRL_SQUARE | CTRL_CIRCLE);
}
if (digitalY == 0) {
__CtrlButtonUp(tiltButtonsDown & (CTRL_TRIANGLE | CTRL_CROSS));
__CtrlUpdateButtons(0, 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;
ctrlMask &= ~__CtrlPeekButtons();
__CtrlButtonDown(ctrlMask);
__CtrlUpdateButtons(ctrlMask, 0);
tiltButtonsDown |= ctrlMask;
}
@ -208,14 +208,13 @@ void GenerateTriggerButtonEvent(int digitalX, int digitalY) {
}
downButtons &= ~__CtrlPeekButtons();
__CtrlButtonUp(tiltButtonsDown & upButtons);
__CtrlButtonDown(downButtons);
__CtrlUpdateButtons(downButtons, tiltButtonsDown & upButtons);
tiltButtonsDown = (tiltButtonsDown & ~upButtons) | downButtons;
}
void ResetTiltEvents() {
// Reset the buttons we have marked pressed.
__CtrlButtonUp(tiltButtonsDown);
__CtrlUpdateButtons(0, tiltButtonsDown);
tiltButtonsDown = 0;
__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::onVKeyAnalog, this, _1, _2),
[](uint32_t bitsToSet, uint32_t bitsToClear) {
__CtrlSetAllButtons(bitsToSet, bitsToClear);
__CtrlUpdateButtons(bitsToSet, bitsToClear);
},
[](int pspButton, bool down) {
if (down) {
__CtrlButtonDown(pspButton);
__CtrlUpdateButtons(pspButton, 0);
} else {
__CtrlButtonUp(pspButton);
__CtrlUpdateButtons(0, pspButton);
}
},
&SetPSPAnalog,

View File

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

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