From dbcb2207429ebedb15a7a77fdd71a176a8ce3cac Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 19 Jul 2021 01:22:31 +0900 Subject: [PATCH] ebiten: Add GamepadAxisValue replacing GamepadAxis Updates #1718 Closes #1719 --- input.go | 15 +++++++++++---- internal/driver/input.go | 2 +- internal/uidriver/glfw/input.go | 2 +- internal/uidriver/js/input_js.go | 2 +- internal/uidriver/mobile/input.go | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/input.go b/input.go index 0283b1c7a..82a359f4d 100644 --- a/input.go +++ b/input.go @@ -169,13 +169,20 @@ func GamepadAxisNum(id GamepadID) int { return uiDriver().Input().GamepadAxisNum(id) } +// GamepadAxisValue returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis). +// +// GamepadAxisValue is concurrent-safe. +// +// GamepadAxisValue always returns 0 on iOS. +func GamepadAxisValue(id GamepadID, axis int) float64 { + return uiDriver().Input().GamepadAxisValue(id, axis) +} + // GamepadAxis returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis). // -// GamepadAxis is concurrent-safe. -// -// GamepadAxis always returns 0 on iOS. +// Deprecated: as of v2.2. Use GamepadAxisValue instead. func GamepadAxis(id GamepadID, axis int) float64 { - return uiDriver().Input().GamepadAxis(id, axis) + return GamepadAxisValue(id, axis) } // GamepadButtonNum returns the number of the buttons of the given gamepad (id). diff --git a/internal/driver/input.go b/internal/driver/input.go index f4f9f2167..7e480317e 100644 --- a/internal/driver/input.go +++ b/internal/driver/input.go @@ -25,7 +25,7 @@ type Input interface { CursorPosition() (x, y int) GamepadSDLID(id GamepadID) string GamepadName(id GamepadID) string - GamepadAxis(id GamepadID, axis int) float64 + GamepadAxisValue(id GamepadID, axis int) float64 GamepadAxisNum(id GamepadID) int GamepadButtonNum(id GamepadID) int IsGamepadButtonPressed(id GamepadID, button GamepadButton) bool diff --git a/internal/uidriver/glfw/input.go b/internal/uidriver/glfw/input.go index 82d731981..c7c1dd777 100644 --- a/internal/uidriver/glfw/input.go +++ b/internal/uidriver/glfw/input.go @@ -121,7 +121,7 @@ func (i *Input) GamepadAxisNum(id driver.GamepadID) int { return i.gamepads[id].axisNum } -func (i *Input) GamepadAxis(id driver.GamepadID, axis int) float64 { +func (i *Input) GamepadAxisValue(id driver.GamepadID, axis int) float64 { if !i.ui.isRunning() { return 0 } diff --git a/internal/uidriver/js/input_js.go b/internal/uidriver/js/input_js.go index 88c2461c4..d83a0c2b5 100644 --- a/internal/uidriver/js/input_js.go +++ b/internal/uidriver/js/input_js.go @@ -129,7 +129,7 @@ func (i *Input) GamepadAxisNum(id driver.GamepadID) int { return g.axisNum } -func (i *Input) GamepadAxis(id driver.GamepadID, axis int) float64 { +func (i *Input) GamepadAxisValue(id driver.GamepadID, axis int) float64 { g, ok := i.gamepads[id] if !ok { return 0 diff --git a/internal/uidriver/mobile/input.go b/internal/uidriver/mobile/input.go index 55df346c6..08d7d6e64 100644 --- a/internal/uidriver/mobile/input.go +++ b/internal/uidriver/mobile/input.go @@ -87,7 +87,7 @@ func (i *Input) GamepadAxisNum(id driver.GamepadID) int { return 0 } -func (i *Input) GamepadAxis(id driver.GamepadID, axis int) float64 { +func (i *Input) GamepadAxisValue(id driver.GamepadID, axis int) float64 { i.ui.m.RLock() defer i.ui.m.RUnlock()