From a3aba6004d9e9bd0e6de33410d3dc248cfa00541 Mon Sep 17 00:00:00 2001 From: nightghost Date: Tue, 31 Dec 2019 01:59:20 +0300 Subject: [PATCH 1/5] pixelgl has been ported to GLFW 3.5. --- go.mod | 2 +- go.sum | 4 ++-- pixelgl/input.go | 2 +- pixelgl/joystick.go | 14 +++++++------- pixelgl/monitor.go | 2 +- pixelgl/run.go | 2 +- pixelgl/window.go | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index c9d5ef2..dc9ce1c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/faiface/glhf v0.0.0-20181018222622-82a6317ac380 github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 // indirect - github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 + github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/pkg/errors v0.8.1 diff --git a/go.sum b/go.sum index 20d14f9..ebe9824 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHr github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M= github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw= github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 h1:b+9H1GAsx5RsjvDFLoS5zkNBzIQMuVKUYQDmxU3N5XE= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 h1:THttjeRn1iiz69E875U6gAik8KTWk/JYAHoSVpUxBBI= github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= diff --git a/pixelgl/input.go b/pixelgl/input.go index aa16b64..541afb1 100644 --- a/pixelgl/input.go +++ b/pixelgl/input.go @@ -3,7 +3,7 @@ package pixelgl import ( "github.com/faiface/mainthread" "github.com/faiface/pixel" - "github.com/go-gl/glfw/v3.2/glfw" + "github.com/go-gl/glfw/v3.3/glfw" ) // Pressed returns whether the Button is currently pressed down. diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index cfedd35..8ff361b 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -1,7 +1,7 @@ package pixelgl import ( - "github.com/go-gl/glfw/v3.2/glfw" + "github.com/go-gl/glfw/v3.3/glfw" ) // Joystick is a joystick or controller. @@ -94,22 +94,22 @@ func (w *Window) JoystickAxis(js Joystick, axis int) float64 { func (w *Window) updateJoystickInput() { for js := Joystick1; js <= JoystickLast; js++ { // Determine and store if the joystick was connected - joystickPresent := glfw.JoystickPresent(glfw.Joystick(js)) + joystickPresent := glfw.Joystick(js).Present() w.tempJoy.connected[js] = joystickPresent if joystickPresent { - w.tempJoy.buttons[js] = glfw.GetJoystickButtons(glfw.Joystick(js)) - w.tempJoy.axis[js] = glfw.GetJoystickAxes(glfw.Joystick(js)) + w.tempJoy.buttons[js] = glfw.Joystick(js).GetButtons() + w.tempJoy.axis[js] = glfw.Joystick(js).GetAxes() if !w.currJoy.connected[js] { // The joystick was recently connected, we get the name - w.tempJoy.name[js] = glfw.GetJoystickName(glfw.Joystick(js)) + w.tempJoy.name[js] = glfw.Joystick(js).GetName() } else { // Use the name from the previous one w.tempJoy.name[js] = w.currJoy.name[js] } } else { - w.tempJoy.buttons[js] = []byte{} + w.tempJoy.buttons[js] = []glfw.Action{} w.tempJoy.axis[js] = []float32{} w.tempJoy.name[js] = "" } @@ -122,7 +122,7 @@ func (w *Window) updateJoystickInput() { type joystickState struct { connected [JoystickLast + 1]bool name [JoystickLast + 1]string - buttons [JoystickLast + 1][]byte + buttons [JoystickLast + 1][]glfw.Action axis [JoystickLast + 1][]float32 } diff --git a/pixelgl/monitor.go b/pixelgl/monitor.go index 90ae7cc..1d6077a 100644 --- a/pixelgl/monitor.go +++ b/pixelgl/monitor.go @@ -2,7 +2,7 @@ package pixelgl import ( "github.com/faiface/mainthread" - "github.com/go-gl/glfw/v3.2/glfw" + "github.com/go-gl/glfw/v3.3/glfw" ) // Monitor represents a physical display attached to your computer. diff --git a/pixelgl/run.go b/pixelgl/run.go index 94e89c2..c2822fb 100644 --- a/pixelgl/run.go +++ b/pixelgl/run.go @@ -2,7 +2,7 @@ package pixelgl import ( "github.com/faiface/mainthread" - "github.com/go-gl/glfw/v3.2/glfw" + "github.com/go-gl/glfw/v3.3/glfw" "github.com/pkg/errors" ) diff --git a/pixelgl/window.go b/pixelgl/window.go index 10c16ce..676196c 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -8,7 +8,7 @@ import ( "github.com/faiface/glhf" "github.com/faiface/mainthread" "github.com/faiface/pixel" - "github.com/go-gl/glfw/v3.2/glfw" + "github.com/go-gl/glfw/v3.3/glfw" "github.com/pkg/errors" ) From 484c1775b099df4b6b3ddab1108e2a2e6b2c5107 Mon Sep 17 00:00:00 2001 From: nightghost Date: Sun, 5 Jan 2020 21:37:24 +0300 Subject: [PATCH 2/5] Gamepad API added. --- pixelgl/joystick.go | 70 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index 8ff361b..0c4c5c4 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -4,7 +4,7 @@ import ( "github.com/go-gl/glfw/v3.3/glfw" ) -// Joystick is a joystick or controller. +// Joystick is a joystick or controller (gamepad). type Joystick int // List all of the joysticks. @@ -29,6 +29,47 @@ const ( JoystickLast = Joystick(glfw.JoystickLast) ) +// GamepadAxis corresponds to a gamepad axis. +type GamepadAxis int + +// Gamepad axis IDs. +const ( + AxisLeftX = GamepadAxis(glfw.AxisLeftX) + AxisLeftY = GamepadAxis(glfw.AxisLeftY) + AxisRightX = GamepadAxis(glfw.AxisRightX) + AxisRightY = GamepadAxis(glfw.AxisRightY) + AxisLeftTrigger = GamepadAxis(glfw.AxisLeftTrigger) + AxisRightTrigger = GamepadAxis(glfw.AxisRightTrigger) + AxisLast = GamepadAxis(glfw.AxisLast) +) + +// GamepadButton corresponds to a gamepad button. +type GamepadButton int + +// Gamepad button IDs. +const ( + ButtonA = GamepadButton(glfw.ButtonA) + ButtonB = GamepadButton(glfw.ButtonB) + ButtonX = GamepadButton(glfw.ButtonX) + ButtonY = GamepadButton(glfw.ButtonY) + ButtonLeftBumper = GamepadButton(glfw.ButtonLeftBumper) + ButtonRightBumper = GamepadButton(glfw.ButtonRightBumper) + ButtonBack = GamepadButton(glfw.ButtonBack) + ButtonStart = GamepadButton(glfw.ButtonStart) + ButtonGuide = GamepadButton(glfw.ButtonGuide) + ButtonLeftThumb = GamepadButton(glfw.ButtonLeftThumb) + ButtonRightThumb = GamepadButton(glfw.ButtonRightThumb) + ButtonDpadUp = GamepadButton(glfw.ButtonDpadUp) + ButtonDpadRight = GamepadButton(glfw.ButtonDpadRight) + ButtonDpadDown = GamepadButton(glfw.ButtonDpadDown) + ButtonDpadLeft = GamepadButton(glfw.ButtonDpadLeft) + ButtonLast = GamepadButton(glfw.ButtonLast) + ButtonCross = GamepadButton(glfw.ButtonCross) + ButtonCircle = GamepadButton(glfw.ButtonCircle) + ButtonSquare = GamepadButton(glfw.ButtonSquare) + ButtonTriangle = GamepadButton(glfw.ButtonTriangle) +) + // JoystickPresent returns if the joystick is currently connected. // // This API is experimental. @@ -62,32 +103,32 @@ func (w *Window) JoystickAxisCount(js Joystick) int { // If the button index is out of range, this will return false. // // This API is experimental. -func (w *Window) JoystickPressed(js Joystick, button int) bool { - return w.currJoy.getButton(js, button) +func (w *Window) JoystickPressed(js Joystick, button GamepadButton) bool { + return w.currJoy.getButton(js, int(button)) } // JoystickJustPressed returns whether the joystick Button has just been pressed down. // If the button index is out of range, this will return false. // // This API is experimental. -func (w *Window) JoystickJustPressed(js Joystick, button int) bool { - return w.currJoy.getButton(js, button) && !w.prevJoy.getButton(js, button) +func (w *Window) JoystickJustPressed(js Joystick, button GamepadButton) bool { + return w.currJoy.getButton(js, int(button)) && !w.prevJoy.getButton(js, int(button)) } // JoystickJustReleased returns whether the joystick Button has just been released up. // If the button index is out of range, this will return false. // // This API is experimental. -func (w *Window) JoystickJustReleased(js Joystick, button int) bool { - return !w.currJoy.getButton(js, button) && w.prevJoy.getButton(js, button) +func (w *Window) JoystickJustReleased(js Joystick, button GamepadButton) bool { + return !w.currJoy.getButton(js, int(button)) && w.prevJoy.getButton(js, int(button)) } // JoystickAxis returns the value of a joystick axis at the last call to Window.Update. // If the axis index is out of range, this will return 0. // // This API is experimental. -func (w *Window) JoystickAxis(js Joystick, axis int) float64 { - return w.currJoy.getAxis(js, axis) +func (w *Window) JoystickAxis(js Joystick, axis GamepadAxis) float64 { + return w.currJoy.getAxis(js, int(axis)) } // Used internally during Window.UpdateInput to update the state of the joysticks. @@ -98,8 +139,15 @@ func (w *Window) updateJoystickInput() { w.tempJoy.connected[js] = joystickPresent if joystickPresent { - w.tempJoy.buttons[js] = glfw.Joystick(js).GetButtons() - w.tempJoy.axis[js] = glfw.Joystick(js).GetAxes() + if glfw.Joystick(js).IsGamepad() { + gamepadInputs := glfw.Joystick(js).GetGamepadState() + + w.tempJoy.buttons[js] = gamepadInputs.Buttons[:] + w.tempJoy.axis[js] = gamepadInputs.Axes[:] + } else { + w.tempJoy.buttons[js] = glfw.Joystick(js).GetButtons() + w.tempJoy.axis[js] = glfw.Joystick(js).GetAxes() + } if !w.currJoy.connected[js] { // The joystick was recently connected, we get the name From 7e3a88ef6388ff578d718e8dc64705c7a70eb24d Mon Sep 17 00:00:00 2001 From: nightghost Date: Sun, 5 Jan 2020 21:47:11 +0300 Subject: [PATCH 3/5] Magic number removed. --- pixelgl/joystick.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index 0c4c5c4..25fd374 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -180,7 +180,7 @@ func (js *joystickState) getButton(joystick Joystick, button int) bool { if js.buttons[joystick] == nil || button >= len(js.buttons[joystick]) || button < 0 { return false } - return js.buttons[joystick][byte(button)] == 1 + return js.buttons[joystick][byte(button)] == glfw.Press } // Returns the value of a joystick axis, returning 0 if the button or joystick is invalid. From 09ea5585a027cfd5b0fa9f030dc6766fe3db8029 Mon Sep 17 00:00:00 2001 From: zergon321 Date: Mon, 20 Apr 2020 21:43:49 +0300 Subject: [PATCH 4/5] Revert "Magic number removed." This reverts commit 7e3a88ef6388ff578d718e8dc64705c7a70eb24d. --- pixelgl/joystick.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index 25fd374..0c4c5c4 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -180,7 +180,7 @@ func (js *joystickState) getButton(joystick Joystick, button int) bool { if js.buttons[joystick] == nil || button >= len(js.buttons[joystick]) || button < 0 { return false } - return js.buttons[joystick][byte(button)] == glfw.Press + return js.buttons[joystick][byte(button)] == 1 } // Returns the value of a joystick axis, returning 0 if the button or joystick is invalid. From 8909d199d14d8cb60119e04e1bebf69aeeeb7140 Mon Sep 17 00:00:00 2001 From: zergon321 Date: Mon, 20 Apr 2020 21:46:15 +0300 Subject: [PATCH 5/5] Revert "Gamepad API added." This reverts commit 484c1775b099df4b6b3ddab1108e2a2e6b2c5107. --- pixelgl/joystick.go | 70 +++++++-------------------------------------- 1 file changed, 11 insertions(+), 59 deletions(-) diff --git a/pixelgl/joystick.go b/pixelgl/joystick.go index 0c4c5c4..8ff361b 100644 --- a/pixelgl/joystick.go +++ b/pixelgl/joystick.go @@ -4,7 +4,7 @@ import ( "github.com/go-gl/glfw/v3.3/glfw" ) -// Joystick is a joystick or controller (gamepad). +// Joystick is a joystick or controller. type Joystick int // List all of the joysticks. @@ -29,47 +29,6 @@ const ( JoystickLast = Joystick(glfw.JoystickLast) ) -// GamepadAxis corresponds to a gamepad axis. -type GamepadAxis int - -// Gamepad axis IDs. -const ( - AxisLeftX = GamepadAxis(glfw.AxisLeftX) - AxisLeftY = GamepadAxis(glfw.AxisLeftY) - AxisRightX = GamepadAxis(glfw.AxisRightX) - AxisRightY = GamepadAxis(glfw.AxisRightY) - AxisLeftTrigger = GamepadAxis(glfw.AxisLeftTrigger) - AxisRightTrigger = GamepadAxis(glfw.AxisRightTrigger) - AxisLast = GamepadAxis(glfw.AxisLast) -) - -// GamepadButton corresponds to a gamepad button. -type GamepadButton int - -// Gamepad button IDs. -const ( - ButtonA = GamepadButton(glfw.ButtonA) - ButtonB = GamepadButton(glfw.ButtonB) - ButtonX = GamepadButton(glfw.ButtonX) - ButtonY = GamepadButton(glfw.ButtonY) - ButtonLeftBumper = GamepadButton(glfw.ButtonLeftBumper) - ButtonRightBumper = GamepadButton(glfw.ButtonRightBumper) - ButtonBack = GamepadButton(glfw.ButtonBack) - ButtonStart = GamepadButton(glfw.ButtonStart) - ButtonGuide = GamepadButton(glfw.ButtonGuide) - ButtonLeftThumb = GamepadButton(glfw.ButtonLeftThumb) - ButtonRightThumb = GamepadButton(glfw.ButtonRightThumb) - ButtonDpadUp = GamepadButton(glfw.ButtonDpadUp) - ButtonDpadRight = GamepadButton(glfw.ButtonDpadRight) - ButtonDpadDown = GamepadButton(glfw.ButtonDpadDown) - ButtonDpadLeft = GamepadButton(glfw.ButtonDpadLeft) - ButtonLast = GamepadButton(glfw.ButtonLast) - ButtonCross = GamepadButton(glfw.ButtonCross) - ButtonCircle = GamepadButton(glfw.ButtonCircle) - ButtonSquare = GamepadButton(glfw.ButtonSquare) - ButtonTriangle = GamepadButton(glfw.ButtonTriangle) -) - // JoystickPresent returns if the joystick is currently connected. // // This API is experimental. @@ -103,32 +62,32 @@ func (w *Window) JoystickAxisCount(js Joystick) int { // If the button index is out of range, this will return false. // // This API is experimental. -func (w *Window) JoystickPressed(js Joystick, button GamepadButton) bool { - return w.currJoy.getButton(js, int(button)) +func (w *Window) JoystickPressed(js Joystick, button int) bool { + return w.currJoy.getButton(js, button) } // JoystickJustPressed returns whether the joystick Button has just been pressed down. // If the button index is out of range, this will return false. // // This API is experimental. -func (w *Window) JoystickJustPressed(js Joystick, button GamepadButton) bool { - return w.currJoy.getButton(js, int(button)) && !w.prevJoy.getButton(js, int(button)) +func (w *Window) JoystickJustPressed(js Joystick, button int) bool { + return w.currJoy.getButton(js, button) && !w.prevJoy.getButton(js, button) } // JoystickJustReleased returns whether the joystick Button has just been released up. // If the button index is out of range, this will return false. // // This API is experimental. -func (w *Window) JoystickJustReleased(js Joystick, button GamepadButton) bool { - return !w.currJoy.getButton(js, int(button)) && w.prevJoy.getButton(js, int(button)) +func (w *Window) JoystickJustReleased(js Joystick, button int) bool { + return !w.currJoy.getButton(js, button) && w.prevJoy.getButton(js, button) } // JoystickAxis returns the value of a joystick axis at the last call to Window.Update. // If the axis index is out of range, this will return 0. // // This API is experimental. -func (w *Window) JoystickAxis(js Joystick, axis GamepadAxis) float64 { - return w.currJoy.getAxis(js, int(axis)) +func (w *Window) JoystickAxis(js Joystick, axis int) float64 { + return w.currJoy.getAxis(js, axis) } // Used internally during Window.UpdateInput to update the state of the joysticks. @@ -139,15 +98,8 @@ func (w *Window) updateJoystickInput() { w.tempJoy.connected[js] = joystickPresent if joystickPresent { - if glfw.Joystick(js).IsGamepad() { - gamepadInputs := glfw.Joystick(js).GetGamepadState() - - w.tempJoy.buttons[js] = gamepadInputs.Buttons[:] - w.tempJoy.axis[js] = gamepadInputs.Axes[:] - } else { - w.tempJoy.buttons[js] = glfw.Joystick(js).GetButtons() - w.tempJoy.axis[js] = glfw.Joystick(js).GetAxes() - } + w.tempJoy.buttons[js] = glfw.Joystick(js).GetButtons() + w.tempJoy.axis[js] = glfw.Joystick(js).GetAxes() if !w.currJoy.connected[js] { // The joystick was recently connected, we get the name