mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
a7beddbc94
commit
d6547f12c6
@ -109,6 +109,13 @@ type _GameInputGamepadState struct {
|
|||||||
rightThumbstickY float32
|
rightThumbstickY float32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type _GameInputRumbleParams struct {
|
||||||
|
lowFrequency float32
|
||||||
|
highFrequency float32
|
||||||
|
leftTrigger float32
|
||||||
|
rightTrigger float32
|
||||||
|
}
|
||||||
|
|
||||||
func _GameInputCreate() (*_IGameInput, error) {
|
func _GameInputCreate() (*_IGameInput, error) {
|
||||||
var gameInput *_IGameInput
|
var gameInput *_IGameInput
|
||||||
r, _, _ := procGameInputCreate.Call(uintptr(unsafe.Pointer(&gameInput)))
|
r, _, _ := procGameInputCreate.Call(uintptr(unsafe.Pointer(&gameInput)))
|
||||||
@ -250,3 +257,8 @@ func (i *_IGameInputReading) GetGamepadState() (_GameInputGamepadState, bool) {
|
|||||||
func (i *_IGameInputReading) Release() {
|
func (i *_IGameInputReading) Release() {
|
||||||
syscall.Syscall(i.vtbl.Release, 1, uintptr(unsafe.Pointer(i)), 0, 0)
|
syscall.Syscall(i.vtbl.Release, 1, uintptr(unsafe.Pointer(i)), 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *_IGameInputDevice) SetRumbleState(params *_GameInputRumbleParams, timestamp uint64) {
|
||||||
|
syscall.Syscall(i.vtbl.SetRumbleState, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(params)), uintptr(timestamp))
|
||||||
|
runtime.KeepAlive(params)
|
||||||
|
}
|
||||||
|
@ -123,6 +123,9 @@ func (n *nativeGamepadsXbox) deviceCallback(callbackToken _GameInputCallbackToke
|
|||||||
type nativeGamepadXbox struct {
|
type nativeGamepadXbox struct {
|
||||||
gameInputDevice *_IGameInputDevice
|
gameInputDevice *_IGameInputDevice
|
||||||
state _GameInputGamepadState
|
state _GameInputGamepadState
|
||||||
|
|
||||||
|
vib bool
|
||||||
|
vibEnd time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nativeGamepadXbox) update(gamepads *gamepads) error {
|
func (n *nativeGamepadXbox) update(gamepads *gamepads) error {
|
||||||
@ -139,6 +142,15 @@ func (n *nativeGamepadXbox) update(gamepads *gamepads) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
n.state = state
|
n.state = state
|
||||||
|
|
||||||
|
if n.vib && time.Now().Sub(n.vibEnd) >= 0 {
|
||||||
|
n.gameInputDevice.SetRumbleState(&_GameInputRumbleParams{
|
||||||
|
lowFrequency: 0,
|
||||||
|
highFrequency: 0,
|
||||||
|
}, 0)
|
||||||
|
n.vib = false
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,4 +228,17 @@ func (n *nativeGamepadXbox) hatState(hat int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *nativeGamepadXbox) vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
|
func (n *nativeGamepadXbox) vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
|
||||||
|
if strongMagnitude <= 0 && weakMagnitude <= 0 {
|
||||||
|
n.gameInputDevice.SetRumbleState(&_GameInputRumbleParams{
|
||||||
|
lowFrequency: 0,
|
||||||
|
highFrequency: 0,
|
||||||
|
}, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
n.vib = true
|
||||||
|
n.vibEnd = time.Now().Add(duration)
|
||||||
|
n.gameInputDevice.SetRumbleState(&_GameInputRumbleParams{
|
||||||
|
lowFrequency: float32(strongMagnitude),
|
||||||
|
highFrequency: float32(weakMagnitude),
|
||||||
|
}, 0)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user