mobile/ebitenmobileview: bug fix: gamepads didn't work on Android

Closes #1934
This commit is contained in:
Hajime Hoshi 2022-01-07 17:16:30 +09:00
parent 3b0ce21a56
commit 7e08333dd9

View File

@ -302,7 +302,7 @@ func OnGamepadAdded(deviceID int, name string, buttonNum int, axisNum int, descr
sdlid[15] = byte(axisMask >> 8) sdlid[15] = byte(axisMask >> 8)
id := gamepadIDFromDeviceID(deviceID) id := gamepadIDFromDeviceID(deviceID)
gamepads[id] = mobile.Gamepad{ gamepads[id] = &mobile.Gamepad{
ID: id, ID: id,
SDLID: hex.EncodeToString(sdlid[:]), SDLID: hex.EncodeToString(sdlid[:]),
Name: name, Name: name,
@ -321,14 +321,14 @@ func OnInputDeviceRemoved(deviceID int) {
} }
var ( var (
gamepads = map[driver.GamepadID]mobile.Gamepad{} gamepads = map[driver.GamepadID]*mobile.Gamepad{}
gamepadSlice []mobile.Gamepad gamepadSlice []mobile.Gamepad
) )
func updateGamepads() { func updateGamepads() {
gamepadSlice = gamepadSlice[:0] gamepadSlice = gamepadSlice[:0]
for _, g := range gamepads { for _, g := range gamepads {
gamepadSlice = append(gamepadSlice, g) gamepadSlice = append(gamepadSlice, *g)
} }
mobile.Get().UpdateGamepads(gamepadSlice) mobile.Get().UpdateGamepads(gamepadSlice)
} }