Merge pull request #156 from Humpheh/master

Correctly index joysticks in internal state (fixes #155)
This commit is contained in:
Michal Štrba 2019-01-22 22:53:08 +01:00 committed by GitHub
commit f1ad821f1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -25,6 +25,8 @@ const (
Joystick14 = Joystick(glfw.Joystick14) Joystick14 = Joystick(glfw.Joystick14)
Joystick15 = Joystick(glfw.Joystick15) Joystick15 = Joystick(glfw.Joystick15)
Joystick16 = Joystick(glfw.Joystick16) Joystick16 = Joystick(glfw.Joystick16)
JoystickLast = Joystick(glfw.JoystickLast)
) )
// JoystickPresent returns if the joystick is currently connected. // 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. // Used internally during Window.UpdateInput to update the state of the joysticks.
func (w *Window) updateJoystickInput() { func (w *Window) updateJoystickInput() {
for js := Joystick1; js < Joystick16; js++ { for js := Joystick1; js <= JoystickLast; js++ {
// Determine and store if the joystick was connected // Determine and store if the joystick was connected
joystickPresent := glfw.JoystickPresent(glfw.Joystick(js)) joystickPresent := glfw.JoystickPresent(glfw.Joystick(js))
w.tempJoy.connected[js] = joystickPresent w.tempJoy.connected[js] = joystickPresent
@ -118,10 +120,10 @@ func (w *Window) updateJoystickInput() {
} }
type joystickState struct { type joystickState struct {
connected [Joystick16]bool connected [JoystickLast + 1]bool
name [Joystick16]string name [JoystickLast + 1]string
buttons [Joystick16][]byte buttons [JoystickLast + 1][]byte
axis [Joystick16][]float32 axis [JoystickLast + 1][]float32
} }
// Returns if a button on a joystick is down, returning false if the button or joystick is invalid. // Returns if a button on a joystick is down, returning false if the button or joystick is invalid.