ebiten: rename VibrateOptions.Intensity -> Magnitude

Updates #1452
This commit is contained in:
Hajime Hoshi 2022-01-10 16:01:57 +09:00
parent edff1f0dd9
commit d4b722eb06
6 changed files with 17 additions and 18 deletions

View File

@ -63,7 +63,7 @@ type UI interface {
SetScreenTransparent(transparent bool)
SetInitFocused(focused bool)
Vibrate(duration time.Duration, intensity float64)
Vibrate(duration time.Duration, magnitude float64)
Input() Input
Window() Window

View File

@ -1625,6 +1625,6 @@ func (u *UserInterface) setOrigPos(x, y int) {
u.origPosY = y
}
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
// Do nothing.
}

View File

@ -653,8 +653,8 @@ func (u *UserInterface) SetInitFocused(focused bool) {
u.initFocused = focused
}
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
// intensity is ignored.
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
// magnitude is ignored.
if js.Global().Get("navigator").Get("vibrate").Truthy() {
js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond))

View File

@ -31,7 +31,7 @@ import (
//
// Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
// if (Build.VERSION.SDK_INT >= 26) {
// v.vibrate(VibrationEffect.createOneShot(milliseconds, intensity * 255))
// v.vibrate(VibrationEffect.createOneShot(milliseconds, magnitude * 255))
// } else {
// v.vibrate(millisecond)
// }
@ -40,7 +40,7 @@ import (
//
// <uses-permission android:name="android.permission.VIBRATE"/>
//
static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, int64_t milliseconds, double intensity) {
static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, int64_t milliseconds, double magnitude) {
JavaVM* vm = (JavaVM*)java_vm;
JNIEnv* env = (JNIEnv*)jni_env;
jobject context = (jobject)ctx;
@ -77,7 +77,7 @@ static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx,
(*env)->CallStaticObjectMethod(
env, android_os_VibrationEffect,
(*env)->GetStaticMethodID(env, android_os_VibrationEffect, "createOneShot", "(JI)Landroid/os/VibrationEffect;"),
milliseconds, (int)(intensity * 255));
milliseconds, (int)(magnitude * 255));
(*env)->CallVoidMethod(
env, vibrator,
@ -104,10 +104,10 @@ static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx,
*/
import "C"
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
_ = app.RunOnJVM(func(vm, env, ctx uintptr) error {
// TODO: This might be crash when this is called from init(). How can we detect this?
C.vibrateOneShot(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), C.int64_t(duration/time.Millisecond), C.double(intensity))
C.vibrateOneShot(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), C.int64_t(duration/time.Millisecond), C.double(magnitude))
return nil
})
}

View File

@ -93,7 +93,6 @@ package mobile
// }
// }
// }
//
import "C"
import (
@ -103,9 +102,9 @@ import (
var vibrationM sync.Mutex
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
vibrationM.Lock()
defer vibrationM.Unlock()
C.vibrate(C.double(float64(duration)/float64(time.Second)), C.double(intensity))
C.vibrate(C.double(float64(duration)/float64(time.Second)), C.double(magnitude))
}

View File

@ -23,23 +23,23 @@ type VibrateOptions struct {
// Duration is the time duration of the effect.
Duration time.Duration
// Intensity is the strength of the device vibration.
// Magnitude is the strength of the device vibration.
// The value is in between 0 and 1.
Intensity float64
Magnitude float64
}
// Vibrate vibrates the device with the specified options.
//
// Vibrate works on mobiles and browsers.
//
// On browsers, Intensity in the options is ignored.
// On browsers, Magnitude in the options is ignored.
//
// On Android, this line is required in the manifest setting to use Vibrate:
//
// <uses-permission android:name="android.permission.VIBRATE"/>
//
// On Android, Intensity in the options is recognized only when the API Level is 26 or newer.
// Otherwise, Intensity is ignored.
// On Android, Magnitude in the options is recognized only when the API Level is 26 or newer.
// Otherwise, Magnitude is ignored.
//
// On iOS, CoreHaptics.framework is required to use Vibrate.
//
@ -48,7 +48,7 @@ type VibrateOptions struct {
//
// Vibrate is concurrent-safe.
func Vibrate(options *VibrateOptions) {
uiDriver().Vibrate(options.Duration, options.Intensity)
uiDriver().Vibrate(options.Duration, options.Magnitude)
}
// VibrateGamepadOptions represents the options for gamepad vibration.