diff --git a/internal/uidriver/mobile/input.go b/internal/uidriver/mobile/input.go index 8b3e6fb00..0c4fc8416 100644 --- a/internal/uidriver/mobile/input.go +++ b/internal/uidriver/mobile/input.go @@ -199,7 +199,7 @@ func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool { return false } -func (i *Input) update(keys map[driver.Key]struct{}, runes []rune, touches []*Touch, gamepads []Gamepad) { +func (i *Input) update(keys map[driver.Key]struct{}, runes []rune, touches []Touch, gamepads []Gamepad) { i.ui.m.Lock() defer i.ui.m.Unlock() diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index 81ac4afb7..23f081582 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -129,7 +129,7 @@ func (u *UserInterface) appMain(a app.App) { var glctx gl.Context var sizeInited bool - touches := map[touch.Sequence]*Touch{} + touches := map[touch.Sequence]Touch{} keys := map[driver.Key]struct{}{} for e := range a.Events() { @@ -184,7 +184,7 @@ func (u *UserInterface) appMain(a app.App) { s := deviceScale() x, y := float64(e.X)/s, float64(e.Y)/s // TODO: Is it ok to cast from int64 to int here? - touches[e.Sequence] = &Touch{ + touches[e.Sequence] = Touch{ ID: driver.TouchID(e.Sequence), X: int(x), Y: int(y), @@ -214,7 +214,7 @@ func (u *UserInterface) appMain(a app.App) { } if updateInput { - ts := []*Touch{} + var ts []Touch for _, t := range touches { ts = append(ts, t) } @@ -468,7 +468,7 @@ type Gamepad struct { AxisNum int } -func (u *UserInterface) UpdateInput(keys map[driver.Key]struct{}, runes []rune, touches []*Touch, gamepads []Gamepad) { +func (u *UserInterface) UpdateInput(keys map[driver.Key]struct{}, runes []rune, touches []Touch, gamepads []Gamepad) { u.input.update(keys, runes, touches, gamepads) if u.fpsMode == driver.FPSModeVsyncOffMinimum { u.renderRequester.RequestRenderIfNeeded() diff --git a/mobile/ebitenmobileview/input.go b/mobile/ebitenmobileview/input.go index 47ff83e5b..dffde113d 100644 --- a/mobile/ebitenmobileview/input.go +++ b/mobile/ebitenmobileview/input.go @@ -31,23 +31,28 @@ var ( keys = map[driver.Key]struct{}{} runes []rune touches = map[driver.TouchID]position{} - gamepads = map[driver.GamepadID]*mobile.Gamepad{} + gamepads = map[driver.GamepadID]mobile.Gamepad{} +) + +var ( + touchSlice []mobile.Touch + gamepadSlice []mobile.Gamepad ) func updateInput() { - ts := make([]*mobile.Touch, 0, len(touches)) + touchSlice = touchSlice[:0] for id, position := range touches { - ts = append(ts, &mobile.Touch{ + touchSlice = append(touchSlice, mobile.Touch{ ID: id, X: position.x, Y: position.y, }) } - gs := make([]mobile.Gamepad, 0, len(gamepads)) + gamepadSlice = gamepadSlice[:0] for _, g := range gamepads { - gs = append(gs, *g) + gamepadSlice = append(gamepadSlice, g) } - mobile.Get().UpdateInput(keys, runes, ts, gs) + mobile.Get().UpdateInput(keys, runes, touchSlice, gamepadSlice) } diff --git a/mobile/ebitenmobileview/input_android.go b/mobile/ebitenmobileview/input_android.go index 5aee13ac2..752265997 100644 --- a/mobile/ebitenmobileview/input_android.go +++ b/mobile/ebitenmobileview/input_android.go @@ -302,7 +302,7 @@ func OnGamepadAdded(deviceID int, name string, buttonNum int, axisNum int, descr sdlid[15] = byte(axisMask >> 8) id := gamepadIDFromDeviceID(deviceID) - gamepads[id] = &mobile.Gamepad{ + gamepads[id] = mobile.Gamepad{ ID: id, SDLID: hex.EncodeToString(sdlid[:]), Name: name,