mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
internal/gamepad: refactoring
This commit is contained in:
parent
d0e8efca33
commit
8d9937801b
@ -53,9 +53,6 @@ func (g *gamepads) addAndroidGamepad(androidDeviceID int, name, sdlID string, ax
|
|||||||
|
|
||||||
gp := g.add(name, sdlID)
|
gp := g.add(name, sdlID)
|
||||||
gp.androidDeviceID = androidDeviceID
|
gp.androidDeviceID = androidDeviceID
|
||||||
gp.axisCount_ = axisCount
|
|
||||||
gp.buttonCount_ = buttonCount
|
|
||||||
gp.hatCount_ = hatCount
|
|
||||||
gp.axes = make([]float64, axisCount)
|
gp.axes = make([]float64, axisCount)
|
||||||
gp.buttons = make([]bool, buttonCount)
|
gp.buttons = make([]bool, buttonCount)
|
||||||
gp.hats = make([]int, hatCount)
|
gp.hats = make([]int, hatCount)
|
||||||
@ -113,7 +110,7 @@ func (g *Gamepad) updateAndroidGamepadAxis(axis int, value float64) {
|
|||||||
g.m.Lock()
|
g.m.Lock()
|
||||||
defer g.m.Unlock()
|
defer g.m.Unlock()
|
||||||
|
|
||||||
if axis < 0 || axis >= g.axisCount_ {
|
if axis < 0 || axis >= len(g.axes) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
g.axes[axis] = value
|
g.axes[axis] = value
|
||||||
@ -123,7 +120,7 @@ func (g *Gamepad) updateAndroidGamepadButton(button driver.GamepadButton, presse
|
|||||||
g.m.Lock()
|
g.m.Lock()
|
||||||
defer g.m.Unlock()
|
defer g.m.Unlock()
|
||||||
|
|
||||||
if button < 0 || int(button) >= g.buttonCount_ {
|
if button < 0 || int(button) >= len(g.buttons) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
g.buttons[button] = pressed
|
g.buttons[button] = pressed
|
||||||
@ -133,7 +130,7 @@ func (g *Gamepad) updateAndroidGamepadHat(hat int, dir AndroidHatDirection, valu
|
|||||||
g.m.Lock()
|
g.m.Lock()
|
||||||
defer g.m.Unlock()
|
defer g.m.Unlock()
|
||||||
|
|
||||||
if hat < 0 || hat >= g.hatCount_ {
|
if hat < 0 || hat >= len(g.hats) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v := g.hats[hat]
|
v := g.hats[hat]
|
||||||
|
@ -31,10 +31,6 @@ func (*nativeGamepads) update(gamepads *gamepads) error {
|
|||||||
type nativeGamepad struct {
|
type nativeGamepad struct {
|
||||||
androidDeviceID int
|
androidDeviceID int
|
||||||
|
|
||||||
axisCount_ int
|
|
||||||
buttonCount_ int
|
|
||||||
hatCount_ int
|
|
||||||
|
|
||||||
axes []float64
|
axes []float64
|
||||||
buttons []bool
|
buttons []bool
|
||||||
hats []int
|
hats []int
|
||||||
@ -50,15 +46,15 @@ func (*nativeGamepad) hasOwnStandardLayoutMapping() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepad) axisCount() int {
|
func (g *nativeGamepad) axisCount() int {
|
||||||
return g.axisCount_
|
return len(g.axes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepad) buttonCount() int {
|
func (g *nativeGamepad) buttonCount() int {
|
||||||
return g.buttonCount_
|
return len(g.buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepad) hatCount() int {
|
func (g *nativeGamepad) hatCount() int {
|
||||||
return g.hatCount_
|
return len(g.hats)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepad) axisValue(axis int) float64 {
|
func (g *nativeGamepad) axisValue(axis int) float64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user