internal/glfw: refactoring: remove unused APIs

Ebiten doesn't rely on GLFW for gamepads.
This commit is contained in:
Hajime Hoshi 2022-05-19 01:04:15 +09:00
parent fef79f4d3e
commit 7189c7f649
3 changed files with 9 additions and 180 deletions

View File

@ -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
)

View File

@ -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()
}

View File

@ -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.