Xbox Cloud Gaming app for PS5 Homebrew
C
WIP: mouse wheel: 120 per notch to the game (Windows' WHEEL_DELTA); a press of Y per notch as a controller
Rafael Abud Ferreirafeb8b3e4fa5b
diff --git a/src/app/stream_player.cpp b/src/app/stream_player.cppindex 87b2951..12abbeb 100644--- a/src/app/stream_player.cpp+++ b/src/app/stream_player.cpp@@ -685,7 +685,7 @@ void StreamPlayer::sendKbm(const input::KbmInput& in) {stream::MouseFrame m;m.dx = in.dx * 2; // as the web client: twice the pointer's movementm.dy = in.dy * 2;- m.wheelY = in.wheel;+ m.wheelY = in.wheel * 120; // one notch = WHEEL_DELTA (120), as Windows (and the game) count itm.buttons = in.buttons;s->sendMouse(m);}diff --git a/src/input/kbm.cpp b/src/input/kbm.cppindex fe4a7a9..95284b4 100644--- a/src/input/kbm.cpp+++ b/src/input/kbm.cpp@@ -198,6 +198,8 @@ KbmInput kbmPoll() {}out.buttons = buttons;out.moved = out.dx || out.dy || out.wheel || buttons != g_buttons;+ static int wheelLogged = 0; // which way the console counts a notch+ if (out.wheel && wheelLogged < 5) XC_LOGI("mouse: wheel %d (%d)", out.wheel, ++wheelLogged);static int movesLogged = 0;if (out.moved && movesLogged < 10)XC_LOGI("mouse: %d,%d wheel %d buttons 0x%02x (%d)", out.dx, out.dy, out.wheel, buttons, ++movesLogged);diff --git a/src/input/keyboard_nav.cpp b/src/input/keyboard_nav.cppindex b014803..515f039 100644--- a/src/input/keyboard_nav.cpp+++ b/src/input/keyboard_nav.cpp@@ -43,6 +43,17 @@ void keyboardAsGamepad(const KbmInput& in, MouseStick& stick, ControllerState& oif (std::abs(stick.y) < 0.02f) stick.y = 0;out.rightStickX = stick.x;out.rightStickY = stick.y;+ // The wheel: a press of Y per notch, ~50 ms down and ~30 ms up so the+ // game sees each one (a pass is ~8 ms).+ constexpr int kDown = 6, kCycle = 10;+ stick.wheelPresses = std::min(stick.wheelPresses + std::abs(in.wheel), 4);+ if (stick.wheelPresses > 0) {+ if (stick.wheelPhase < kDown) out.btnY = true;+ if (++stick.wheelPhase >= kCycle) {+ stick.wheelPhase = 0;+ --stick.wheelPresses;+ }+ }}void mergePads(ControllerState& pad, const ControllerState& e) {diff --git a/src/input/keyboard_nav.h b/src/input/keyboard_nav.hindex 7353306..9ce6d01 100644--- a/src/input/keyboard_nav.h+++ b/src/input/keyboard_nav.h@@ -29,9 +29,12 @@ constexpr uint8_t kVkAppMenu = 0x7B;// a second controller isn't needed): W A S D the left stick, the mouse the// right stick, the arrows the D-pad; Space A, C B, R X, E Y, Q LB, F RB, the// mouse's right / left buttons LT / RT, Shift and the middle button the-// sticks' clicks, Tab View, Esc Menu.+// sticks' clicks, Tab View, Esc Menu, a wheel notch a press of Y.struct MouseStick {float x = 0, y = 0; // the right stick, eased towards the mouse's speed+ // The wheel: each notch is a short press of Y (switch weapon in most+ // shooters): presses still to give, and where the current one is.+ int wheelPresses = 0, wheelPhase = 0;};void keyboardAsGamepad(const KbmInput& in, MouseStick& stick, ControllerState& out);diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 446a2f8..3a1cdd2 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -966,6 +966,19 @@ static void testKeyboardAsGamepad() {in.keyboard = true;for (int i = 0; i < 20; ++i) xc::input::keyboardAsGamepad(in, stick, out); // the mouse still: back to the centreCHECK(out.rightStickX == 0.0f && !out.btnA);+ // A wheel notch: Y pressed for a few passes, then released.+ in = {};+ in.keyboard = true;+ in.wheel = 1;+ xc::input::keyboardAsGamepad(in, stick, out);+ CHECK(out.btnY);+ in.wheel = 0;+ bool released = false;+ for (int i = 0; i < 12; ++i) {+ xc::input::keyboardAsGamepad(in, stick, out);+ released |= !out.btnY;+ }+ CHECK(released && !out.btnY);xc::input::ControllerState pad, kb;pad.btnB = true;pad.leftStickX = 0.3f;