mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
internal/uidriver/mobile: Separate UpdateInput into UpdateInput and UpdateGamepads
This commit is contained in:
parent
ab5220ea4c
commit
2d9349824f
@ -191,7 +191,7 @@ func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool {
|
|||||||
return false
|
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) {
|
||||||
i.ui.m.Lock()
|
i.ui.m.Lock()
|
||||||
defer i.ui.m.Unlock()
|
defer i.ui.m.Unlock()
|
||||||
|
|
||||||
@ -210,7 +210,9 @@ func (i *Input) update(keys map[driver.Key]struct{}, runes []rune, touches []Tou
|
|||||||
|
|
||||||
i.touches = i.touches[:0]
|
i.touches = i.touches[:0]
|
||||||
i.touches = append(i.touches, touches...)
|
i.touches = append(i.touches, touches...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Input) updateGamepads(gamepads []Gamepad) {
|
||||||
i.gamepads = i.gamepads[:0]
|
i.gamepads = i.gamepads[:0]
|
||||||
i.gamepads = append(i.gamepads, gamepads...)
|
i.gamepads = append(i.gamepads, gamepads...)
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ func (u *UserInterface) appMain(a app.App) {
|
|||||||
for _, t := range touches {
|
for _, t := range touches {
|
||||||
ts = append(ts, t)
|
ts = append(ts, t)
|
||||||
}
|
}
|
||||||
u.input.update(keys, runes, ts, nil)
|
u.input.update(keys, runes, ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -468,8 +468,17 @@ type Gamepad struct {
|
|||||||
AxisNum int
|
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) {
|
||||||
u.input.update(keys, runes, touches, gamepads)
|
u.input.update(keys, runes, touches)
|
||||||
|
if u.fpsMode == driver.FPSModeVsyncOffMinimum {
|
||||||
|
u.renderRequester.RequestRenderIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGamepads updates the gamepad states.
|
||||||
|
// UpdateGamepads is called when the gamepad states are given from outside like Android.
|
||||||
|
func (u *UserInterface) UpdateGamepads(gamepads []Gamepad) {
|
||||||
|
u.input.updateGamepads(gamepads)
|
||||||
if u.fpsMode == driver.FPSModeVsyncOffMinimum {
|
if u.fpsMode == driver.FPSModeVsyncOffMinimum {
|
||||||
u.renderRequester.RequestRenderIfNeeded()
|
u.renderRequester.RequestRenderIfNeeded()
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
package ebitenmobileview
|
package ebitenmobileview
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/uidriver/mobile"
|
"github.com/hajimehoshi/ebiten/v2/internal/uidriver/mobile"
|
||||||
)
|
)
|
||||||
@ -28,9 +30,11 @@ type position struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
keys = map[driver.Key]struct{}{}
|
keys = map[driver.Key]struct{}{}
|
||||||
runes []rune
|
runes []rune
|
||||||
touches = map[driver.TouchID]position{}
|
touches = map[driver.TouchID]position{}
|
||||||
|
|
||||||
|
// gamepads is updated only at Android.
|
||||||
gamepads = map[driver.GamepadID]mobile.Gamepad{}
|
gamepads = map[driver.GamepadID]mobile.Gamepad{}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,10 +53,13 @@ func updateInput() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
gamepadSlice = gamepadSlice[:0]
|
mobile.Get().UpdateInput(keys, runes, touchSlice)
|
||||||
for _, g := range gamepads {
|
|
||||||
gamepadSlice = append(gamepadSlice, g)
|
|
||||||
}
|
|
||||||
|
|
||||||
mobile.Get().UpdateInput(keys, runes, touchSlice, gamepadSlice)
|
if runtime.GOOS == "android" {
|
||||||
|
gamepadSlice = gamepadSlice[:0]
|
||||||
|
for _, g := range gamepads {
|
||||||
|
gamepadSlice = append(gamepadSlice, g)
|
||||||
|
}
|
||||||
|
mobile.Get().UpdateGamepads(gamepadSlice)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user