mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
internal/gamepaddb: Use XInput's trigger threshold
This commit is contained in:
parent
226378da88
commit
f64a946052
@ -398,6 +398,10 @@ func ButtonValue(id string, button driver.StandardGamepadButton, state GamepadSt
|
|||||||
mappingsM.RLock()
|
mappingsM.RLock()
|
||||||
defer mappingsM.RUnlock()
|
defer mappingsM.RUnlock()
|
||||||
|
|
||||||
|
return buttonValue(id, button, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buttonValue(id string, button driver.StandardGamepadButton, state GamepadState) float64 {
|
||||||
mappings, ok := gamepadButtonMappings[id]
|
mappings, ok := gamepadButtonMappings[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0
|
return 0
|
||||||
@ -429,6 +433,10 @@ func ButtonValue(id string, button driver.StandardGamepadButton, state GamepadSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsButtonPressed(id string, button driver.StandardGamepadButton, state GamepadState) bool {
|
func IsButtonPressed(id string, button driver.StandardGamepadButton, state GamepadState) bool {
|
||||||
|
// Use XInput's trigger dead zone.
|
||||||
|
// See https://source.chromium.org/chromium/chromium/src/+/main:device/gamepad/public/cpp/gamepad.h;l=22-23;drc=6997f8a177359bb99598988ed5e900841984d242
|
||||||
|
const threshold = 30.0 / 255.0
|
||||||
|
|
||||||
mappingsM.RLock()
|
mappingsM.RLock()
|
||||||
defer mappingsM.RUnlock()
|
defer mappingsM.RUnlock()
|
||||||
|
|
||||||
@ -438,12 +446,8 @@ func IsButtonPressed(id string, button driver.StandardGamepadButton, state Gamep
|
|||||||
}
|
}
|
||||||
switch m := mappings[button]; m.Type {
|
switch m := mappings[button]; m.Type {
|
||||||
case mappingTypeAxis:
|
case mappingTypeAxis:
|
||||||
v := state.Axis(m.Index)*float64(m.AxisScale) + float64(m.AxisOffset)
|
v := buttonValue(id, button, state)
|
||||||
if m.AxisOffset < 0 || m.AxisOffset == 0 && m.AxisScale > 0 {
|
return v > threshold
|
||||||
return v >= 0
|
|
||||||
} else {
|
|
||||||
return v <= 0
|
|
||||||
}
|
|
||||||
case mappingTypeButton:
|
case mappingTypeButton:
|
||||||
return state.Button(m.Index)
|
return state.Button(m.Index)
|
||||||
case mappingTypeHat:
|
case mappingTypeHat:
|
||||||
|
Loading…
Reference in New Issue
Block a user