diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5d1b30a549..78719e31a2 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -62,7 +62,6 @@ add_library( fs/fs_util.h fs/path_util.cpp fs/path_util.h - hash.h heap_tracker.cpp heap_tracker.h hex_util.cpp diff --git a/src/common/android/id_cache.cpp b/src/common/android/id_cache.cpp index 3da532703a..0e1bc07626 100644 --- a/src/common/android/id_cache.cpp +++ b/src/common/android/id_cache.cpp @@ -12,93 +12,94 @@ #include "common/android/multiplayer/multiplayer.h" #include +static struct { + JavaVM *java_vm; + jclass native_library_class; + jclass disk_cache_progress_class; + jclass load_callback_stage_class; + jclass game_dir_class; + jmethodID game_dir_constructor; + jmethodID exit_emulation_activity; + jmethodID disk_cache_load_progress; + jmethodID on_emulation_started; + jmethodID on_emulation_stopped; + jmethodID on_program_changed; + jmethodID copy_to_storage; + jmethodID file_exists; + jmethodID file_extension; -static JavaVM *s_java_vm; -static jclass s_native_library_class; -static jclass s_disk_cache_progress_class; -static jclass s_load_callback_stage_class; -static jclass s_game_dir_class; -static jmethodID s_game_dir_constructor; -static jmethodID s_exit_emulation_activity; -static jmethodID s_disk_cache_load_progress; -static jmethodID s_on_emulation_started; -static jmethodID s_on_emulation_stopped; -static jmethodID s_on_program_changed; -static jmethodID s_copy_to_storage; -static jmethodID s_file_exists; -static jmethodID s_file_extension; + jclass game_class; + jmethodID game_constructor; + jfieldID game_title_field; + jfieldID game_path_field; + jfieldID game_program_id_field; + jfieldID game_developer_field; + jfieldID game_version_field; + jfieldID game_is_homebrew_field; -static jclass s_game_class; -static jmethodID s_game_constructor; -static jfieldID s_game_title_field; -static jfieldID s_game_path_field; -static jfieldID s_game_program_id_field; -static jfieldID s_game_developer_field; -static jfieldID s_game_version_field; -static jfieldID s_game_is_homebrew_field; + jclass string_class; + jclass pair_class; + jmethodID pair_constructor; + jfieldID pair_first_field; + jfieldID pair_second_field; -static jclass s_string_class; -static jclass s_pair_class; -static jmethodID s_pair_constructor; -static jfieldID s_pair_first_field; -static jfieldID s_pair_second_field; + jclass overlay_control_data_class; + jmethodID overlay_control_data_constructor; + jfieldID overlay_control_data_id_field; + jfieldID overlay_control_data_enabled_field; + jfieldID overlay_control_data_individual_scale_field; + jfieldID overlay_control_data_landscape_position_field; + jfieldID overlay_control_data_portrait_position_field; + jfieldID overlay_control_data_foldable_position_field; -static jclass s_overlay_control_data_class; -static jmethodID s_overlay_control_data_constructor; -static jfieldID s_overlay_control_data_id_field; -static jfieldID s_overlay_control_data_enabled_field; -static jfieldID s_overlay_control_data_individual_scale_field; -static jfieldID s_overlay_control_data_landscape_position_field; -static jfieldID s_overlay_control_data_portrait_position_field; -static jfieldID s_overlay_control_data_foldable_position_field; + jclass patch_class; + jmethodID patch_constructor; + jfieldID patch_enabled_field; + jfieldID patch_name_field; + jfieldID patch_version_field; + jfieldID patch_type_field; + jfieldID patch_program_id_field; + jfieldID patch_title_id_field; -static jclass s_patch_class; -static jmethodID s_patch_constructor; -static jfieldID s_patch_enabled_field; -static jfieldID s_patch_name_field; -static jfieldID s_patch_version_field; -static jfieldID s_patch_type_field; -static jfieldID s_patch_program_id_field; -static jfieldID s_patch_title_id_field; + jclass double_class; + jmethodID double_constructor; + jmethodID double_value_method; -static jclass s_double_class; -static jmethodID s_double_constructor; -static jmethodID s_double_value_method; + jclass integer_class; + jmethodID integer_constructor; + jmethodID integer_value_method; -static jclass s_integer_class; -static jmethodID s_integer_constructor; -static jmethodID s_integer_value_method; + jclass boolean_class; + jmethodID boolean_constructor; + jmethodID boolean_value_method; -static jclass s_boolean_class; -static jmethodID s_boolean_constructor; -static jmethodID s_boolean_value_method; + jclass player_input_class; + jmethodID player_input_constructor; + jfieldID player_input_connected_field; + jfieldID player_input_buttons_field; + jfieldID player_input_analogs_field; + jfieldID player_input_motions_field; + jfieldID player_input_vibration_enabled_field; + jfieldID player_input_vibration_strength_field; + jfieldID player_input_body_color_left_field; + jfieldID player_input_body_color_right_field; + jfieldID player_input_button_color_left_field; + jfieldID player_input_button_color_right_field; + jfieldID player_input_profile_name_field; + jfieldID player_input_use_system_vibrator_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; + jclass yuzu_input_device_interface; + jmethodID yuzu_input_device_get_name; + jmethodID yuzu_input_device_get_guid; + jmethodID yuzu_input_device_get_port; + jmethodID yuzu_input_device_get_supports_vibration; + jmethodID yuzu_input_device_vibrate; + jmethodID yuzu_input_device_get_axes; + jmethodID yuzu_input_device_has_keys; -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 jmethodID s_add_netplay_message; -static jmethodID s_clear_chat; + jmethodID add_netplay_message; + jmethodID clear_chat; +} state; static constexpr jint JNI_VERSION = JNI_VERSION_1_6; @@ -123,303 +124,303 @@ namespace Common::Android { } jclass GetNativeLibraryClass() { - return s_native_library_class; + return state.native_library_class; } jclass GetDiskCacheProgressClass() { - return s_disk_cache_progress_class; + return state.disk_cache_progress_class; } jclass GetDiskCacheLoadCallbackStageClass() { - return s_load_callback_stage_class; + return state.load_callback_stage_class; } jclass GetGameDirClass() { - return s_game_dir_class; + return state.game_dir_class; } jmethodID GetGameDirConstructor() { - return s_game_dir_constructor; + return state.game_dir_constructor; } jmethodID GetExitEmulationActivity() { - return s_exit_emulation_activity; + return state.exit_emulation_activity; } jmethodID GetDiskCacheLoadProgress() { - return s_disk_cache_load_progress; + return state.disk_cache_load_progress; } jmethodID GetCopyToStorage() { - return s_copy_to_storage; + return state.copy_to_storage; } jmethodID GetFileExists() { - return s_file_exists; + return state.file_exists; } jmethodID GetFileExtension() { - return s_file_extension; + return state.file_extension; } jmethodID GetOnEmulationStarted() { - return s_on_emulation_started; + return state.on_emulation_started; } jmethodID GetOnEmulationStopped() { - return s_on_emulation_stopped; + return state.on_emulation_stopped; } jmethodID GetOnProgramChanged() { - return s_on_program_changed; + return state.on_program_changed; } jclass GetGameClass() { - return s_game_class; + return state.game_class; } jmethodID GetGameConstructor() { - return s_game_constructor; + return state.game_constructor; } jfieldID GetGameTitleField() { - return s_game_title_field; + return state.game_title_field; } jfieldID GetGamePathField() { - return s_game_path_field; + return state.game_path_field; } jfieldID GetGameProgramIdField() { - return s_game_program_id_field; + return state.game_program_id_field; } jfieldID GetGameDeveloperField() { - return s_game_developer_field; + return state.game_developer_field; } jfieldID GetGameVersionField() { - return s_game_version_field; + return state.game_version_field; } jfieldID GetGameIsHomebrewField() { - return s_game_is_homebrew_field; + return state.game_is_homebrew_field; } jclass GetStringClass() { - return s_string_class; + return state.string_class; } jclass GetPairClass() { - return s_pair_class; + return state.pair_class; } jmethodID GetPairConstructor() { - return s_pair_constructor; + return state.pair_constructor; } jfieldID GetPairFirstField() { - return s_pair_first_field; + return state.pair_first_field; } jfieldID GetPairSecondField() { - return s_pair_second_field; + return state.pair_second_field; } jclass GetOverlayControlDataClass() { - return s_overlay_control_data_class; + return state.overlay_control_data_class; } jmethodID GetOverlayControlDataConstructor() { - return s_overlay_control_data_constructor; + return state.overlay_control_data_constructor; } jfieldID GetOverlayControlDataIdField() { - return s_overlay_control_data_id_field; + return state.overlay_control_data_id_field; } jfieldID GetOverlayControlDataEnabledField() { - return s_overlay_control_data_enabled_field; + return state.overlay_control_data_enabled_field; } jfieldID GetOverlayControlDataIndividualScaleField() { - return s_overlay_control_data_individual_scale_field; + return state.overlay_control_data_individual_scale_field; } jfieldID GetOverlayControlDataLandscapePositionField() { - return s_overlay_control_data_landscape_position_field; + return state.overlay_control_data_landscape_position_field; } jfieldID GetOverlayControlDataPortraitPositionField() { - return s_overlay_control_data_portrait_position_field; + return state.overlay_control_data_portrait_position_field; } jfieldID GetOverlayControlDataFoldablePositionField() { - return s_overlay_control_data_foldable_position_field; + return state.overlay_control_data_foldable_position_field; } jclass GetPatchClass() { - return s_patch_class; + return state.patch_class; } jmethodID GetPatchConstructor() { - return s_patch_constructor; + return state.patch_constructor; } jfieldID GetPatchEnabledField() { - return s_patch_enabled_field; + return state.patch_enabled_field; } jfieldID GetPatchNameField() { - return s_patch_name_field; + return state.patch_name_field; } jfieldID GetPatchVersionField() { - return s_patch_version_field; + return state.patch_version_field; } jfieldID GetPatchTypeField() { - return s_patch_type_field; + return state.patch_type_field; } jfieldID GetPatchProgramIdField() { - return s_patch_program_id_field; + return state.patch_program_id_field; } jfieldID GetPatchTitleIdField() { - return s_patch_title_id_field; + return state.patch_title_id_field; } jclass GetDoubleClass() { - return s_double_class; + return state.double_class; } jmethodID GetDoubleConstructor() { - return s_double_constructor; + return state.double_constructor; } jmethodID GetDoubleValueMethod() { - return s_double_value_method; + return state.double_value_method; } jclass GetIntegerClass() { - return s_integer_class; + return state.integer_class; } jmethodID GetIntegerConstructor() { - return s_integer_constructor; + return state.integer_constructor; } jmethodID GetIntegerValueMethod() { - return s_integer_value_method; + return state.integer_value_method; } jclass GetBooleanClass() { - return s_boolean_class; + return state.boolean_class; } jmethodID GetBooleanConstructor() { - return s_boolean_constructor; + return state.boolean_constructor; } jmethodID GetBooleanValueMethod() { - return s_boolean_value_method; + return state.boolean_value_method; } jclass GetPlayerInputClass() { - return s_player_input_class; + return state.player_input_class; } jmethodID GetPlayerInputConstructor() { - return s_player_input_constructor; + return state.player_input_constructor; } jfieldID GetPlayerInputConnectedField() { - return s_player_input_connected_field; + return state.player_input_connected_field; } jfieldID GetPlayerInputButtonsField() { - return s_player_input_buttons_field; + return state.player_input_buttons_field; } jfieldID GetPlayerInputAnalogsField() { - return s_player_input_analogs_field; + return state.player_input_analogs_field; } jfieldID GetPlayerInputMotionsField() { - return s_player_input_motions_field; + return state.player_input_motions_field; } jfieldID GetPlayerInputVibrationEnabledField() { - return s_player_input_vibration_enabled_field; + return state.player_input_vibration_enabled_field; } jfieldID GetPlayerInputVibrationStrengthField() { - return s_player_input_vibration_strength_field; + return state.player_input_vibration_strength_field; } jfieldID GetPlayerInputBodyColorLeftField() { - return s_player_input_body_color_left_field; + return state.player_input_body_color_left_field; } jfieldID GetPlayerInputBodyColorRightField() { - return s_player_input_body_color_right_field; + return state.player_input_body_color_right_field; } jfieldID GetPlayerInputButtonColorLeftField() { - return s_player_input_button_color_left_field; + return state.player_input_button_color_left_field; } jfieldID GetPlayerInputButtonColorRightField() { - return s_player_input_button_color_right_field; + return state.player_input_button_color_right_field; } jfieldID GetPlayerInputProfileNameField() { - return s_player_input_profile_name_field; + return state.player_input_profile_name_field; } jfieldID GetPlayerInputUseSystemVibratorField() { - return s_player_input_use_system_vibrator_field; + return state.player_input_use_system_vibrator_field; } jclass GetYuzuInputDeviceInterface() { - return s_yuzu_input_device_interface; + return state.yuzu_input_device_interface; } jmethodID GetYuzuDeviceGetName() { - return s_yuzu_input_device_get_name; + return state.yuzu_input_device_get_name; } jmethodID GetYuzuDeviceGetGUID() { - return s_yuzu_input_device_get_guid; + return state.yuzu_input_device_get_guid; } jmethodID GetYuzuDeviceGetPort() { - return s_yuzu_input_device_get_port; + return state.yuzu_input_device_get_port; } jmethodID GetYuzuDeviceGetSupportsVibration() { - return s_yuzu_input_device_get_supports_vibration; + return state.yuzu_input_device_get_supports_vibration; } jmethodID GetYuzuDeviceVibrate() { - return s_yuzu_input_device_vibrate; + return state.yuzu_input_device_vibrate; } jmethodID GetYuzuDeviceGetAxes() { - return s_yuzu_input_device_get_axes; + return state.yuzu_input_device_get_axes; } jmethodID GetYuzuDeviceHasKeys() { - return s_yuzu_input_device_has_keys; + return state.yuzu_input_device_has_keys; } jmethodID GetAddNetPlayMessage() { - return s_add_netplay_message; + return state.add_netplay_message; } jmethodID ClearChat() { - return s_clear_chat; + return state.clear_chat; } #ifdef __cplusplus @@ -436,20 +437,20 @@ namespace Common::Android { // UnInitialize Android Storage Common::FS::Android::UnRegisterCallbacks(); - env->DeleteGlobalRef(s_native_library_class); - env->DeleteGlobalRef(s_disk_cache_progress_class); - env->DeleteGlobalRef(s_load_callback_stage_class); - env->DeleteGlobalRef(s_game_dir_class); - env->DeleteGlobalRef(s_game_class); - env->DeleteGlobalRef(s_string_class); - env->DeleteGlobalRef(s_pair_class); - env->DeleteGlobalRef(s_overlay_control_data_class); - env->DeleteGlobalRef(s_patch_class); - 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); + env->DeleteGlobalRef(state.native_library_class); + env->DeleteGlobalRef(state.disk_cache_progress_class); + env->DeleteGlobalRef(state.load_callback_stage_class); + env->DeleteGlobalRef(state.game_dir_class); + env->DeleteGlobalRef(state.game_class); + env->DeleteGlobalRef(state.string_class); + env->DeleteGlobalRef(state.pair_class); + env->DeleteGlobalRef(state.overlay_control_data_class); + env->DeleteGlobalRef(state.patch_class); + env->DeleteGlobalRef(state.double_class); + env->DeleteGlobalRef(state.integer_class); + env->DeleteGlobalRef(state.boolean_class); + env->DeleteGlobalRef(state.player_input_class); + env->DeleteGlobalRef(state.yuzu_input_device_interface); // UnInitialize applets SoftwareKeyboard::CleanupJNI(env); @@ -463,7 +464,7 @@ namespace Common::Android { #endif void Initialize(JavaVM* vm, JNIEnv *env) { - s_java_vm = vm; + state.java_vm = vm; InitFFmpegOnLoad(vm); if (env->ExceptionCheck()) { @@ -472,169 +473,169 @@ void Initialize(JavaVM* vm, JNIEnv *env) { // Initialize Java classes const jclass native_library_class = env->FindClass("org/yuzu/yuzu_emu/NativeLibrary"); - s_native_library_class = reinterpret_cast(env->NewGlobalRef(native_library_class)); - s_disk_cache_progress_class = reinterpret_cast(env->NewGlobalRef( + state.native_library_class = reinterpret_cast(env->NewGlobalRef(native_library_class)); + state.disk_cache_progress_class = reinterpret_cast(env->NewGlobalRef( env->FindClass("org/yuzu/yuzu_emu/disk_shader_cache/DiskShaderCacheProgress"))); - s_load_callback_stage_class = reinterpret_cast(env->NewGlobalRef(env->FindClass( + state.load_callback_stage_class = reinterpret_cast(env->NewGlobalRef(env->FindClass( "org/yuzu/yuzu_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage"))); const jclass game_dir_class = env->FindClass("org/yuzu/yuzu_emu/model/GameDir"); - s_game_dir_class = reinterpret_cast(env->NewGlobalRef(game_dir_class)); - s_game_dir_constructor = env->GetMethodID(game_dir_class, "", + state.game_dir_class = reinterpret_cast(env->NewGlobalRef(game_dir_class)); + state.game_dir_constructor = env->GetMethodID(game_dir_class, "", "(Ljava/lang/String;Z)V"); env->DeleteLocalRef(game_dir_class); // Initialize methods - s_exit_emulation_activity = - env->GetStaticMethodID(s_native_library_class, "exitEmulationActivity", "(I)V"); - s_disk_cache_load_progress = - env->GetStaticMethodID(s_disk_cache_progress_class, "loadProgress", "(III)V"); - s_copy_to_storage = env->GetStaticMethodID(s_native_library_class, "copyFileToStorage", + state.exit_emulation_activity = + env->GetStaticMethodID(state.native_library_class, "exitEmulationActivity", "(I)V"); + state.disk_cache_load_progress = + env->GetStaticMethodID(state.disk_cache_progress_class, "loadProgress", "(III)V"); + state.copy_to_storage = env->GetStaticMethodID(state.native_library_class, "copyFileToStorage", "(Ljava/lang/String;Ljava/lang/String;)Z"); - s_file_exists = env->GetStaticMethodID(s_native_library_class, "exists", + state.file_exists = env->GetStaticMethodID(state.native_library_class, "exists", "(Ljava/lang/String;)Z"); - s_file_extension = env->GetStaticMethodID(s_native_library_class, "getFileExtension", + state.file_extension = env->GetStaticMethodID(state.native_library_class, "getFileExtension", "(Ljava/lang/String;)Ljava/lang/String;"); - s_on_emulation_started = - env->GetStaticMethodID(s_native_library_class, "onEmulationStarted", "()V"); - s_on_emulation_stopped = - env->GetStaticMethodID(s_native_library_class, "onEmulationStopped", "(I)V"); - s_on_program_changed = - env->GetStaticMethodID(s_native_library_class, "onProgramChanged", "(I)V"); + state.on_emulation_started = + env->GetStaticMethodID(state.native_library_class, "onEmulationStarted", "()V"); + state.on_emulation_stopped = + env->GetStaticMethodID(state.native_library_class, "onEmulationStopped", "(I)V"); + state.on_program_changed = + env->GetStaticMethodID(state.native_library_class, "onProgramChanged", "(I)V"); const jclass game_class = env->FindClass("org/yuzu/yuzu_emu/model/Game"); - s_game_class = reinterpret_cast(env->NewGlobalRef(game_class)); - s_game_constructor = env->GetMethodID(game_class, "", + state.game_class = reinterpret_cast(env->NewGlobalRef(game_class)); + state.game_constructor = env->GetMethodID(game_class, "", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/" "String;Ljava/lang/String;Ljava/lang/String;Z)V"); - s_game_title_field = env->GetFieldID(game_class, "title", "Ljava/lang/String;"); - s_game_path_field = env->GetFieldID(game_class, "path", "Ljava/lang/String;"); - s_game_program_id_field = env->GetFieldID(game_class, "programId", "Ljava/lang/String;"); - s_game_developer_field = env->GetFieldID(game_class, "developer", "Ljava/lang/String;"); - s_game_version_field = env->GetFieldID(game_class, "version", "Ljava/lang/String;"); - s_game_is_homebrew_field = env->GetFieldID(game_class, "isHomebrew", "Z"); + state.game_title_field = env->GetFieldID(game_class, "title", "Ljava/lang/String;"); + state.game_path_field = env->GetFieldID(game_class, "path", "Ljava/lang/String;"); + state.game_program_id_field = env->GetFieldID(game_class, "programId", "Ljava/lang/String;"); + state.game_developer_field = env->GetFieldID(game_class, "developer", "Ljava/lang/String;"); + state.game_version_field = env->GetFieldID(game_class, "version", "Ljava/lang/String;"); + state.game_is_homebrew_field = env->GetFieldID(game_class, "isHomebrew", "Z"); env->DeleteLocalRef(game_class); const jclass string_class = env->FindClass("java/lang/String"); - s_string_class = reinterpret_cast(env->NewGlobalRef(string_class)); + state.string_class = reinterpret_cast(env->NewGlobalRef(string_class)); env->DeleteLocalRef(string_class); const jclass pair_class = env->FindClass("kotlin/Pair"); - s_pair_class = reinterpret_cast(env->NewGlobalRef(pair_class)); - s_pair_constructor = + state.pair_class = reinterpret_cast(env->NewGlobalRef(pair_class)); + state.pair_constructor = env->GetMethodID(pair_class, "", "(Ljava/lang/Object;Ljava/lang/Object;)V"); - s_pair_first_field = env->GetFieldID(pair_class, "first", "Ljava/lang/Object;"); - s_pair_second_field = env->GetFieldID(pair_class, "second", "Ljava/lang/Object;"); + state.pair_first_field = env->GetFieldID(pair_class, "first", "Ljava/lang/Object;"); + state.pair_second_field = env->GetFieldID(pair_class, "second", "Ljava/lang/Object;"); env->DeleteLocalRef(pair_class); const jclass overlay_control_data_class = env->FindClass("org/yuzu/yuzu_emu/overlay/model/OverlayControlData"); - s_overlay_control_data_class = + state.overlay_control_data_class = reinterpret_cast(env->NewGlobalRef(overlay_control_data_class)); - s_overlay_control_data_constructor = + state.overlay_control_data_constructor = env->GetMethodID(overlay_control_data_class, "", "(Ljava/lang/String;ZLkotlin/Pair;Lkotlin/Pair;Lkotlin/Pair;F)V"); - s_overlay_control_data_id_field = + state.overlay_control_data_id_field = env->GetFieldID(overlay_control_data_class, "id", "Ljava/lang/String;"); - s_overlay_control_data_enabled_field = + state.overlay_control_data_enabled_field = env->GetFieldID(overlay_control_data_class, "enabled", "Z"); - s_overlay_control_data_landscape_position_field = + state.overlay_control_data_landscape_position_field = env->GetFieldID(overlay_control_data_class, "landscapePosition", "Lkotlin/Pair;"); - s_overlay_control_data_portrait_position_field = + state.overlay_control_data_portrait_position_field = env->GetFieldID(overlay_control_data_class, "portraitPosition", "Lkotlin/Pair;"); - s_overlay_control_data_foldable_position_field = + state.overlay_control_data_foldable_position_field = env->GetFieldID(overlay_control_data_class, "foldablePosition", "Lkotlin/Pair;"); - s_overlay_control_data_individual_scale_field = + state.overlay_control_data_individual_scale_field = env->GetFieldID(overlay_control_data_class, "individualScale", "F"); env->DeleteLocalRef(overlay_control_data_class); const jclass patch_class = env->FindClass("org/yuzu/yuzu_emu/model/Patch"); - s_patch_class = reinterpret_cast(env->NewGlobalRef(patch_class)); - s_patch_constructor = env->GetMethodID( + state.patch_class = reinterpret_cast(env->NewGlobalRef(patch_class)); + state.patch_constructor = env->GetMethodID( patch_class, "", "(ZLjava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;JI)V"); - s_patch_enabled_field = env->GetFieldID(patch_class, "enabled", "Z"); - s_patch_name_field = env->GetFieldID(patch_class, "name", "Ljava/lang/String;"); - s_patch_version_field = env->GetFieldID(patch_class, "version", "Ljava/lang/String;"); - s_patch_type_field = env->GetFieldID(patch_class, "type", "I"); - s_patch_program_id_field = env->GetFieldID(patch_class, "programId", "Ljava/lang/String;"); - s_patch_title_id_field = env->GetFieldID(patch_class, "titleId", "Ljava/lang/String;"); + state.patch_enabled_field = env->GetFieldID(patch_class, "enabled", "Z"); + state.patch_name_field = env->GetFieldID(patch_class, "name", "Ljava/lang/String;"); + state.patch_version_field = env->GetFieldID(patch_class, "version", "Ljava/lang/String;"); + state.patch_type_field = env->GetFieldID(patch_class, "type", "I"); + state.patch_program_id_field = env->GetFieldID(patch_class, "programId", "Ljava/lang/String;"); + state.patch_title_id_field = env->GetFieldID(patch_class, "titleId", "Ljava/lang/String;"); env->DeleteLocalRef(patch_class); const jclass double_class = env->FindClass("java/lang/Double"); - s_double_class = reinterpret_cast(env->NewGlobalRef(double_class)); - s_double_constructor = env->GetMethodID(double_class, "", "(D)V"); - s_double_value_method = env->GetMethodID(double_class, "doubleValue", "()D"); + state.double_class = reinterpret_cast(env->NewGlobalRef(double_class)); + state.double_constructor = env->GetMethodID(double_class, "", "(D)V"); + state.double_value_method = env->GetMethodID(double_class, "doubleValue", "()D"); env->DeleteLocalRef(double_class); const jclass int_class = env->FindClass("java/lang/Integer"); - s_integer_class = reinterpret_cast(env->NewGlobalRef(int_class)); - s_integer_constructor = env->GetMethodID(int_class, "", "(I)V"); - s_integer_value_method = env->GetMethodID(int_class, "intValue", "()I"); + state.integer_class = reinterpret_cast(env->NewGlobalRef(int_class)); + state.integer_constructor = env->GetMethodID(int_class, "", "(I)V"); + state.integer_value_method = env->GetMethodID(int_class, "intValue", "()I"); env->DeleteLocalRef(int_class); const jclass boolean_class = env->FindClass("java/lang/Boolean"); - s_boolean_class = reinterpret_cast(env->NewGlobalRef(boolean_class)); - s_boolean_constructor = env->GetMethodID(boolean_class, "", "(Z)V"); - s_boolean_value_method = env->GetMethodID(boolean_class, "booleanValue", "()Z"); + state.boolean_class = reinterpret_cast(env->NewGlobalRef(boolean_class)); + state.boolean_constructor = env->GetMethodID(boolean_class, "", "(Z)V"); + state.boolean_value_method = env->GetMethodID(boolean_class, "booleanValue", "()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(env->NewGlobalRef(player_input_class)); - s_player_input_constructor = env->GetMethodID( + state.player_input_class = reinterpret_cast(env->NewGlobalRef(player_input_class)); + state.player_input_constructor = env->GetMethodID( player_input_class, "", "(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 = + state.player_input_connected_field = env->GetFieldID(player_input_class, "connected", "Z"); + state.player_input_buttons_field = env->GetFieldID(player_input_class, "buttons", "[Ljava/lang/String;"); - s_player_input_analogs_field = + state.player_input_analogs_field = env->GetFieldID(player_input_class, "analogs", "[Ljava/lang/String;"); - s_player_input_motions_field = + state.player_input_motions_field = env->GetFieldID(player_input_class, "motions", "[Ljava/lang/String;"); - s_player_input_vibration_enabled_field = + state.player_input_vibration_enabled_field = env->GetFieldID(player_input_class, "vibrationEnabled", "Z"); - s_player_input_vibration_strength_field = + state.player_input_vibration_strength_field = env->GetFieldID(player_input_class, "vibrationStrength", "I"); - s_player_input_body_color_left_field = + state.player_input_body_color_left_field = env->GetFieldID(player_input_class, "bodyColorLeft", "J"); - s_player_input_body_color_right_field = + state.player_input_body_color_right_field = env->GetFieldID(player_input_class, "bodyColorRight", "J"); - s_player_input_button_color_left_field = + state.player_input_button_color_left_field = env->GetFieldID(player_input_class, "buttonColorLeft", "J"); - s_player_input_button_color_right_field = + state.player_input_button_color_right_field = env->GetFieldID(player_input_class, "buttonColorRight", "J"); - s_player_input_profile_name_field = + state.player_input_profile_name_field = env->GetFieldID(player_input_class, "profileName", "Ljava/lang/String;"); - s_player_input_use_system_vibrator_field = + state.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 = + state.yuzu_input_device_interface = reinterpret_cast(env->NewGlobalRef(yuzu_input_device_interface)); - s_yuzu_input_device_get_name = + state.yuzu_input_device_get_name = env->GetMethodID(yuzu_input_device_interface, "getName", "()Ljava/lang/String;"); - s_yuzu_input_device_get_guid = + state.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", + state.yuzu_input_device_get_port = env->GetMethodID(yuzu_input_device_interface, "getPort", "()I"); - s_yuzu_input_device_get_supports_vibration = + state.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", + state.yuzu_input_device_vibrate = env->GetMethodID(yuzu_input_device_interface, "vibrate", "(F)V"); - s_yuzu_input_device_get_axes = + state.yuzu_input_device_get_axes = env->GetMethodID(yuzu_input_device_interface, "getAxes", "()[Ljava/lang/Integer;"); - s_yuzu_input_device_has_keys = + state.yuzu_input_device_has_keys = env->GetMethodID(yuzu_input_device_interface, "hasKeys", "([I)[Z"); env->DeleteLocalRef(yuzu_input_device_interface); - s_add_netplay_message = env->GetStaticMethodID(s_native_library_class, "addNetPlayMessage", + state.add_netplay_message = env->GetStaticMethodID(state.native_library_class, "addNetPlayMessage", "(ILjava/lang/String;)V"); - s_clear_chat = env->GetStaticMethodID(s_native_library_class, "clearChat", "()V"); + state.clear_chat = env->GetStaticMethodID(state.native_library_class, "clearChat", "()V"); // Initialize Android Storage - Common::FS::Android::RegisterCallbacks(env, s_native_library_class); + Common::FS::Android::RegisterCallbacks(env, state.native_library_class); // Initialize applets Common::Android::SoftwareKeyboard::InitJNI(env); diff --git a/src/common/bit_util.h b/src/common/bit_util.h index ce916e6162..9d687f0b7d 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -22,36 +22,22 @@ template return std::size_t(sizeof(T) * CHAR_BIT); } -template - requires std::is_integral_v -[[nodiscard]] constexpr u32 MostSignificantBit(const T value) { - return u32(sizeof(T) * CHAR_BIT - 1 - std::countl_zero(value)); -} - template requires std::is_integral_v [[nodiscard]] constexpr T Log2Floor(const T value) { - return T(MostSignificantBit(value)); + return std::bit_width(value) - 1; } template requires std::is_integral_v [[nodiscard]] constexpr T Log2Ceil(const T value) { - const T log2_f = Log2Floor(value); - return T(log2_f + T((value ^ (T(1ULL) << log2_f)) != T(0ULL))); -} - -template - requires std::is_integral_v -[[nodiscard]] T NextPow2(T value) { - return T(1ULL << (sizeof(T) * CHAR_BIT - std::countl_zero(value - 1U))); + return std::bit_width(value - 1); } template - requires std::is_integral_v + requires (std::is_integral_v && bit_index < BitSize()) [[nodiscard]] constexpr bool Bit(const T value) { - static_assert(bit_index < BitSize(), "bit_index must be smaller than size of T"); - return ((value >> bit_index) & T(1)) == T(1); + return (T(value >> bit_index) & T(1)) == T(1); } } // namespace Common diff --git a/src/common/container_hash.h b/src/common/container_hash.h index d7477f7e4f..46a09a2d59 100644 --- a/src/common/container_hash.h +++ b/src/common/container_hash.h @@ -25,26 +25,18 @@ template requires std::is_unsigned_v inline std::size_t HashValue(T val) { const unsigned int size_t_bits = std::numeric_limits::digits; - const unsigned int length = - (std::numeric_limits::digits - 1) / static_cast(size_t_bits); - + const unsigned int length = (std::numeric_limits::digits - 1) / static_cast(size_t_bits); std::size_t seed = 0; - - for (unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits) { - seed ^= static_cast(val >> i) + (seed << 6) + (seed >> 2); - } - - seed ^= static_cast(val) + (seed << 6) + (seed >> 2); - - return seed; + for (unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits) + seed ^= std::size_t(val >> i) + (seed << 6) + (seed >> 2); + return seed ^= std::size_t(val) + (seed << 6) + (seed >> 2); } template struct HashCombineImpl { template static inline T fn(T seed, T value) { - seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; + return seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2); } }; diff --git a/src/common/div_ceil.h b/src/common/div_ceil.h index c12477d42e..423f032497 100644 --- a/src/common/div_ceil.h +++ b/src/common/div_ceil.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -12,14 +15,14 @@ namespace Common { template requires std::is_integral_v && std::is_unsigned_v [[nodiscard]] constexpr N DivCeil(N number, D divisor) { - return static_cast((static_cast(number) + divisor - 1) / divisor); + return N((D(number) + divisor - 1) / divisor); } /// Ceiled integer division with logarithmic divisor in base 2 template requires std::is_integral_v && std::is_unsigned_v [[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) { - return static_cast((static_cast(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); + return N((D(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); } } // namespace Common diff --git a/src/common/hash.h b/src/common/hash.h deleted file mode 100644 index e8fe78b075..0000000000 --- a/src/common/hash.h +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-FileCopyrightText: 2015 Citra Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include -#include - -namespace Common { - -struct PairHash { - template - std::size_t operator()(const std::pair& pair) const noexcept { - std::size_t seed = std::hash()(pair.first); - boost::hash_combine(seed, std::hash()(pair.second)); - return seed; - } -}; - -template -struct IdentityHash { - [[nodiscard]] size_t operator()(T value) const noexcept { - return static_cast(value); - } -}; - -} // namespace Common diff --git a/src/common/hex_util.h b/src/common/hex_util.h index 2f5417143c..0d413dbc0b 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project // SPDX-FileCopyrightText: 2014 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -16,14 +19,12 @@ namespace Common { [[nodiscard]] constexpr u8 ToHexNibble(char c) { if (c >= 65 && c <= 70) { - return static_cast(c - 55); + return u8(c - 55); } - if (c >= 97 && c <= 102) { - return static_cast(c - 87); + return u8(c - 87); } - - return static_cast(c - 48); + return u8(c - 48); } [[nodiscard]] std::vector HexStringToVector(std::string_view str, bool little_endian); @@ -31,35 +32,29 @@ namespace Common { template [[nodiscard]] constexpr std::array HexStringToArray(std::string_view str) { ASSERT_MSG(Size * 2 <= str.size(), "Invalid string size"); - std::array out{}; if constexpr (le) { for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { - out[i / 2] = static_cast((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); + out[i / 2] = u8((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); } } else { for (std::size_t i = 0; i < 2 * Size; i += 2) { - out[i / 2] = static_cast((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); + out[i / 2] = u8((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); } } return out; } template + requires std::is_same_v [[nodiscard]] std::string HexToString(const ContiguousContainer& data, bool upper = true) { - static_assert(std::is_same_v, - "Underlying type within the contiguous container must be u8."); - - constexpr std::size_t pad_width = 2; - - std::string out; - out.reserve(std::size(data) * pad_width); - - const auto format_str = fmt::runtime(upper ? "{:02X}" : "{:02x}"); - for (const u8 c : data) { - out += fmt::format(format_str, c); + auto const* htbl = upper ? "0123456789ABCDEF" : "0123456789abcdef"; + std::string out(std::size(data) * 2); + for (size_t i = 0; i < std::size(data); ++i) { + auto const c = data[i]; + out[i * 2 + 0] = htbl[(c >> 4) & 0xf]; + out[i * 2 + 1] = htbl[(c >> 0) & 0xf]; } - return out; } diff --git a/src/common/logging.cpp b/src/common/logging.cpp index ed12d52532..79418861c2 100644 --- a/src/common/logging.cpp +++ b/src/common/logging.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #if defined(__ANDROID__) #include @@ -95,9 +96,10 @@ std::string FormatLogMessage(const Entry& entry) noexcept { template Level GetLevelByName(const It begin, const It end) { + std::string_view const sv{begin, end}; for (u32 i = 0; i < u32(Level::Count); ++i) { - const char* level_name = GetLevelName(Level(i)); - if (Common::ComparePartialString(begin, end, level_name)) + auto const level_name = GetLevelName(Level(i)); + if (boost::iequals(sv, level_name)) return Level(i); } return Level::Count; @@ -105,9 +107,10 @@ Level GetLevelByName(const It begin, const It end) { template Class GetClassByName(const It begin, const It end) { + std::string_view const sv{begin, end}; for (u32 i = 0; i < u32(Class::Count); ++i) { - const char* level_name = GetLogClassName(Class(i)); - if (Common::ComparePartialString(begin, end, level_name)) + auto const level_name = GetLogClassName(Class(i)); + if (boost::iequals(sv, level_name)) return Class(i); } return Class::Count; @@ -120,12 +123,13 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: {}", std::string(begin, end)); return false; } - const Level level = GetLevelByName(level_separator + 1, end); + auto const sv = std::string_view{begin, level_separator}; + auto const level = GetLevelByName(level_separator + 1, end); if (level == Level::Count) { LOG_ERROR(Log, "Unknown log level in filter: {}", std::string(begin, end)); return false; } - if (Common::ComparePartialString(begin, level_separator, "*")) { + if (boost::iequals(sv, "*")) { instance.class_levels.fill(level); return true; } diff --git a/src/common/param_package.cpp b/src/common/param_package.cpp index b2803a4fcf..9ebaaf33d5 100644 --- a/src/common/param_package.cpp +++ b/src/common/param_package.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "common/logging.h" #include "common/param_package.h" @@ -15,17 +17,16 @@ namespace Common { -constexpr char KEY_VALUE_SEPARATOR = ':'; -constexpr char PARAM_SEPARATOR = ','; - -constexpr char ESCAPE_CHARACTER = '$'; -constexpr char KEY_VALUE_SEPARATOR_ESCAPE[] = "$0"; -constexpr char PARAM_SEPARATOR_ESCAPE[] = "$1"; -constexpr char ESCAPE_CHARACTER_ESCAPE[] = "$2"; +constexpr auto KEY_VALUE_SEPARATOR = ":"; +constexpr auto PARAM_SEPARATOR = ","; +constexpr auto ESCAPE_CHARACTER = "$"; +constexpr auto KEY_VALUE_SEPARATOR_ESCAPE = "$0"; +constexpr auto PARAM_SEPARATOR_ESCAPE = "$1"; +constexpr auto ESCAPE_CHARACTER_ESCAPE = "$2"; /// A placeholder for empty param packages to avoid empty strings /// (they may be recognized as "not set" by some frontend libraries like qt) -constexpr char EMPTY_PLACEHOLDER[] = "[empty]"; +constexpr auto EMPTY_PLACEHOLDER = "[empty]"; ParamPackage::ParamPackage(const std::string& serialized) { if (serialized == EMPTY_PLACEHOLDER) { @@ -33,20 +34,20 @@ ParamPackage::ParamPackage(const std::string& serialized) { } std::vector pairs; - Common::SplitString(serialized, PARAM_SEPARATOR, pairs); + boost::split(pairs, serialized, PARAM_SEPARATOR); for (const std::string& pair : pairs) { std::vector key_value; - Common::SplitString(pair, KEY_VALUE_SEPARATOR, key_value); + boost::split(key_value, pair, KEY_VALUE_SEPARATOR); if (key_value.size() != 2) { LOG_ERROR(Common, "invalid key pair {}", pair); continue; } - for (std::string& part : key_value) { - part = Common::ReplaceAll(part, KEY_VALUE_SEPARATOR_ESCAPE, {KEY_VALUE_SEPARATOR}); - part = Common::ReplaceAll(part, PARAM_SEPARATOR_ESCAPE, {PARAM_SEPARATOR}); - part = Common::ReplaceAll(part, ESCAPE_CHARACTER_ESCAPE, {ESCAPE_CHARACTER}); + for (auto& part : key_value) { + boost::replace_all(part, KEY_VALUE_SEPARATOR_ESCAPE, KEY_VALUE_SEPARATOR); + boost::replace_all(part, PARAM_SEPARATOR_ESCAPE, PARAM_SEPARATOR); + boost::replace_all(part, ESCAPE_CHARACTER_ESCAPE, ESCAPE_CHARACTER); } Set(key_value[0], std::move(key_value[1])); @@ -63,10 +64,10 @@ std::string ParamPackage::Serialize() const { for (const auto& pair : data) { std::array key_value{{pair.first, pair.second}}; - for (std::string& part : key_value) { - part = Common::ReplaceAll(part, {ESCAPE_CHARACTER}, ESCAPE_CHARACTER_ESCAPE); - part = Common::ReplaceAll(part, {PARAM_SEPARATOR}, PARAM_SEPARATOR_ESCAPE); - part = Common::ReplaceAll(part, {KEY_VALUE_SEPARATOR}, KEY_VALUE_SEPARATOR_ESCAPE); + for (auto& part : key_value) { + boost::replace_all(part, ESCAPE_CHARACTER, ESCAPE_CHARACTER_ESCAPE); + boost::replace_all(part, PARAM_SEPARATOR, PARAM_SEPARATOR_ESCAPE); + boost::replace_all(part, KEY_VALUE_SEPARATOR, KEY_VALUE_SEPARATOR_ESCAPE); } result += key_value[0] + KEY_VALUE_SEPARATOR + key_value[1] + PARAM_SEPARATOR; } diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 9543a62343..5fcab6e7ab 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -24,22 +24,6 @@ namespace Common { -/// Make a string lowercase -std::string ToLower(const std::string_view sv) { - std::string str{sv}; - std::transform(str.begin(), str.end(), str.begin(), - [](auto const c) { return char(std::tolower(c)); }); - return str; -} - -/// Make a string uppercase -std::string ToUpper(const std::string_view sv) { - std::string str{sv}; - std::transform(str.begin(), str.end(), str.begin(), - [](auto const c) { return char(std::toupper(c)); }); - return str; -} - bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension) { if (full_path.empty()) @@ -80,41 +64,6 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ return true; } -void SplitString(const std::string& str, const char delim, std::vector& output) { - std::istringstream iss(str); - output.resize(1); - - while (std::getline(iss, *output.rbegin(), delim)) { - output.emplace_back(); - } - - output.pop_back(); -} - -std::string TabsToSpaces(int tab_size, std::string in) { - std::size_t i = 0; - - while ((i = in.find('\t')) != std::string::npos) { - in.replace(i, 1, tab_size, ' '); - } - - return in; -} - -std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { - std::size_t pos = 0; - - if (src == dest) - return result; - - while ((pos = result.find(src, pos)) != std::string::npos) { - result.replace(pos, src.size(), dest); - pos += dest.length(); - } - - return result; -} - std::string UTF16ToUTF8(std::u16string_view input) { std::wstring_convert, char16_t> convert; return convert.to_bytes(input.data(), input.data() + input.size()); diff --git a/src/common/string_util.h b/src/common/string_util.h index 4358541b14..d7e7c69d27 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project @@ -16,12 +16,6 @@ namespace Common { -/// Make a string lowercase -[[nodiscard]] std::string ToLower(const std::string_view sv); - -/// Make a string uppercase -[[nodiscard]] std::string ToUpper(const std::string_view sv); - [[nodiscard]] inline std::string StringFromBuffer(std::span data) noexcept { return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); } @@ -29,37 +23,8 @@ namespace Common { return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); } -/// Turns " hej " into "hej". Also handles tabs. -[[nodiscard]] inline std::string StripSpaces(const std::string_view str) noexcept { - const std::size_t s = str.find_first_not_of(" \t\r\n"); - if (str.npos != s) - return std::string{str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1)}; - return {}; -} - -/// "\"hello\"" is turned to "hello" -/// This one assumes that the string has already been space stripped in both -/// ends, as done by StripSpaces above, for example. -[[nodiscard]] inline std::string StripQuotes(const std::string_view s) noexcept { - if (s.size() && '\"' == s[0] && '\"' == *s.rbegin()) - return std::string{s.substr(1, s.size() - 2)}; - return std::string{s}; -} - -[[nodiscard]] inline std::string StringFromBool(bool value) noexcept { - return value ? "True" : "False"; -} - -[[nodiscard]] std::string TabsToSpaces(int tab_size, std::string in); - -void SplitString(const std::string& str, char delim, std::vector& output); - // "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe" -bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, - std::string* _pExtension); - -[[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, - const std::string& dest); +bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension); [[nodiscard]] std::string UTF16ToUTF8(std::u16string_view input); [[nodiscard]] std::u16string UTF8ToUTF16(std::string_view input); @@ -73,30 +38,13 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ [[nodiscard]] std::u16string U16StringFromBuffer(const u16* input, std::size_t length); -/** - * Compares the string defined by the range [`begin`, `end`) to the null-terminated C-string - * `other` for equality. - */ -template -[[nodiscard]] inline bool ComparePartialString(InIt begin, InIt end, const char* other) noexcept { - for (; begin != end && *other != '\0'; ++begin, ++other) { - if (*begin != *other) { - return false; - } - } - // Only return true if both strings finished at the same point - return (begin == end) == (*other == '\0'); -} - /// Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't /// NUL-terminated then the string ends at max_len characters. -[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, - std::size_t max_len); +[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len); /// Creates a UTF-16 std::u16string from a fixed-size NUL-terminated char buffer. If the buffer isn't /// null-terminated, then the string ends at the greatest multiple of two less then or equal to /// max_len_bytes. -[[nodiscard]] std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, - std::size_t max_len); +[[nodiscard]] std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, std::size_t max_len); } // namespace Common diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.h b/src/core/arm/dynarmic/arm_dynarmic_64.h index 5ea5dde8a6..7d55cb049b 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.h +++ b/src/core/arm/dynarmic/arm_dynarmic_64.h @@ -13,7 +13,6 @@ #include #include #include "common/common_types.h" -#include "common/hash.h" #include "core/arm/arm_interface.h" #include "core/arm/dynarmic/dynarmic_exclusive_monitor.h" #include "dynarmic/interface/A64/config.h" diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 23d5ac3dfd..f598242ced 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -168,7 +168,7 @@ void CpuManager::ShutdownThread(Kernel::KernelCore& kernel) { UNREACHABLE(); } -void CpuManager::RunThread(std::stop_token token, std::size_t core) { +void CpuManager::RunThread(std::stop_token stop_token, std::size_t core) { /// Initialization system.RegisterCoreThread(core); std::string name = is_multicore ? ("CPUCore_" + std::to_string(core)) : std::string{"CPUThread"}; @@ -178,26 +178,19 @@ void CpuManager::RunThread(std::stop_token token, std::size_t core) { auto& data = core_data[core]; data.host_context = Common::Fiber::ThreadToFiber(); - // Cleanup - SCOPE_EXIT { - data.host_context->Exit(); - }; - // Running - if (!gpu_barrier->Sync(token)) { - return; + gpu_barrier->arrive_and_wait(); + if (!stop_token.stop_requested()) { + if (!is_async_gpu && !is_multicore) { + system.GPU().ObtainContext(); + } + auto& kernel = system.Kernel(); + auto& scheduler = *kernel.CurrentScheduler(); + auto* thread = scheduler.GetSchedulerCurrentThread(); + Kernel::SetCurrentThread(kernel, thread); + Common::Fiber::YieldTo(data.host_context, *thread->GetHostContext()); } - - if (!is_async_gpu && !is_multicore) { - system.GPU().ObtainContext(); - } - - auto& kernel = system.Kernel(); - auto& scheduler = *kernel.CurrentScheduler(); - auto* thread = scheduler.GetSchedulerCurrentThread(); - Kernel::SetCurrentThread(kernel, thread); - - Common::Fiber::YieldTo(data.host_context, *thread->GetHostContext()); + data.host_context->Exit(); } } // namespace Core diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h index 5e97f51bfb..dc070f1f96 100644 --- a/src/core/cpu_manager.h +++ b/src/core/cpu_manager.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -52,7 +53,7 @@ public: } void OnGpuReady() { - gpu_barrier->Sync(); + gpu_barrier->arrive_and_wait(); } void Initialize(); @@ -95,7 +96,7 @@ private: static constexpr std::size_t max_cycle_runs = 5; - std::optional gpu_barrier{}; + std::optional> gpu_barrier{}; struct CoreData { std::shared_ptr host_context; std::jthread host_thread; diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 4c5732a155..2f75029aac 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include "common/fs/file.h" @@ -622,7 +623,7 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti Key128 key = Common::HexStringToArray<16>(out[1]); s128_keys[{S128KeyType::Titlekey, rights_id[1], rights_id[0]}] = key; } else { - out[0] = Common::ToLower(out[0]); + boost::algorithm::to_lower(out[0]); if (const auto iter128 = Find128ByName(out[0]); iter128 != s128_file_id.end()) { const auto& index = iter128->second; const Key128 key = Common::HexStringToArray<16>(out[1]); diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp index 4dd3d34fdc..0a93400a7a 100644 --- a/src/core/crypto/partition_data_manager.cpp +++ b/src/core/crypto/partition_data_manager.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "common/common_funcs.h" #include "common/common_types.h" #include "common/hex_util.h" @@ -41,16 +42,13 @@ static_assert(sizeof(Package2Header) == 0x200, "Package2Header has incorrect siz const u8 PartitionDataManager::MAX_KEYBLOB_SOURCE_HASH = 32; -static FileSys::VirtualFile FindFileInDirWithNames(const FileSys::VirtualDir& dir, - const std::string& name) { - const auto upper = Common::ToUpper(name); - +static FileSys::VirtualFile FindFileInDirWithNames(const FileSys::VirtualDir& dir, const std::string& name) { + const auto upper = boost::algorithm::to_upper_copy(name); for (const auto& fname : {name, name + ".bin", upper, upper + ".BIN"}) { if (dir->GetFile(fname) != nullptr) { return dir->GetFile(fname); } } - return nullptr; } diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 4fd7dc6c71..e27e4a96cc 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "common/assert.h" #include "common/hex_util.h" @@ -73,12 +74,10 @@ VirtualDir FindSubdirectoryCaseless(const VirtualDir dir, std::string_view name) #else const auto subdirs = dir->GetSubdirectories(); for (const auto& subdir : subdirs) { - std::string dir_name = Common::ToLower(subdir->GetName()); - if (dir_name == name) { + if (name == boost::algorithm::to_lower_copy(subdir->GetName())) { return subdir; } } - return nullptr; #endif } diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 1f430434f7..d1da0d9cff 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "common/assert.h" #include "common/fs/path_util.h" @@ -1414,11 +1415,10 @@ void ExternalContentProvider::ScanDirectory(const VirtualDir& dir) { continue; } - const auto extension = Common::ToLower(filename.substr(dot_pos + 1)); - - if (extension == "nsp") { + const auto ext = boost::to_lower_copy(filename.substr(dot_pos + 1)); + if (ext == "nsp") { ProcessNSP(file); - } else if (extension == "xci") { + } else if (ext == "xci") { ProcessXCI(file); } } diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp index 7c5da5e7e3..fcd13d202a 100644 --- a/src/core/file_sys/xts_archive.cpp +++ b/src/core/file_sys/xts_archive.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -63,8 +64,8 @@ NAX::NAX(VirtualFile file_) return; } - const std::string two_dir = Common::ToUpper(std::string{match[1]}); - const std::string nca_id = Common::ToLower(std::string{match[2]}); + const std::string two_dir = boost::algorithm::to_upper_copy(std::string{match[1]}); + const std::string nca_id = boost::algorithm::to_lower_copy(std::string{match[2]}); status = Parse(fmt::format("/registered/{}/{}.nca", two_dir, nca_id)); } diff --git a/src/core/hardware_properties.h b/src/core/hardware_properties.h index 3f870becbf..587ea34fb9 100644 --- a/src/core/hardware_properties.h +++ b/src/core/hardware_properties.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -19,8 +22,14 @@ constexpr u32 NUM_CPU_CORES = 4; // Number of CPU Cores - sync wit // Virtual to Physical core map. constexpr std::array()> VirtualToPhysicalCoreMap{ - 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, + 0, 1, 2, 3, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 3, }; static constexpr inline size_t NumVirtualCores = Common::BitSize(); diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 90e23ccc11..021f14b573 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "common/concepts.h" #include "common/fs/path_util.h" #include "common/logging.h" @@ -170,8 +171,7 @@ FileType GuessFromFilename(const std::string& name) { else if (name == "00") return FileType::NCA; - auto const extension = - Common::ToLower(std::string(Common::FS::GetExtensionFromFilename(name))); + auto const extension = boost::algorithm::to_lower_copy(std::string(Common::FS::GetExtensionFromFilename(name))); if (extension == "nro") return FileType::NRO; else if (extension == "nso") diff --git a/src/dedicated_room/yuzu_room.cpp b/src/dedicated_room/yuzu_room.cpp index 824fd0f26c..f23103eef1 100644 --- a/src/dedicated_room/yuzu_room.cpp +++ b/src/dedicated_room/yuzu_room.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef _WIN32 // windows.h needs to be included before shellapi.h @@ -132,7 +133,7 @@ static Network::Room::BanList LoadBanList(const std::string& path) { std::string line; std::getline(file, line); line.erase(std::remove(line.begin(), line.end(), '\0'), line.end()); - line = Common::StripSpaces(line); + boost::trim(line); if (line.empty()) { // An empty line marks start of the IP ban list ban_list_type = true; diff --git a/src/qt_common/discord/discord_impl.cpp b/src/qt_common/discord/discord_impl.cpp index 666b490347..e0798f4934 100644 --- a/src/qt_common/discord/discord_impl.cpp +++ b/src/qt_common/discord/discord_impl.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include "common/httplib.h" @@ -45,7 +46,7 @@ void DiscordImpl::Pause() { std::string DiscordImpl::GetGameString(const std::string& title) { // Convert to lowercase - std::string icon_name = Common::ToLower(title); + std::string icon_name = boost::algorithm::to_lower_copy(title); // Replace spaces with dashes std::replace(icon_name.begin(), icon_name.end(), ' ', '-'); diff --git a/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp b/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp index d9535c277d..a1ed74180c 100644 --- a/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp +++ b/src/video_core/renderer_opengl/gl_staging_buffer_pool.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project @@ -55,7 +55,7 @@ size_t StagingBuffers::RequestBuffer(size_t requested_size) { } StagingBufferAlloc alloc; alloc.buffer.Create(); - const auto next_pow2_size = Common::NextPow2(requested_size); + const auto next_pow2_size = std::bit_ceil(requested_size); glNamedBufferStorage(alloc.buffer.handle, next_pow2_size, nullptr, storage_flags | GL_MAP_PERSISTENT_BIT); alloc.map = static_cast(glMapNamedBufferRange(alloc.buffer.handle, 0, next_pow2_size, diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 680cb2179f..3635f0124b 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -1404,7 +1404,7 @@ void FormatConversionPass::ConvertImage(Image& dst_image, Image& src_image, const u32 copy_size = region.width * region.height * region.depth * img_bpp; if (pbo_size < copy_size) { intermediate_pbo.Create(); - pbo_size = Common::NextPow2(copy_size); + pbo_size = std::bit_ceil(copy_size); glNamedBufferData(intermediate_pbo.handle, pbo_size, nullptr, GL_STREAM_COPY); } // Copy from source to PBO diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index bc2e82acae..cefddc011c 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -1011,7 +1011,7 @@ VkBuffer TextureCacheRuntime::GetTemporaryBuffer(size_t needed_size) { if (buffers[level]) { return *buffers[level]; } - const auto new_size = Common::NextPow2(needed_size); + const auto new_size = std::bit_ceil(needed_size); static constexpr VkBufferUsageFlags flags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 640bd38407..660aa56d9f 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -2190,7 +2190,7 @@ void TextureCache

::UnregisterImage(ImageId image_id) { image.flags &= ~ImageFlagBits::BadOverlap; lru_cache.Free(image.lru_index); const auto& clear_page_table = - [image_id](u64 page, ::Common::unordered_map, Common::IdentityHash>& selected_page_table) { + [image_id](u64 page, ::Common::unordered_map>& selected_page_table) { const auto page_it = selected_page_table.find(page); if (page_it == selected_page_table.end()) { ASSERT_MSG(false, "Unregistering unregistered page={:#x}", page << YUZU_PAGEBITS); diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 8a2318cc72..304aabc28e 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h @@ -22,7 +22,6 @@ #include #include "common/common_types.h" -#include "common/hash.h" #include "common/literals.h" #include "common/lru_cache.h" #include @@ -69,7 +68,7 @@ struct AsyncDecodeContext { std::atomic_bool complete; }; -using TextureCacheGPUMap = ::Common::unordered_map, Common::IdentityHash>; +using TextureCacheGPUMap = ::Common::unordered_map>; class TextureCacheChannelInfo : public ChannelInfo { public: @@ -443,7 +442,7 @@ private: u64 last_framebuffer_serial = 0; ::Common::unordered_map framebuffers; - ::Common::unordered_map, Common::IdentityHash> page_table; + ::Common::unordered_map> page_table; ::Common::unordered_map> sparse_views; DAddr virtual_invalid_space{};