mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
parent
2d9349824f
commit
a70be6e2f8
33
internal/uidriver/mobile/gamepad_android.go
Normal file
33
internal/uidriver/mobile/gamepad_android.go
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2021 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 mobile
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
)
|
||||
|
||||
// UpdateGamepads updates the gamepad states.
|
||||
// UpdateGamepads is called when the gamepad states are given from outside like Android.
|
||||
func (u *UserInterface) UpdateGamepads(gamepads []Gamepad) {
|
||||
u.input.updateGamepads(gamepads)
|
||||
if u.fpsMode == driver.FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Input) updateGamepads(gamepads []Gamepad) {
|
||||
i.gamepads = i.gamepads[:0]
|
||||
i.gamepads = append(i.gamepads, gamepads...)
|
||||
}
|
20
internal/uidriver/mobile/gamepad_ios.go
Normal file
20
internal/uidriver/mobile/gamepad_ios.go
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2021 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.
|
||||
|
||||
//go:build ios
|
||||
// +build ios
|
||||
|
||||
package mobile
|
||||
|
||||
// TODO: Implement gamepad detection for iOS (#1105).
|
@ -212,11 +212,6 @@ func (i *Input) update(keys map[driver.Key]struct{}, runes []rune, touches []Tou
|
||||
i.touches = append(i.touches, touches...)
|
||||
}
|
||||
|
||||
func (i *Input) updateGamepads(gamepads []Gamepad) {
|
||||
i.gamepads = i.gamepads[:0]
|
||||
i.gamepads = append(i.gamepads, gamepads...)
|
||||
}
|
||||
|
||||
func (i *Input) resetForFrame() {
|
||||
i.runes = nil
|
||||
}
|
||||
|
@ -475,15 +475,6 @@ func (u *UserInterface) UpdateInput(keys map[driver.Key]struct{}, runes []rune,
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateGamepads updates the gamepad states.
|
||||
// UpdateGamepads is called when the gamepad states are given from outside like Android.
|
||||
func (u *UserInterface) UpdateGamepads(gamepads []Gamepad) {
|
||||
u.input.updateGamepads(gamepads)
|
||||
if u.fpsMode == driver.FPSModeVsyncOffMinimum {
|
||||
u.renderRequester.RequestRenderIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
type RenderRequester interface {
|
||||
SetExplicitRenderingMode(explicitRendering bool)
|
||||
RequestRenderIfNeeded()
|
||||
|
@ -18,8 +18,6 @@
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/uidriver/mobile"
|
||||
)
|
||||
@ -33,14 +31,10 @@ var (
|
||||
keys = map[driver.Key]struct{}{}
|
||||
runes []rune
|
||||
touches = map[driver.TouchID]position{}
|
||||
|
||||
// gamepads is updated only at Android.
|
||||
gamepads = map[driver.GamepadID]mobile.Gamepad{}
|
||||
)
|
||||
|
||||
var (
|
||||
touchSlice []mobile.Touch
|
||||
gamepadSlice []mobile.Gamepad
|
||||
touchSlice []mobile.Touch
|
||||
)
|
||||
|
||||
func updateInput() {
|
||||
@ -54,12 +48,4 @@ func updateInput() {
|
||||
}
|
||||
|
||||
mobile.Get().UpdateInput(keys, runes, touchSlice)
|
||||
|
||||
if runtime.GOOS == "android" {
|
||||
gamepadSlice = gamepadSlice[:0]
|
||||
for _, g := range gamepads {
|
||||
gamepadSlice = append(gamepadSlice, g)
|
||||
}
|
||||
mobile.Get().UpdateGamepads(gamepadSlice)
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ func OnKeyDownOnAndroid(keyCode int, unicodeChar int, source int, deviceID int)
|
||||
return
|
||||
}
|
||||
g.Buttons[button] = true
|
||||
updateInput()
|
||||
updateGamepads()
|
||||
}
|
||||
case source&sourceJoystick == sourceJoystick:
|
||||
// DPAD keys can come here, but they are also treated as an axis at a motion event. Ignore them.
|
||||
@ -248,7 +248,7 @@ func OnKeyUpOnAndroid(keyCode int, source int, deviceID int) {
|
||||
return
|
||||
}
|
||||
g.Buttons[button] = false
|
||||
updateInput()
|
||||
updateGamepads()
|
||||
}
|
||||
case source&sourceJoystick == sourceJoystick:
|
||||
// DPAD keys can come here, but they are also treated as an axis at a motion event. Ignore them.
|
||||
@ -272,7 +272,7 @@ func OnGamepadAxesChanged(deviceID int, axisID int, value float32) {
|
||||
return
|
||||
}
|
||||
g.Axes[aid] = value
|
||||
updateInput()
|
||||
updateGamepads()
|
||||
}
|
||||
|
||||
func OnGamepadAdded(deviceID int, name string, buttonNum int, axisNum int, descriptor string, vendorID int, productID int, buttonMask int, axisMask int) {
|
||||
@ -309,6 +309,7 @@ func OnGamepadAdded(deviceID int, name string, buttonNum int, axisNum int, descr
|
||||
ButtonNum: buttonNum,
|
||||
AxisNum: axisNum,
|
||||
}
|
||||
updateGamepads()
|
||||
}
|
||||
|
||||
func OnInputDeviceRemoved(deviceID int) {
|
||||
@ -316,4 +317,18 @@ func OnInputDeviceRemoved(deviceID int) {
|
||||
delete(gamepads, id)
|
||||
delete(deviceIDToGamepadID, deviceID)
|
||||
}
|
||||
updateGamepads()
|
||||
}
|
||||
|
||||
var (
|
||||
gamepads = map[driver.GamepadID]mobile.Gamepad{}
|
||||
gamepadSlice []mobile.Gamepad
|
||||
)
|
||||
|
||||
func updateGamepads() {
|
||||
gamepadSlice = gamepadSlice[:0]
|
||||
for _, g := range gamepads {
|
||||
gamepadSlice = append(gamepadSlice, g)
|
||||
}
|
||||
mobile.Get().UpdateGamepads(gamepadSlice)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user