From 7189c7f649a046cb2ed47c9347a6a8c8918a9e38 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 19 May 2022 01:04:15 +0900 Subject: [PATCH] internal/glfw: refactoring: remove unused APIs Ebiten doesn't rely on GLFW for gamepads. --- internal/glfw/const.go | 51 +++------------ internal/glfw/glfw_notwindows.go | 32 ---------- internal/glfw/glfw_windows.go | 106 ------------------------------- 3 files changed, 9 insertions(+), 180 deletions(-) diff --git a/internal/glfw/const.go b/internal/glfw/const.go index a7c4610b1..74fb82a1c 100644 --- a/internal/glfw/const.go +++ b/internal/glfw/const.go @@ -22,17 +22,15 @@ import ( ) type ( - Action int - ErrorCode int - Hint int - InputMode int - Joystick int - JoystickHatState int - Key int - ModifierKey int - MouseButton int - PeripheralEvent int - StandardCursor int + Action int + ErrorCode int + Hint int + InputMode int + Key int + ModifierKey int + MouseButton int + PeripheralEvent int + StandardCursor int ) const ( @@ -59,25 +57,6 @@ const ( MouseButtonMiddle = MouseButton(2) ) -const ( - Joystick1 = Joystick(0) - Joystick2 = Joystick(1) - Joystick3 = Joystick(2) - Joystick4 = Joystick(3) - Joystick5 = Joystick(4) - Joystick6 = Joystick(5) - Joystick7 = Joystick(6) - Joystick8 = Joystick(7) - Joystick9 = Joystick(8) - Joystick10 = Joystick(9) - Joystick11 = Joystick(10) - Joystick12 = Joystick(11) - Joystick13 = Joystick(12) - Joystick14 = Joystick(13) - Joystick15 = Joystick(14) - Joystick16 = Joystick(15) -) - const ( AutoIconify = Hint(0x00020006) ClientAPI = Hint(0x00022001) @@ -156,15 +135,3 @@ const ( HResizeCursor = StandardCursor(0x00036005) VResizeCursor = StandardCursor(0x00036006) ) - -const ( - HatCentered = JoystickHatState(0) - HatUp = JoystickHatState(1) - HatRight = JoystickHatState(2) - HatDown = JoystickHatState(4) - HatLeft = JoystickHatState(8) - HatRightUp = HatRight | HatUp - HatRightDown = HatRight | HatDown - HatLeftUp = HatLeft | HatUp - HatLeftDown = HatLeft | HatDown -) diff --git a/internal/glfw/glfw_notwindows.go b/internal/glfw/glfw_notwindows.go index 1dc80629a..4e9d81957 100644 --- a/internal/glfw/glfw_notwindows.go +++ b/internal/glfw/glfw_notwindows.go @@ -269,34 +269,6 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind return theWindows.add(w), nil } -func (j Joystick) GetGUID() string { - return glfw.Joystick(j).GetGUID() -} - -func (j Joystick) GetName() string { - return glfw.Joystick(j).GetName() -} - -func (j Joystick) GetAxes() []float32 { - return glfw.Joystick(j).GetAxes() -} - -func (j Joystick) GetButtons() []Action { - var bs []Action - for _, b := range glfw.Joystick(j).GetButtons() { - bs = append(bs, Action(b)) - } - return bs -} - -func (j Joystick) GetHats() []JoystickHatState { - var hats []JoystickHatState - for _, s := range glfw.Joystick(j).GetHats() { - hats = append(hats, JoystickHatState(s)) - } - return hats -} - func GetMonitors() []*Monitor { ms := []*Monitor{} for _, m := range glfw.GetMonitors() { @@ -321,10 +293,6 @@ func Init() error { return glfw.Init() } -func (j Joystick) Present() bool { - return glfw.Joystick(j).Present() -} - func PollEvents() { glfw.PollEvents() } diff --git a/internal/glfw/glfw_windows.go b/internal/glfw/glfw_windows.go index de2d5978f..176652814 100644 --- a/internal/glfw/glfw_windows.go +++ b/internal/glfw/glfw_windows.go @@ -352,106 +352,6 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind return theGLFWWindows.add(w), nil } -func (j Joystick) GetGUID() string { - ptr := glfwDLL.call("glfwGetJoystickGUID", uintptr(j)) - panicError() - - // ptr can be nil after disconnecting the joystick. - if ptr == 0 { - return "" - } - - var backed [256]byte - as := backed[:0] - for i := int32(0); ; i++ { - b := *(*byte)(unsafe.Pointer(ptr)) - ptr += unsafe.Sizeof(byte(0)) - if b == 0 { - break - } - as = append(as, b) - } - r := string(as) - return r -} - -func (j Joystick) GetName() string { - ptr := glfwDLL.call("glfwGetJoystickName", uintptr(j)) - panicError() - - // ptr can be nil after disconnecting the joystick. - if ptr == 0 { - return "" - } - - var backed [256]byte - as := backed[:0] - for i := int32(0); ; i++ { - b := *(*byte)(unsafe.Pointer(ptr)) - ptr += unsafe.Sizeof(byte(0)) - if b == 0 { - break - } - as = append(as, b) - } - r := string(as) - return r -} - -func (j Joystick) GetAxes() []float32 { - var l int32 - ptr := glfwDLL.call("glfwGetJoystickAxes", uintptr(j), uintptr(unsafe.Pointer(&l))) - panicError() - - // ptr can be nil after disconnecting the joystick. - if ptr == 0 { - return nil - } - - as := make([]float32, l) - for i := int32(0); i < l; i++ { - as[i] = *(*float32)(unsafe.Pointer(ptr)) - ptr += unsafe.Sizeof(float32(0)) - } - return as -} - -func (j Joystick) GetButtons() []byte { - var l int32 - ptr := glfwDLL.call("glfwGetJoystickButtons", uintptr(j), uintptr(unsafe.Pointer(&l))) - panicError() - - // ptr can be nil after disconnecting the joystick. - if ptr == 0 { - return nil - } - - bs := make([]byte, l) - for i := int32(0); i < l; i++ { - bs[i] = *(*byte)(unsafe.Pointer(ptr)) - ptr++ - } - return bs -} - -func (j Joystick) GetHats() []JoystickHatState { - var l int32 - ptr := glfwDLL.call("glfwGetJoystickHats", uintptr(j), uintptr(unsafe.Pointer(&l))) - panicError() - - // ptr can be nil after disconnecting the joystick. - if ptr == 0 { - return nil - } - - hats := make([]JoystickHatState, l) - for i := int32(0); i < l; i++ { - hats[i] = *(*JoystickHatState)(unsafe.Pointer(ptr)) - ptr++ - } - return hats -} - func GetMonitors() []*Monitor { var l int32 ptr := glfwDLL.call("glfwGetMonitors", uintptr(unsafe.Pointer(&l))) @@ -489,12 +389,6 @@ func Init() error { return err } -func (j Joystick) Present() bool { - r := glfwDLL.call("glfwJoystickPresent", uintptr(j)) - panicError() - return byte(r) == True -} - func panicErrorExceptForInvalidValue() { // InvalidValue can happen when specific joysticks are used. This issue // will be fixed in GLFW 3.3.5. As a temporary fix, ignore this error.