From 093eb492e5201b0bbeac959582388fff9e171f91 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:16:50 -0500 Subject: [PATCH] Fix gamepad support (see changelog) --- CHANGES.md | 5 +++++ data/emulator.js | 2 +- data/gamepad.js | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 210a3ae..5c1d04a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ - Added picodrive core (sega32x) - Cleaned up documentation - Fixed/updated rar de-compression +- Added segaMD, segaCD, sega32x button labels and virtual gamepad (Thanks to [@n-at](https://github.com/n-at)) +- Added ability to use threads (pre compiled cores not yet available) +- Fixed reversed gamepad button events (down was up, up was down) +- Fixed Gamepad axis release not triggering +- Add ***highly beta*** psp core - see readme # 4.0.4 [View Tree](https://github.com/EmulatorJS/EmulatorJS/tree/41491a738cf92ef9cee7d53f323aa2ab9732c053) - Fix cheats "x" button diff --git a/data/emulator.js b/data/emulator.js index 500a63f..5122c62 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -2228,7 +2228,7 @@ class EmulatorJS { for (let i=0; i<4; i++) { for (let j=0; j<27; j++) { if (['buttonup', 'buttondown'].includes(e.type) && (this.controls[i][j] && this.controls[i][j].value2 === e.index)) { - this.gameManager.simulateInput(i, j, (e.type === 'buttondown' ? 0 : (special.includes(j) ? 0x7fff : 1))); + this.gameManager.simulateInput(i, j, (e.type === 'buttonup' ? 0 : (special.includes(j) ? 0x7fff : 1))); } else if (e.type === "axischanged") { if (this.controls[i][j] && typeof this.controls[i][j].value2 === 'string' && this.controls[i][j].value2.split(":")[0] === e.axis) { if (special.includes(j)) { diff --git a/data/gamepad.js b/data/gamepad.js index 488b6a8..f93c692 100644 --- a/data/gamepad.js +++ b/data/gamepad.js @@ -42,13 +42,16 @@ class GamepadHandler { hasGamepad = true; oldGamepad.axes.forEach((axis, axisIndex) => { - if (gamepad.axes[axisIndex] !== axis) { + const val = (axis < 0.01 && axis > -0.01) ? 0 : axis; + const newVal = (gamepad.axes[axisIndex] < 0.01 && gamepad.axes[axisIndex] > -0.01) ? 0 : gamepad.axes[axisIndex]; + if (newVal !== val) { const axis = ['LEFT_STICK_X', 'LEFT_STICK_Y', 'RIGHT_STICK_X', 'RIGHT_STICK_Y'][axisIndex]; if (!axis) return; - this.dispatchEvent('axischanged', {axis: axis, value: gamepad.axes[axisIndex], index: gamepad.index, gamepadIndex: gamepad.index}); + this.dispatchEvent('axischanged', {axis: axis, value: newVal, index: gamepad.index, gamepadIndex: gamepad.index}); } - gamepadToSave.axes[axisIndex] = axis; + gamepadToSave.axes[axisIndex] = newVal; }) + gamepad.buttons.forEach((button, buttonIndex) => { let pressed = oldGamepad.buttons[buttonIndex] === 1.0; if (typeof oldGamepad.buttons[buttonIndex] === "object") {