From 8d9937801be3fcb3a018eb80ba413bc1a1b1e036 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 5 Feb 2022 02:09:30 +0900 Subject: [PATCH] internal/gamepad: refactoring --- internal/gamepad/extern_android.go | 9 +++------ internal/gamepad/gamepad_android.go | 10 +++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/gamepad/extern_android.go b/internal/gamepad/extern_android.go index 289e083bd..ca9aef3cd 100644 --- a/internal/gamepad/extern_android.go +++ b/internal/gamepad/extern_android.go @@ -53,9 +53,6 @@ func (g *gamepads) addAndroidGamepad(androidDeviceID int, name, sdlID string, ax gp := g.add(name, sdlID) gp.androidDeviceID = androidDeviceID - gp.axisCount_ = axisCount - gp.buttonCount_ = buttonCount - gp.hatCount_ = hatCount gp.axes = make([]float64, axisCount) gp.buttons = make([]bool, buttonCount) gp.hats = make([]int, hatCount) @@ -113,7 +110,7 @@ func (g *Gamepad) updateAndroidGamepadAxis(axis int, value float64) { g.m.Lock() defer g.m.Unlock() - if axis < 0 || axis >= g.axisCount_ { + if axis < 0 || axis >= len(g.axes) { return } g.axes[axis] = value @@ -123,7 +120,7 @@ func (g *Gamepad) updateAndroidGamepadButton(button driver.GamepadButton, presse g.m.Lock() defer g.m.Unlock() - if button < 0 || int(button) >= g.buttonCount_ { + if button < 0 || int(button) >= len(g.buttons) { return } g.buttons[button] = pressed @@ -133,7 +130,7 @@ func (g *Gamepad) updateAndroidGamepadHat(hat int, dir AndroidHatDirection, valu g.m.Lock() defer g.m.Unlock() - if hat < 0 || hat >= g.hatCount_ { + if hat < 0 || hat >= len(g.hats) { return } v := g.hats[hat] diff --git a/internal/gamepad/gamepad_android.go b/internal/gamepad/gamepad_android.go index b3d9b901b..2eac82813 100644 --- a/internal/gamepad/gamepad_android.go +++ b/internal/gamepad/gamepad_android.go @@ -31,10 +31,6 @@ func (*nativeGamepads) update(gamepads *gamepads) error { type nativeGamepad struct { androidDeviceID int - axisCount_ int - buttonCount_ int - hatCount_ int - axes []float64 buttons []bool hats []int @@ -50,15 +46,15 @@ func (*nativeGamepad) hasOwnStandardLayoutMapping() bool { } func (g *nativeGamepad) axisCount() int { - return g.axisCount_ + return len(g.axes) } func (g *nativeGamepad) buttonCount() int { - return g.buttonCount_ + return len(g.buttons) } func (g *nativeGamepad) hatCount() int { - return g.hatCount_ + return len(g.hats) } func (g *nativeGamepad) axisValue(axis int) float64 {