ui: Avoid creating empty slice at GamepadIDs

This commit is contained in:
Hajime Hoshi 2018-02-12 20:20:39 +09:00
parent 57dd7db893
commit 7d9b901ab3

View File

@ -31,9 +31,14 @@ func (i *Input) CursorPosition() (x, y int) {
return adjustCursorPosition(i.cursorX, i.cursorY) return adjustCursorPosition(i.cursorX, i.cursorY)
} }
var emptyIDs = []int{}
func (i *Input) GamepadIDs() []int { func (i *Input) GamepadIDs() []int {
i.m.RLock() i.m.RLock()
defer i.m.RUnlock() defer i.m.RUnlock()
if len(i.gamepads) == 0 {
return emptyIDs
}
r := []int{} r := []int{}
for id, g := range i.gamepads { for id, g := range i.gamepads {
if g.valid { if g.valid {