From 64f27879d7138cea406e6403f907c9d62f0f3c2b Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 31 Oct 2023 11:25:45 -0500 Subject: [PATCH] multiple controllers no longer interfere --- src/common/emu.ts | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/common/emu.ts b/src/common/emu.ts index 3ec11ac9..94b1b733 100644 --- a/src/common/emu.ts +++ b/src/common/emu.ts @@ -545,39 +545,55 @@ const DEFAULT_CONTROLLER_KEYS : KeyDef[] = [ export class ControllerPoller { active = false; handler; - state = new Int8Array(32); - lastState = new Int8Array(32); + state : Int32Array[]; + lastState : Int32Array[]; AXIS0 = 24; // first joystick axis index constructor(handler:(key,code,flags) => void) { this.handler = handler; window.addEventListener("gamepadconnected", (event) => { console.log("Gamepad connected:", event); - this.active = typeof navigator.getGamepads === 'function'; + this.reset(); }); window.addEventListener("gamepaddisconnected", (event) => { console.log("Gamepad disconnected:", event); + this.reset(); }); } + reset() { + this.active = typeof navigator.getGamepads === 'function'; + if (this.active) { + let numGamepads = navigator.getGamepads().length; + this.state = new Array(numGamepads); + this.lastState = new Array(numGamepads); + for (var i=0; i