2022-02-04 15:29:09 +01:00
|
|
|
// 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.
|
|
|
|
|
2022-09-14 17:20:45 +02:00
|
|
|
//go:build !nintendosdk
|
2022-02-04 15:29:09 +01:00
|
|
|
|
|
|
|
package gamepad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2022-08-11 05:35:20 +02:00
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/gamepaddb"
|
2022-02-04 15:29:09 +01:00
|
|
|
)
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
type nativeGamepadsImpl struct{}
|
2022-02-04 15:29:09 +01:00
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func newNativeGamepadsImpl() nativeGamepads {
|
|
|
|
return &nativeGamepadsImpl{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*nativeGamepadsImpl) init(gamepads *gamepads) error {
|
2022-02-04 15:29:09 +01:00
|
|
|
initializeIOSGamepads()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (*nativeGamepadsImpl) update(gamepads *gamepads) error {
|
2022-02-04 15:29:09 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
type nativeGamepadImpl struct {
|
2022-02-04 15:29:09 +01:00
|
|
|
controller uintptr
|
|
|
|
buttonMask uint16
|
|
|
|
hasDualshockTouchpad bool
|
|
|
|
hasXboxPaddles bool
|
|
|
|
hasXboxShareButton bool
|
|
|
|
|
|
|
|
axes []float64
|
|
|
|
buttons []bool
|
|
|
|
hats []int
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) update(gamepad *gamepads) error {
|
2022-02-04 15:29:09 +01:00
|
|
|
g.updateIOSGamepad()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (*nativeGamepadImpl) hasOwnStandardLayoutMapping() bool {
|
2022-02-04 15:29:09 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-08-11 05:35:20 +02:00
|
|
|
func (*nativeGamepadImpl) isStandardAxisAvailableInOwnMapping(axis gamepaddb.StandardAxis) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*nativeGamepadImpl) isStandardButtonAvailableInOwnMapping(button gamepaddb.StandardButton) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) axisCount() int {
|
2022-02-04 15:29:09 +01:00
|
|
|
return len(g.axes)
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) buttonCount() int {
|
2022-02-04 15:29:09 +01:00
|
|
|
return len(g.buttons)
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) hatCount() int {
|
2022-02-04 15:29:09 +01:00
|
|
|
return len(g.hats)
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) axisValue(axis int) float64 {
|
2022-02-04 15:29:09 +01:00
|
|
|
if axis < 0 || axis >= len(g.axes) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return g.axes[axis]
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) isButtonPressed(button int) bool {
|
2022-02-04 15:29:09 +01:00
|
|
|
if button < 0 || button >= len(g.buttons) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return g.buttons[button]
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (*nativeGamepadImpl) buttonValue(button int) float64 {
|
2022-02-04 15:29:09 +01:00
|
|
|
panic("gamepad: buttonValue is not implemented")
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) hatState(hat int) int {
|
2022-02-04 15:29:09 +01:00
|
|
|
if hat < 0 || hat >= len(g.hats) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return g.hats[hat]
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:03:56 +02:00
|
|
|
func (g *nativeGamepadImpl) vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
|
2022-02-04 15:29:09 +01:00
|
|
|
// TODO: Implement this (#1452)
|
|
|
|
}
|