cmd/ebitenmobile: remove counting buttons and use a constant instead

Updates #2309
This commit is contained in:
Hajime Hoshi 2022-09-07 15:43:07 +09:00
parent db1255cdf8
commit d66c599938
4 changed files with 8 additions and 17 deletions

View File

@ -545,15 +545,6 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
return; return;
} }
boolean[] keyExistences = inputDevice.hasKeys(gamepadButtons);
int nbuttons = 0;
for (int i = 0; i < gamepadButtons.length; i++) {
if (!keyExistences[i]) {
break;
}
nbuttons++;
}
int naxes = 0; int naxes = 0;
int nhats2 = 0; int nhats2 = 0;
for (int i = 0; i < axes.length; i++) { for (int i = 0; i < axes.length; i++) {
@ -576,7 +567,7 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
int buttonMask = getButtonMask(inputDevice); int buttonMask = getButtonMask(inputDevice);
int axisMask = getAxisMask(inputDevice); int axisMask = getAxisMask(inputDevice);
Ebitenmobileview.onGamepadAdded(deviceId, inputDevice.getName(), nbuttons, naxes, nhats2/2, descriptor, vendorId, productId, buttonMask, axisMask); Ebitenmobileview.onGamepadAdded(deviceId, inputDevice.getName(), naxes, nhats2/2, descriptor, vendorId, productId, buttonMask, axisMask);
} }
// The implementation is copied from SDL: // The implementation is copied from SDL:

File diff suppressed because one or more lines are too long

View File

@ -28,8 +28,8 @@ const (
AndroidHatDirectionY AndroidHatDirectionY
) )
func AddAndroidGamepad(androidDeviceID int, name, sdlID string, axisCount, buttonCount, hatCount int) { func AddAndroidGamepad(androidDeviceID int, name, sdlID string, axisCount, hatCount int) {
theGamepads.addAndroidGamepad(androidDeviceID, name, sdlID, axisCount, buttonCount, hatCount) theGamepads.addAndroidGamepad(androidDeviceID, name, sdlID, axisCount, hatCount)
} }
func RemoveAndroidGamepad(androidDeviceID int) { func RemoveAndroidGamepad(androidDeviceID int) {
@ -48,7 +48,7 @@ func UpdateAndroidGamepadHat(androidDeviceID int, hat int, dir AndroidHatDirecti
theGamepads.updateAndroidGamepadHat(androidDeviceID, hat, dir, value) theGamepads.updateAndroidGamepadHat(androidDeviceID, hat, dir, value)
} }
func (g *gamepads) addAndroidGamepad(androidDeviceID int, name, sdlID string, axisCount, buttonCount, hatCount int) { func (g *gamepads) addAndroidGamepad(androidDeviceID int, name, sdlID string, axisCount, hatCount int) {
g.m.Lock() g.m.Lock()
defer g.m.Unlock() defer g.m.Unlock()
@ -56,7 +56,7 @@ func (g *gamepads) addAndroidGamepad(androidDeviceID int, name, sdlID string, ax
gp.native = &nativeGamepadImpl{ gp.native = &nativeGamepadImpl{
androidDeviceID: androidDeviceID, androidDeviceID: androidDeviceID,
axes: make([]float64, axisCount), axes: make([]float64, axisCount),
buttons: make([]bool, buttonCount), buttons: make([]bool, ButtonCount),
hats: make([]int, hatCount), hats: make([]int, hatCount),
} }
} }

View File

@ -254,7 +254,7 @@ func OnGamepadAxesOrHatsChanged(deviceID int, axisID int, value float32) {
} }
} }
func OnGamepadAdded(deviceID int, name string, buttonCount int, axisCount int, hatCount int, descriptor string, vendorID int, productID int, buttonMask int, axisMask int) { func OnGamepadAdded(deviceID int, name string, axisCount int, hatCount int, descriptor string, vendorID int, productID int, buttonMask int, axisMask int) {
// This emulates the implementation of Android_AddJoystick. // This emulates the implementation of Android_AddJoystick.
// https://github.com/libsdl-org/SDL/blob/0e9560aea22818884921e5e5064953257bfe7fa7/src/joystick/android/SDL_sysjoystick.c#L386 // https://github.com/libsdl-org/SDL/blob/0e9560aea22818884921e5e5064953257bfe7fa7/src/joystick/android/SDL_sysjoystick.c#L386
const SDL_HARDWARE_BUS_BLUETOOTH = 0x05 const SDL_HARDWARE_BUS_BLUETOOTH = 0x05
@ -280,7 +280,7 @@ func OnGamepadAdded(deviceID int, name string, buttonCount int, axisCount int, h
sdlid[14] = byte(axisMask) sdlid[14] = byte(axisMask)
sdlid[15] = byte(axisMask >> 8) sdlid[15] = byte(axisMask >> 8)
gamepad.AddAndroidGamepad(deviceID, name, hex.EncodeToString(sdlid[:]), axisCount, buttonCount, hatCount) gamepad.AddAndroidGamepad(deviceID, name, hex.EncodeToString(sdlid[:]), axisCount, hatCount)
} }
func OnInputDeviceRemoved(deviceID int) { func OnInputDeviceRemoved(deviceID int) {