diff options
| author | alexandersato0830 <66799221+alexandersato0830@users.noreply.github.com> | 2026-11-25 13:46:10 -0600 |
|---|---|---|
| committer | alexandersato0830 <66799221+alexandersato0830@users.noreply.github.com> | 2026-11-25 13:46:10 -0600 |
| commit | 8b3db052e4068ef7097af39a07dfff70ca1cac42 (patch) | |
| tree | cd63ca0f57f9de820a683dc6c85347b137709d42 /runtime/shims/gameinput.cpp | |
| parent | 5da72d19f0bec96b716cad601d1af9c920976af7 (diff) | |
Keep virtual gamepad mouse deltas in range
Diffstat (limited to 'runtime/shims/gameinput.cpp')
| -rw-r--r-- | runtime/shims/gameinput.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 47e9aa941..214a59c5e 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp | |||
| @@ -1870,13 +1870,17 @@ void update_keyboard_pad() { | |||
| 1870 | int x = 0, y = 0; | 1870 | int x = 0, y = 0; |
| 1871 | const bool have = g_cursor_pos.load()(&x, &y); | 1871 | const bool have = g_cursor_pos.load()(&x, &y); |
| 1872 | const bool moved = have && g_keyboard.have_cursor; | 1872 | const bool moved = have && g_keyboard.have_cursor; |
| 1873 | // Raw input exposes the low bits of a running total. Keep subtraction modular across a wrap. | ||
| 1874 | auto delta = [](int current, int previous) { | ||
| 1875 | return static_cast<int>(static_cast<unsigned>(current) - static_cast<unsigned>(previous)); | ||
| 1876 | }; | ||
| 1873 | auto step = [sens](int v, int pixels) { | 1877 | auto step = [sens](int v, int pixels) { |
| 1874 | const long long n = static_cast<long long>(v) * kMouseDecayNum / kMouseDecayDen + | 1878 | const long long n = static_cast<long long>(v) * kMouseDecayNum / kMouseDecayDen + |
| 1875 | std::lround(static_cast<long long>(pixels) * kMouseAxisPerPixel * sens); | 1879 | std::llround(static_cast<long long>(pixels) * kMouseAxisPerPixel * sens); |
| 1876 | return static_cast<int>(std::clamp<long long>(n, -kStickFull, kStickFull)); | 1880 | return static_cast<int>(std::clamp<long long>(n, -kStickFull, kStickFull)); |
| 1877 | }; | 1881 | }; |
| 1878 | g_keyboard.right_x = step(g_keyboard.right_x, moved ? x - g_keyboard.cursor_x : 0); | 1882 | g_keyboard.right_x = step(g_keyboard.right_x, moved ? delta(x, g_keyboard.cursor_x) : 0); |
| 1879 | g_keyboard.right_y = step(g_keyboard.right_y, moved ? y - g_keyboard.cursor_y : 0); | 1883 | g_keyboard.right_y = step(g_keyboard.right_y, moved ? delta(y, g_keyboard.cursor_y) : 0); |
| 1880 | if (have) g_keyboard.cursor_x = x, g_keyboard.cursor_y = y; | 1884 | if (have) g_keyboard.cursor_x = x, g_keyboard.cursor_y = y; |
| 1881 | g_keyboard.have_cursor = have; | 1885 | g_keyboard.have_cursor = have; |
| 1882 | } else { | 1886 | } else { |