mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-15 07:27:32 +01:00
b7dd45c0e4
On Android, MotionEvent with 0 values might come for axes when connecting a gamepad, even though a user didn't touch any axes. This is problematic especially for tirgger axes, where the default value should be -1. This change fixes the issue by adding a new state `axesReady` to check if an axis is really touched or not. If an axis is not touched yet, a button value for a standard (trigger) button always returns 0. This change also removes an old hack to initialize axis values for triggers. Closes #2598
114 lines
2.5 KiB
Go
114 lines
2.5 KiB
Go
// Copyright 2022 The Ebiten Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package gamepad
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/gamepaddb"
|
|
)
|
|
|
|
type nativeGamepadsImpl struct{}
|
|
|
|
func newNativeGamepadsImpl() nativeGamepads {
|
|
return &nativeGamepadsImpl{}
|
|
}
|
|
|
|
func (*nativeGamepadsImpl) init(gamepads *gamepads) error {
|
|
initializeIOSGamepads()
|
|
return nil
|
|
}
|
|
|
|
func (*nativeGamepadsImpl) update(gamepads *gamepads) error {
|
|
return nil
|
|
}
|
|
|
|
type nativeGamepadImpl struct {
|
|
controller uintptr
|
|
buttonMask uint16
|
|
hasDualshockTouchpad bool
|
|
hasXboxPaddles bool
|
|
hasXboxShareButton bool
|
|
|
|
axes []float64
|
|
buttons []bool
|
|
hats []int
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) update(gamepad *gamepads) error {
|
|
g.updateIOSGamepad()
|
|
return nil
|
|
}
|
|
|
|
func (*nativeGamepadImpl) hasOwnStandardLayoutMapping() bool {
|
|
return false
|
|
}
|
|
|
|
func (*nativeGamepadImpl) standardAxisInOwnMapping(axis gamepaddb.StandardAxis) mappingInput {
|
|
return nil
|
|
}
|
|
|
|
func (*nativeGamepadImpl) standardButtonInOwnMapping(button gamepaddb.StandardButton) mappingInput {
|
|
return nil
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) axisCount() int {
|
|
return len(g.axes)
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) buttonCount() int {
|
|
return len(g.buttons)
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) hatCount() int {
|
|
return len(g.hats)
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) isAxisReady(axis int) bool {
|
|
return axis >= 0 && axis < g.axisCount()
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) axisValue(axis int) float64 {
|
|
if axis < 0 || axis >= len(g.axes) {
|
|
return 0
|
|
}
|
|
return g.axes[axis]
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) isButtonPressed(button int) bool {
|
|
if button < 0 || button >= len(g.buttons) {
|
|
return false
|
|
}
|
|
return g.buttons[button]
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) buttonValue(button int) float64 {
|
|
if g.isButtonPressed(button) {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) hatState(hat int) int {
|
|
if hat < 0 || hat >= len(g.hats) {
|
|
return 0
|
|
}
|
|
return g.hats[hat]
|
|
}
|
|
|
|
func (g *nativeGamepadImpl) vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
|
|
// TODO: Implement this (#1452)
|
|
}
|