diff options
author | t895 <clombardo169@gmail.com> | 2024-02-17 03:19:17 +0100 |
---|---|---|
committer | t895 <clombardo169@gmail.com> | 2024-02-17 18:32:33 +0100 |
commit | 50ecad547ea7e88301583f17c9f1eea2cc75b0af (patch) | |
tree | 21e6a6669ea19d05b389b097c0d411654aba4fbf /src/common | |
parent | hid_core: Prevent crash if we try to iterate through empty color devices list (diff) | |
download | yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.gz yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.bz2 yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.lz yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.xz yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.zst yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/android/id_cache.cpp | 163 | ||||
-rw-r--r-- | src/common/android/id_cache.h | 24 | ||||
-rw-r--r-- | src/common/settings_input.h | 4 |
3 files changed, 191 insertions, 0 deletions
diff --git a/src/common/android/id_cache.cpp b/src/common/android/id_cache.cpp index f39262db9..1145cbdf2 100644 --- a/src/common/android/id_cache.cpp +++ b/src/common/android/id_cache.cpp @@ -65,6 +65,30 @@ static jclass s_boolean_class; static jmethodID s_boolean_constructor; static jfieldID s_boolean_value_field; +static jclass s_player_input_class; +static jmethodID s_player_input_constructor; +static jfieldID s_player_input_connected_field; +static jfieldID s_player_input_buttons_field; +static jfieldID s_player_input_analogs_field; +static jfieldID s_player_input_motions_field; +static jfieldID s_player_input_vibration_enabled_field; +static jfieldID s_player_input_vibration_strength_field; +static jfieldID s_player_input_body_color_left_field; +static jfieldID s_player_input_body_color_right_field; +static jfieldID s_player_input_button_color_left_field; +static jfieldID s_player_input_button_color_right_field; +static jfieldID s_player_input_profile_name_field; +static jfieldID s_player_input_use_system_vibrator_field; + +static jclass s_yuzu_input_device_interface; +static jmethodID s_yuzu_input_device_get_name; +static jmethodID s_yuzu_input_device_get_guid; +static jmethodID s_yuzu_input_device_get_port; +static jmethodID s_yuzu_input_device_get_supports_vibration; +static jmethodID s_yuzu_input_device_vibrate; +static jmethodID s_yuzu_input_device_get_axes; +static jmethodID s_yuzu_input_device_has_keys; + static constexpr jint JNI_VERSION = JNI_VERSION_1_6; namespace Common::Android { @@ -276,6 +300,94 @@ jfieldID GetBooleanValueField() { return s_boolean_value_field; } +jclass GetPlayerInputClass() { + return s_player_input_class; +} + +jmethodID GetPlayerInputConstructor() { + return s_player_input_constructor; +} + +jfieldID GetPlayerInputConnectedField() { + return s_player_input_connected_field; +} + +jfieldID GetPlayerInputButtonsField() { + return s_player_input_buttons_field; +} + +jfieldID GetPlayerInputAnalogsField() { + return s_player_input_analogs_field; +} + +jfieldID GetPlayerInputMotionsField() { + return s_player_input_motions_field; +} + +jfieldID GetPlayerInputVibrationEnabledField() { + return s_player_input_vibration_enabled_field; +} + +jfieldID GetPlayerInputVibrationStrengthField() { + return s_player_input_vibration_strength_field; +} + +jfieldID GetPlayerInputBodyColorLeftField() { + return s_player_input_body_color_left_field; +} + +jfieldID GetPlayerInputBodyColorRightField() { + return s_player_input_body_color_right_field; +} + +jfieldID GetPlayerInputButtonColorLeftField() { + return s_player_input_button_color_left_field; +} + +jfieldID GetPlayerInputButtonColorRightField() { + return s_player_input_button_color_right_field; +} + +jfieldID GetPlayerInputProfileNameField() { + return s_player_input_profile_name_field; +} + +jfieldID GetPlayerInputUseSystemVibratorField() { + return s_player_input_use_system_vibrator_field; +} + +jclass GetYuzuInputDeviceInterface() { + return s_yuzu_input_device_interface; +} + +jmethodID GetYuzuDeviceGetName() { + return s_yuzu_input_device_get_name; +} + +jmethodID GetYuzuDeviceGetGUID() { + return s_yuzu_input_device_get_guid; +} + +jmethodID GetYuzuDeviceGetPort() { + return s_yuzu_input_device_get_port; +} + +jmethodID GetYuzuDeviceGetSupportsVibration() { + return s_yuzu_input_device_get_supports_vibration; +} + +jmethodID GetYuzuDeviceVibrate() { + return s_yuzu_input_device_vibrate; +} + +jmethodID GetYuzuDeviceGetAxes() { + return s_yuzu_input_device_get_axes; +} + +jmethodID GetYuzuDeviceHasKeys() { + return s_yuzu_input_device_has_keys; +} + #ifdef __cplusplus extern "C" { #endif @@ -387,6 +499,55 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) { s_boolean_value_field = env->GetFieldID(boolean_class, "value", "Z"); env->DeleteLocalRef(boolean_class); + const jclass player_input_class = + env->FindClass("org/yuzu/yuzu_emu/features/input/model/PlayerInput"); + s_player_input_class = reinterpret_cast<jclass>(env->NewGlobalRef(player_input_class)); + s_player_input_constructor = env->GetMethodID( + player_input_class, "<init>", + "(Z[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;ZIJJJJLjava/lang/String;Z)V"); + s_player_input_connected_field = env->GetFieldID(player_input_class, "connected", "Z"); + s_player_input_buttons_field = + env->GetFieldID(player_input_class, "buttons", "[Ljava/lang/String;"); + s_player_input_analogs_field = + env->GetFieldID(player_input_class, "analogs", "[Ljava/lang/String;"); + s_player_input_motions_field = + env->GetFieldID(player_input_class, "motions", "[Ljava/lang/String;"); + s_player_input_vibration_enabled_field = + env->GetFieldID(player_input_class, "vibrationEnabled", "Z"); + s_player_input_vibration_strength_field = + env->GetFieldID(player_input_class, "vibrationStrength", "I"); + s_player_input_body_color_left_field = + env->GetFieldID(player_input_class, "bodyColorLeft", "J"); + s_player_input_body_color_right_field = + env->GetFieldID(player_input_class, "bodyColorRight", "J"); + s_player_input_button_color_left_field = + env->GetFieldID(player_input_class, "buttonColorLeft", "J"); + s_player_input_button_color_right_field = + env->GetFieldID(player_input_class, "buttonColorRight", "J"); + s_player_input_profile_name_field = + env->GetFieldID(player_input_class, "profileName", "Ljava/lang/String;"); + s_player_input_use_system_vibrator_field = + env->GetFieldID(player_input_class, "useSystemVibrator", "Z"); + env->DeleteLocalRef(player_input_class); + + const jclass yuzu_input_device_interface = + env->FindClass("org/yuzu/yuzu_emu/features/input/YuzuInputDevice"); + s_yuzu_input_device_interface = + reinterpret_cast<jclass>(env->NewGlobalRef(yuzu_input_device_interface)); + s_yuzu_input_device_get_name = + env->GetMethodID(yuzu_input_device_interface, "getName", "()Ljava/lang/String;"); + s_yuzu_input_device_get_guid = + env->GetMethodID(yuzu_input_device_interface, "getGUID", "()Ljava/lang/String;"); + s_yuzu_input_device_get_port = env->GetMethodID(yuzu_input_device_interface, "getPort", "()I"); + s_yuzu_input_device_get_supports_vibration = + env->GetMethodID(yuzu_input_device_interface, "getSupportsVibration", "()Z"); + s_yuzu_input_device_vibrate = env->GetMethodID(yuzu_input_device_interface, "vibrate", "(F)V"); + s_yuzu_input_device_get_axes = + env->GetMethodID(yuzu_input_device_interface, "getAxes", "()[Ljava/lang/Integer;"); + s_yuzu_input_device_has_keys = + env->GetMethodID(yuzu_input_device_interface, "hasKeys", "([I)[Z"); + env->DeleteLocalRef(yuzu_input_device_interface); + // Initialize Android Storage Common::FS::Android::RegisterCallbacks(env, s_native_library_class); @@ -416,6 +577,8 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) { env->DeleteGlobalRef(s_double_class); env->DeleteGlobalRef(s_integer_class); env->DeleteGlobalRef(s_boolean_class); + env->DeleteGlobalRef(s_player_input_class); + env->DeleteGlobalRef(s_yuzu_input_device_interface); // UnInitialize applets SoftwareKeyboard::CleanupJNI(env); diff --git a/src/common/android/id_cache.h b/src/common/android/id_cache.h index 47802f96c..cd2844dcc 100644 --- a/src/common/android/id_cache.h +++ b/src/common/android/id_cache.h @@ -85,4 +85,28 @@ jclass GetBooleanClass(); jmethodID GetBooleanConstructor(); jfieldID GetBooleanValueField(); +jclass GetPlayerInputClass(); +jmethodID GetPlayerInputConstructor(); +jfieldID GetPlayerInputConnectedField(); +jfieldID GetPlayerInputButtonsField(); +jfieldID GetPlayerInputAnalogsField(); +jfieldID GetPlayerInputMotionsField(); +jfieldID GetPlayerInputVibrationEnabledField(); +jfieldID GetPlayerInputVibrationStrengthField(); +jfieldID GetPlayerInputBodyColorLeftField(); +jfieldID GetPlayerInputBodyColorRightField(); +jfieldID GetPlayerInputButtonColorLeftField(); +jfieldID GetPlayerInputButtonColorRightField(); +jfieldID GetPlayerInputProfileNameField(); +jfieldID GetPlayerInputUseSystemVibratorField(); + +jclass GetYuzuInputDeviceInterface(); +jmethodID GetYuzuDeviceGetName(); +jmethodID GetYuzuDeviceGetGUID(); +jmethodID GetYuzuDeviceGetPort(); +jmethodID GetYuzuDeviceGetSupportsVibration(); +jmethodID GetYuzuDeviceVibrate(); +jmethodID GetYuzuDeviceGetAxes(); +jmethodID GetYuzuDeviceHasKeys(); + } // namespace Common::Android diff --git a/src/common/settings_input.h b/src/common/settings_input.h index 53a95ef8f..a99bb0892 100644 --- a/src/common/settings_input.h +++ b/src/common/settings_input.h @@ -395,6 +395,10 @@ struct PlayerInput { u32 button_color_left; u32 button_color_right; std::string profile_name; + + // This is meant to tell the Android frontend whether to use a device's built-in vibration + // motor or a controller's vibrations. + bool use_system_vibrator; }; struct TouchscreenInput { |