summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar t8952024-02-16 21:19:17 -0500
committerGravatar t8952024-02-17 12:32:33 -0500
commit50ecad547ea7e88301583f17c9f1eea2cc75b0af (patch)
tree21e6a6669ea19d05b389b097c0d411654aba4fbf /src/common
parenthid_core: Prevent crash if we try to iterate through empty color devices list (diff)
downloadyuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.gz
yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.tar.xz
yuzu-50ecad547ea7e88301583f17c9f1eea2cc75b0af.zip
android: Input mapping
Diffstat (limited to 'src/common')
-rw-r--r--src/common/android/id_cache.cpp163
-rw-r--r--src/common/android/id_cache.h24
-rw-r--r--src/common/settings_input.h4
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;
65static jmethodID s_boolean_constructor; 65static jmethodID s_boolean_constructor;
66static jfieldID s_boolean_value_field; 66static jfieldID s_boolean_value_field;
67 67
68static jclass s_player_input_class;
69static jmethodID s_player_input_constructor;
70static jfieldID s_player_input_connected_field;
71static jfieldID s_player_input_buttons_field;
72static jfieldID s_player_input_analogs_field;
73static jfieldID s_player_input_motions_field;
74static jfieldID s_player_input_vibration_enabled_field;
75static jfieldID s_player_input_vibration_strength_field;
76static jfieldID s_player_input_body_color_left_field;
77static jfieldID s_player_input_body_color_right_field;
78static jfieldID s_player_input_button_color_left_field;
79static jfieldID s_player_input_button_color_right_field;
80static jfieldID s_player_input_profile_name_field;
81static jfieldID s_player_input_use_system_vibrator_field;
82
83static jclass s_yuzu_input_device_interface;
84static jmethodID s_yuzu_input_device_get_name;
85static jmethodID s_yuzu_input_device_get_guid;
86static jmethodID s_yuzu_input_device_get_port;
87static jmethodID s_yuzu_input_device_get_supports_vibration;
88static jmethodID s_yuzu_input_device_vibrate;
89static jmethodID s_yuzu_input_device_get_axes;
90static jmethodID s_yuzu_input_device_has_keys;
91
68static constexpr jint JNI_VERSION = JNI_VERSION_1_6; 92static constexpr jint JNI_VERSION = JNI_VERSION_1_6;
69 93
70namespace Common::Android { 94namespace Common::Android {
@@ -276,6 +300,94 @@ jfieldID GetBooleanValueField() {
276 return s_boolean_value_field; 300 return s_boolean_value_field;
277} 301}
278 302
303jclass GetPlayerInputClass() {
304 return s_player_input_class;
305}
306
307jmethodID GetPlayerInputConstructor() {
308 return s_player_input_constructor;
309}
310
311jfieldID GetPlayerInputConnectedField() {
312 return s_player_input_connected_field;
313}
314
315jfieldID GetPlayerInputButtonsField() {
316 return s_player_input_buttons_field;
317}
318
319jfieldID GetPlayerInputAnalogsField() {
320 return s_player_input_analogs_field;
321}
322
323jfieldID GetPlayerInputMotionsField() {
324 return s_player_input_motions_field;
325}
326
327jfieldID GetPlayerInputVibrationEnabledField() {
328 return s_player_input_vibration_enabled_field;
329}
330
331jfieldID GetPlayerInputVibrationStrengthField() {
332 return s_player_input_vibration_strength_field;
333}
334
335jfieldID GetPlayerInputBodyColorLeftField() {
336 return s_player_input_body_color_left_field;
337}
338
339jfieldID GetPlayerInputBodyColorRightField() {
340 return s_player_input_body_color_right_field;
341}
342
343jfieldID GetPlayerInputButtonColorLeftField() {
344 return s_player_input_button_color_left_field;
345}
346
347jfieldID GetPlayerInputButtonColorRightField() {
348 return s_player_input_button_color_right_field;
349}
350
351jfieldID GetPlayerInputProfileNameField() {
352 return s_player_input_profile_name_field;
353}
354
355jfieldID GetPlayerInputUseSystemVibratorField() {
356 return s_player_input_use_system_vibrator_field;
357}
358
359jclass GetYuzuInputDeviceInterface() {
360 return s_yuzu_input_device_interface;
361}
362
363jmethodID GetYuzuDeviceGetName() {
364 return s_yuzu_input_device_get_name;
365}
366
367jmethodID GetYuzuDeviceGetGUID() {
368 return s_yuzu_input_device_get_guid;
369}
370
371jmethodID GetYuzuDeviceGetPort() {
372 return s_yuzu_input_device_get_port;
373}
374
375jmethodID GetYuzuDeviceGetSupportsVibration() {
376 return s_yuzu_input_device_get_supports_vibration;
377}
378
379jmethodID GetYuzuDeviceVibrate() {
380 return s_yuzu_input_device_vibrate;
381}
382
383jmethodID GetYuzuDeviceGetAxes() {
384 return s_yuzu_input_device_get_axes;
385}
386
387jmethodID GetYuzuDeviceHasKeys() {
388 return s_yuzu_input_device_has_keys;
389}
390
279#ifdef __cplusplus 391#ifdef __cplusplus
280extern "C" { 392extern "C" {
281#endif 393#endif
@@ -387,6 +499,55 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
387 s_boolean_value_field = env->GetFieldID(boolean_class, "value", "Z"); 499 s_boolean_value_field = env->GetFieldID(boolean_class, "value", "Z");
388 env->DeleteLocalRef(boolean_class); 500 env->DeleteLocalRef(boolean_class);
389 501
502 const jclass player_input_class =
503 env->FindClass("org/yuzu/yuzu_emu/features/input/model/PlayerInput");
504 s_player_input_class = reinterpret_cast<jclass>(env->NewGlobalRef(player_input_class));
505 s_player_input_constructor = env->GetMethodID(
506 player_input_class, "<init>",
507 "(Z[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;ZIJJJJLjava/lang/String;Z)V");
508 s_player_input_connected_field = env->GetFieldID(player_input_class, "connected", "Z");
509 s_player_input_buttons_field =
510 env->GetFieldID(player_input_class, "buttons", "[Ljava/lang/String;");
511 s_player_input_analogs_field =
512 env->GetFieldID(player_input_class, "analogs", "[Ljava/lang/String;");
513 s_player_input_motions_field =
514 env->GetFieldID(player_input_class, "motions", "[Ljava/lang/String;");
515 s_player_input_vibration_enabled_field =
516 env->GetFieldID(player_input_class, "vibrationEnabled", "Z");
517 s_player_input_vibration_strength_field =
518 env->GetFieldID(player_input_class, "vibrationStrength", "I");
519 s_player_input_body_color_left_field =
520 env->GetFieldID(player_input_class, "bodyColorLeft", "J");
521 s_player_input_body_color_right_field =
522 env->GetFieldID(player_input_class, "bodyColorRight", "J");
523 s_player_input_button_color_left_field =
524 env->GetFieldID(player_input_class, "buttonColorLeft", "J");
525 s_player_input_button_color_right_field =
526 env->GetFieldID(player_input_class, "buttonColorRight", "J");
527 s_player_input_profile_name_field =
528 env->GetFieldID(player_input_class, "profileName", "Ljava/lang/String;");
529 s_player_input_use_system_vibrator_field =
530 env->GetFieldID(player_input_class, "useSystemVibrator", "Z");
531 env->DeleteLocalRef(player_input_class);
532
533 const jclass yuzu_input_device_interface =
534 env->FindClass("org/yuzu/yuzu_emu/features/input/YuzuInputDevice");
535 s_yuzu_input_device_interface =
536 reinterpret_cast<jclass>(env->NewGlobalRef(yuzu_input_device_interface));
537 s_yuzu_input_device_get_name =
538 env->GetMethodID(yuzu_input_device_interface, "getName", "()Ljava/lang/String;");
539 s_yuzu_input_device_get_guid =
540 env->GetMethodID(yuzu_input_device_interface, "getGUID", "()Ljava/lang/String;");
541 s_yuzu_input_device_get_port = env->GetMethodID(yuzu_input_device_interface, "getPort", "()I");
542 s_yuzu_input_device_get_supports_vibration =
543 env->GetMethodID(yuzu_input_device_interface, "getSupportsVibration", "()Z");
544 s_yuzu_input_device_vibrate = env->GetMethodID(yuzu_input_device_interface, "vibrate", "(F)V");
545 s_yuzu_input_device_get_axes =
546 env->GetMethodID(yuzu_input_device_interface, "getAxes", "()[Ljava/lang/Integer;");
547 s_yuzu_input_device_has_keys =
548 env->GetMethodID(yuzu_input_device_interface, "hasKeys", "([I)[Z");
549 env->DeleteLocalRef(yuzu_input_device_interface);
550
390 // Initialize Android Storage 551 // Initialize Android Storage
391 Common::FS::Android::RegisterCallbacks(env, s_native_library_class); 552 Common::FS::Android::RegisterCallbacks(env, s_native_library_class);
392 553
@@ -416,6 +577,8 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) {
416 env->DeleteGlobalRef(s_double_class); 577 env->DeleteGlobalRef(s_double_class);
417 env->DeleteGlobalRef(s_integer_class); 578 env->DeleteGlobalRef(s_integer_class);
418 env->DeleteGlobalRef(s_boolean_class); 579 env->DeleteGlobalRef(s_boolean_class);
580 env->DeleteGlobalRef(s_player_input_class);
581 env->DeleteGlobalRef(s_yuzu_input_device_interface);
419 582
420 // UnInitialize applets 583 // UnInitialize applets
421 SoftwareKeyboard::CleanupJNI(env); 584 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();
85jmethodID GetBooleanConstructor(); 85jmethodID GetBooleanConstructor();
86jfieldID GetBooleanValueField(); 86jfieldID GetBooleanValueField();
87 87
88jclass GetPlayerInputClass();
89jmethodID GetPlayerInputConstructor();
90jfieldID GetPlayerInputConnectedField();
91jfieldID GetPlayerInputButtonsField();
92jfieldID GetPlayerInputAnalogsField();
93jfieldID GetPlayerInputMotionsField();
94jfieldID GetPlayerInputVibrationEnabledField();
95jfieldID GetPlayerInputVibrationStrengthField();
96jfieldID GetPlayerInputBodyColorLeftField();
97jfieldID GetPlayerInputBodyColorRightField();
98jfieldID GetPlayerInputButtonColorLeftField();
99jfieldID GetPlayerInputButtonColorRightField();
100jfieldID GetPlayerInputProfileNameField();
101jfieldID GetPlayerInputUseSystemVibratorField();
102
103jclass GetYuzuInputDeviceInterface();
104jmethodID GetYuzuDeviceGetName();
105jmethodID GetYuzuDeviceGetGUID();
106jmethodID GetYuzuDeviceGetPort();
107jmethodID GetYuzuDeviceGetSupportsVibration();
108jmethodID GetYuzuDeviceVibrate();
109jmethodID GetYuzuDeviceGetAxes();
110jmethodID GetYuzuDeviceHasKeys();
111
88} // namespace Common::Android 112} // 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 {
395 u32 button_color_left; 395 u32 button_color_left;
396 u32 button_color_right; 396 u32 button_color_right;
397 std::string profile_name; 397 std::string profile_name;
398
399 // This is meant to tell the Android frontend whether to use a device's built-in vibration
400 // motor or a controller's vibrations.
401 bool use_system_vibrator;
398}; 402};
399 403
400struct TouchscreenInput { 404struct TouchscreenInput {