mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
uidriver/mobile: Reduce mutex to avoid potential deadlock
This commit is contained in:
parent
6cd74a9f4d
commit
25ac788ee6
@ -17,8 +17,6 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
)
|
||||
|
||||
@ -32,12 +30,11 @@ type Input struct {
|
||||
cursorY int
|
||||
touches map[int]pos
|
||||
ui *UserInterface
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
func (i *Input) CursorPosition() (x, y int) {
|
||||
i.m.RLock()
|
||||
defer i.m.RUnlock()
|
||||
i.ui.m.RLock()
|
||||
defer i.ui.m.RUnlock()
|
||||
return i.ui.adjustPosition(i.cursorX, i.cursorY)
|
||||
}
|
||||
|
||||
@ -62,8 +59,8 @@ func (i *Input) IsGamepadButtonPressed(id int, button driver.GamepadButton) bool
|
||||
}
|
||||
|
||||
func (i *Input) TouchIDs() []int {
|
||||
i.m.RLock()
|
||||
defer i.m.RUnlock()
|
||||
i.ui.m.RLock()
|
||||
defer i.ui.m.RUnlock()
|
||||
|
||||
if len(i.touches) == 0 {
|
||||
return nil
|
||||
@ -77,8 +74,8 @@ func (i *Input) TouchIDs() []int {
|
||||
}
|
||||
|
||||
func (i *Input) TouchPosition(id int) (x, y int) {
|
||||
i.m.RLock()
|
||||
defer i.m.RUnlock()
|
||||
i.ui.m.RLock()
|
||||
defer i.ui.m.RUnlock()
|
||||
|
||||
for tid, pos := range i.touches {
|
||||
if id == tid {
|
||||
@ -105,7 +102,7 @@ func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool {
|
||||
}
|
||||
|
||||
func (i *Input) update(touches []*Touch) {
|
||||
i.m.Lock()
|
||||
i.ui.m.Lock()
|
||||
i.touches = map[int]pos{}
|
||||
for _, t := range touches {
|
||||
i.touches[t.ID] = pos{
|
||||
@ -113,7 +110,7 @@ func (i *Input) update(touches []*Touch) {
|
||||
Y: t.Y,
|
||||
}
|
||||
}
|
||||
i.m.Unlock()
|
||||
i.ui.m.Unlock()
|
||||
}
|
||||
|
||||
func (i *Input) ResetForFrame() {
|
||||
|
@ -376,11 +376,9 @@ func (u *UserInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) {
|
||||
}
|
||||
|
||||
func (u *UserInterface) adjustPosition(x, y int) (int, int) {
|
||||
u.m.Lock()
|
||||
ox, oy, _, _ := u.screenPaddingImpl()
|
||||
s := u.scaleImpl()
|
||||
as := s * getDeviceScale()
|
||||
u.m.Unlock()
|
||||
return int(float64(x)/s - ox/as), int(float64(y)/s - oy/as)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user