From a46f6f6cf41c5ca62b488e7e7c2dd49ab6da276e Mon Sep 17 00:00:00 2001 From: Humphrey Shotton Date: Tue, 22 Jan 2019 21:37:15 +0000 Subject: [PATCH 1/2] Correctly index joysticks in internal state --- pixelgl/joystick.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index 3cdec27..70bcf51 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -25,6 +25,8 @@ const ( Joystick14 = Joystick(glfw.Joystick14) Joystick15 = Joystick(glfw.Joystick15) Joystick16 = Joystick(glfw.Joystick16) + + JoystickLast = Joystick(glfw.JoystickLast) ) // JoystickPresent returns if the joystick is currently connected. @@ -90,7 +92,7 @@ func (w *Window) JoystickAxis(js Joystick, axis int) float64 { // Used internally during Window.UpdateInput to update the state of the joysticks. func (w *Window) updateJoystickInput() { - for js := Joystick1; js < Joystick16; js++ { + for js := Joystick1; js <= Joystick16; js++ { // Determine and store if the joystick was connected joystickPresent := glfw.JoystickPresent(glfw.Joystick(js)) w.tempJoy.connected[js] = joystickPresent @@ -118,10 +120,10 @@ func (w *Window) updateJoystickInput() { } type joystickState struct { - connected [Joystick16]bool - name [Joystick16]string - buttons [Joystick16][]byte - axis [Joystick16][]float32 + connected [Joystick16 + 1]bool + name [Joystick16 + 1]string + buttons [Joystick16 + 1][]byte + axis [Joystick16 + 1][]float32 } // Returns if a button on a joystick is down, returning false if the button or joystick is invalid. From 3be890ea80ead3afbce6f9d029e05c54c74f0a6d Mon Sep 17 00:00:00 2001 From: Humphrey Shotton Date: Tue, 22 Jan 2019 21:48:24 +0000 Subject: [PATCH 2/2] Use JoystickLast instead of Joystick16 --- pixelgl/joystick.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index 70bcf51..cfedd35 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -92,7 +92,7 @@ func (w *Window) JoystickAxis(js Joystick, axis int) float64 { // Used internally during Window.UpdateInput to update the state of the joysticks. func (w *Window) updateJoystickInput() { - for js := Joystick1; js <= Joystick16; js++ { + for js := Joystick1; js <= JoystickLast; js++ { // Determine and store if the joystick was connected joystickPresent := glfw.JoystickPresent(glfw.Joystick(js)) w.tempJoy.connected[js] = joystickPresent @@ -120,10 +120,10 @@ func (w *Window) updateJoystickInput() { } type joystickState struct { - connected [Joystick16 + 1]bool - name [Joystick16 + 1]string - buttons [Joystick16 + 1][]byte - axis [Joystick16 + 1][]float32 + connected [JoystickLast + 1]bool + name [JoystickLast + 1]string + buttons [JoystickLast + 1][]byte + axis [JoystickLast + 1][]float32 } // Returns if a button on a joystick is down, returning false if the button or joystick is invalid.