From d4b722eb0642b5bbfe92bdcbb4b7e223d0c3ff44 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 10 Jan 2022 16:01:57 +0900 Subject: [PATCH] ebiten: rename VibrateOptions.Intensity -> Magnitude Updates #1452 --- internal/driver/ui.go | 2 +- internal/uidriver/glfw/ui.go | 2 +- internal/uidriver/js/ui_js.go | 4 ++-- internal/uidriver/mobile/vibrate_android.go | 10 +++++----- internal/uidriver/mobile/vibrate_ios.go | 5 ++--- vibrate.go | 12 ++++++------ 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/internal/driver/ui.go b/internal/driver/ui.go index 7d87f1fc6..ab2c63a56 100644 --- a/internal/driver/ui.go +++ b/internal/driver/ui.go @@ -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 diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index b03000348..520414969 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -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. } diff --git a/internal/uidriver/js/ui_js.go b/internal/uidriver/js/ui_js.go index 18e41c551..7fe0f2e99 100644 --- a/internal/uidriver/js/ui_js.go +++ b/internal/uidriver/js/ui_js.go @@ -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)) diff --git a/internal/uidriver/mobile/vibrate_android.go b/internal/uidriver/mobile/vibrate_android.go index bdd0b8928..cebe1e03a 100644 --- a/internal/uidriver/mobile/vibrate_android.go +++ b/internal/uidriver/mobile/vibrate_android.go @@ -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 ( // // // -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 }) } diff --git a/internal/uidriver/mobile/vibrate_ios.go b/internal/uidriver/mobile/vibrate_ios.go index 300c9443e..167471386 100644 --- a/internal/uidriver/mobile/vibrate_ios.go +++ b/internal/uidriver/mobile/vibrate_ios.go @@ -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)) } diff --git a/vibrate.go b/vibrate.go index cd45fdf84..6d955bc4c 100644 --- a/vibrate.go +++ b/vibrate.go @@ -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: // // // -// 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.