From ce6042fe9de23c7dbf80ae21b6cfce0d44cefbfe Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 18 Oct 2021 05:14:07 +1030 Subject: [PATCH] [Android] Fix up accessing settings in bridge --- Source/Android/Bridge/UISettings.cpp | 29 ++--- Source/Android/Bridge/UISettings.h | 38 +++--- Source/Android/Bridge/jniBridge.cpp | 92 ++++--------- Source/Android/Bridge/jniBridgeSettings.cpp | 135 +++++++++++++++++++- Source/Android/Bridge/jniBridgeSettings.h | 24 ++-- 5 files changed, 209 insertions(+), 109 deletions(-) diff --git a/Source/Android/Bridge/UISettings.cpp b/Source/Android/Bridge/UISettings.cpp index 58b5a9dbd..a4978ee2f 100644 --- a/Source/Android/Bridge/UISettings.cpp +++ b/Source/Android/Bridge/UISettings.cpp @@ -3,25 +3,24 @@ #include #include #include +#include +#include #include "UISettings.h" void RegisterUISettings(void) { - g_Settings->AddHandler((SettingID)(FirstUISettings + Asserts_Version), new CSettingTypeApplication("Settings", "Asserts Version", (uint32_t)0)); - g_Settings->AddHandler((SettingID)(FirstUISettings + Screen_Orientation), new CSettingTypeApplication("Settings", "Screen Orientation", (uint32_t)0)); - g_Settings->AddHandler((SettingID)(FirstUISettings + File_RecentGameFileCount), new CSettingTypeApplication("Settings", "Remembered ROM Files", (uint32_t)10)); - g_Settings->AddHandler((SettingID)(FirstUISettings + File_RecentGameFileIndex), new CSettingTypeApplicationIndex("Recent File", "Recent ROM", Default_None)); - g_Settings->AddHandler((SettingID)(FirstUISettings + TouchScreen_ButtonScale), new CSettingTypeApplication("Touch Screen", "Button Scale", (uint32_t)100)); - g_Settings->AddHandler((SettingID)(FirstUISettings + TouchScreen_Layout), new CSettingTypeApplication("Touch Screen", "Layout", "Analog")); - g_Settings->AddHandler((SettingID)(FirstUISettings + Controller_ConfigFile), new CSettingTypeRelativePath("Config", "Controller.cfg")); - g_Settings->AddHandler((SettingID)(FirstUISettings + Controller_CurrentProfile), new CSettingTypeApplication("Controller", "Profile", "User")); - g_Settings->AddHandler((SettingID)(FirstUISettings + Controller_Deadzone), new CSettingTypeApplication("Controller", "Deadzone", (uint32_t)0)); - g_Settings->AddHandler((SettingID)(FirstUISettings + Controller_Sensitivity), new CSettingTypeApplication("Controller", "Sensitivity", (uint32_t)100)); - g_Settings->AddHandler((SettingID)(FirstUISettings + SupportWindow_FirstRun), new CSettingTypeApplication("Support Project64", "First Run", "")); - g_Settings->AddHandler((SettingID)(FirstUISettings + SupportWindow_AlwaysShow), new CSettingTypeApplication("Support Project64", "Always Show", false)); - g_Settings->AddHandler((SettingID)(FirstUISettings + SupportWindow_ShowingSupportWindow), new CSettingTypeApplication("Support Project64", "Showing Support Window", false)); - g_Settings->AddHandler((SettingID)(FirstUISettings + SupportWindow_RunCount), new CSettingTypeApplication("Support Project64", "Run Count", (uint32_t)0)); - g_Settings->AddHandler((SettingID)(FirstUISettings + Game_RunCount), new CSettingTypeGame("Run Count", (uint32_t)0)); + g_Settings->AddHandler((SettingID)AssertsVersion, new CSettingTypeApplication("Settings", "Asserts Version", (uint32_t)0)); + g_Settings->AddHandler((SettingID)BuildVersion, new CSettingTypeTempNumber(VERSION_BUILD)); + g_Settings->AddHandler((SettingID)ScreenOrientation, new CSettingTypeApplication("Settings", "Screen Orientation", (uint32_t)0)); + g_Settings->AddHandler((SettingID)FileRecentGameFileCount, new CSettingTypeApplication("Settings", "Remembered ROM Files", (uint32_t)10)); + g_Settings->AddHandler((SettingID)FileRecentGameFileIndex, new CSettingTypeApplicationIndex("Recent File", "Recent ROM", Default_None)); + g_Settings->AddHandler((SettingID)TouchScreenButtonScale, new CSettingTypeApplication("Touch Screen", "Button Scale", (uint32_t)100)); + g_Settings->AddHandler((SettingID)TouchScreenLayout, new CSettingTypeApplication("Touch Screen", "Layout", "Analog")); + g_Settings->AddHandler((SettingID)ControllerConfigFile, new CSettingTypeRelativePath("Config", "Controller.cfg")); + g_Settings->AddHandler((SettingID)ControllerCurrentProfile, new CSettingTypeApplication("Controller", "Profile", "User")); + g_Settings->AddHandler((SettingID)ControllerDeadzone, new CSettingTypeApplication("Controller", "Deadzone", (uint32_t)0)); + g_Settings->AddHandler((SettingID)ControllerSensitivity, new CSettingTypeApplication("Controller", "Sensitivity", (uint32_t)100)); + g_Settings->AddHandler((SettingID)AppInfoRunCount, new CSettingTypeGame("Run Count", (uint32_t)0)); } void UISettingsSaveBool(UISettingID Type, bool Value) diff --git a/Source/Android/Bridge/UISettings.h b/Source/Android/Bridge/UISettings.h index 933777e6f..222178d3b 100644 --- a/Source/Android/Bridge/UISettings.h +++ b/Source/Android/Bridge/UISettings.h @@ -1,34 +1,32 @@ #pragma once #include #include +#include enum UISettingID { - Asserts_Version, - Screen_Orientation, + StartUISetting = SettingID::FirstUISettings, - // Recent game - File_RecentGameFileCount, - File_RecentGameFileIndex, + AssertsVersion, + BuildVersion, + ScreenOrientation, - // Touch screen - TouchScreen_ButtonScale, - TouchScreen_Layout, + //Recent Game + FileRecentGameFileCount, + FileRecentGameFileIndex, - // Controller config - Controller_ConfigFile, - Controller_CurrentProfile, - Controller_Deadzone, - Controller_Sensitivity, + //Touch Screen + TouchScreenButtonScale, + TouchScreenLayout, - // Support window - SupportWindow_FirstRun, - SupportWindow_AlwaysShow, - SupportWindow_ShowingSupportWindow, - SupportWindow_RunCount, + //Controller Config + ControllerConfigFile, + ControllerCurrentProfile, + ControllerDeadzone, + ControllerSensitivity, - // Game settings - Game_RunCount, + //App Info + AppInfoRunCount, }; void RegisterUISettings(void); diff --git a/Source/Android/Bridge/jniBridge.cpp b/Source/Android/Bridge/jniBridge.cpp index 5f098db5c..7275014bc 100644 --- a/Source/Android/Bridge/jniBridge.cpp +++ b/Source/Android/Bridge/jniBridge.cpp @@ -1,17 +1,13 @@ #include #ifdef ANDROID -#include -#include -#include +#include #endif #include #include #include #include -#include #include #include -#include #include #include #include @@ -90,28 +86,18 @@ EXPORT jint CALL JNI_OnLoad(JavaVM* vm, void* reserved) return JNI_VERSION_1_4; } -std::string UISettingsLoadStringIndex(UISettingID Type, int32_t index) -{ - return g_Settings->LoadStringIndex((SettingID)(FirstUISettings + Type), index); -} - -void UISettingsSaveStringIndex(UISettingID Type, int32_t index, const std::string & Value) -{ - g_Settings->SaveStringIndex((SettingID)(FirstUISettings + Type), index, Value); -} - void AddRecentRom(const char * ImagePath) { if (ImagePath == NULL) { return; } WriteTrace(TraceUserInterface, TraceDebug, "Start (ImagePath: %s)", ImagePath); // Get information about the stored ROM list - size_t MaxRememberedFiles = UISettingsLoadDword(File_RecentGameFileCount); + size_t MaxRememberedFiles = g_Settings->LoadDword((SettingID)FileRecentGameFileCount); strlist RecentGames; size_t i; for (i = 0; i < MaxRememberedFiles; i++) { - stdstr RecentGame = UISettingsLoadStringIndex(File_RecentGameFileIndex, i); + stdstr RecentGame = g_Settings->LoadStringIndex((SettingID)FileRecentGameFileIndex, i); if (RecentGame.empty()) { break; @@ -138,7 +124,7 @@ void AddRecentRom(const char * ImagePath) for (i = 0, iter = RecentGames.begin(); iter != RecentGames.end(); iter++, i++) { - UISettingsSaveStringIndex(File_RecentGameFileIndex, i, *iter); + g_Settings->SaveStringIndex((SettingID)FileRecentGameFileIndex, i, *iter); } if (g_JavaBridge) @@ -164,9 +150,9 @@ void GameCpuRunning(void * /*NotUsed*/) } g_System->RefreshGameSettings(); - int RunCount = UISettingsLoadDword(Game_RunCount); - WriteTrace(TraceUserInterface, TraceDebug, "Setting run count to %d", RunCount + 1); - UISettingsSaveDword(Game_RunCount, RunCount + 1); + //int RunCount = UISettingsLoadDword(Game_RunCount); + //WriteTrace(TraceUserInterface, TraceDebug, "Setting run count to %d", RunCount + 1); + //UISettingsSaveDword(Game_RunCount, RunCount + 1); if (env != NULL) { if (g_JavaBridge) @@ -348,9 +334,28 @@ EXPORT jstring CALL Java_emu_project64_jni_NativeExports_SettingsLoadString(JNIE return env->NewStringUTF(""); } +EXPORT jstring CALL Java_emu_project64_jni_NativeExports_SettingsLoadStringIndex(JNIEnv* env, jclass cls, jstring Type, int32_t Index) +{ + const char * szType = env->GetStringUTFChars(Type, 0); + SettingID Id = JniBridegSettings->TranslateSettingID(szType); + env->ReleaseStringUTFChars(Type, szType); + if (Id != Default_None) + { + return env->NewStringUTF(g_Settings->LoadStringIndex(Id,Index).c_str()); + } + return env->NewStringUTF(""); +} + EXPORT jboolean CALL Java_emu_project64_jni_NativeExports_IsSettingSet(JNIEnv* env, jclass cls, jstring Type) { - return g_Settings->IsSettingSet((SettingID)Type); + const char * szType = env->GetStringUTFChars(Type, 0); + SettingID Id = JniBridegSettings->TranslateSettingID(szType); + env->ReleaseStringUTFChars(Type, szType); + if (Id != Default_None) + { + return g_Settings->IsSettingSet(Id); + } + return false; } EXPORT void CALL Java_emu_project64_jni_NativeExports_LoadRomList(JNIEnv* env, jclass cls) @@ -518,49 +523,6 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_onSurfaceChanged(JNIEnv * WriteTrace(TraceUserInterface, TraceDebug, "Done"); } -EXPORT void CALL Java_emu_project64_jni_NativeExports_UISettingsSaveBool(JNIEnv* env, jclass cls, jint Type, jboolean Value) -{ - WriteTrace(TraceUserInterface, TraceDebug, "Saving UI %d value: %s", Type, Value ? "true" : "false"); - UISettingsSaveBool((UISettingID)Type, Value); - WriteTrace(TraceUserInterface, TraceDebug, "Saved"); -} - -EXPORT void CALL Java_emu_project64_jni_NativeExports_UISettingsSaveDword(JNIEnv* env, jclass cls, jint Type, jint Value) -{ - WriteTrace(TraceUserInterface, TraceDebug, "Saving UI %d value: %X", Type, Value); - UISettingsSaveDword((UISettingID)Type, Value); - WriteTrace(TraceUserInterface, TraceDebug, "Saved"); -} - -EXPORT void CALL Java_emu_project64_jni_NativeExports_UISettingsSaveString(JNIEnv* env, jclass cls, jint Type, jstring Buffer) -{ - const char *value = env->GetStringUTFChars(Buffer, 0); - WriteTrace(TraceUserInterface, TraceDebug, "Saving UI %d value: %s", Type, value); - UISettingsSaveString((UISettingID)Type, value); - WriteTrace(TraceUserInterface, TraceDebug, "Saved"); - env->ReleaseStringUTFChars(Buffer, value); -} - -EXPORT jboolean CALL Java_emu_project64_jni_NativeExports_UISettingsLoadBool(JNIEnv* env, jclass cls, jint Type) -{ - return UISettingsLoadBool((UISettingID)Type); -} - -EXPORT int CALL Java_emu_project64_jni_NativeExports_UISettingsLoadDword(JNIEnv* env, jclass cls, jint Type) -{ - return UISettingsLoadDword((UISettingID)Type); -} - -EXPORT jstring CALL Java_emu_project64_jni_NativeExports_UISettingsLoadString(JNIEnv* env, jclass cls, int Type) -{ - return env->NewStringUTF(UISettingsLoadStringVal((UISettingID)Type).c_str()); -} - -EXPORT jstring CALL Java_emu_project64_jni_NativeExports_UISettingsLoadStringIndex(JNIEnv* env, jclass cls, jint Type, jint Index) -{ - return env->NewStringUTF(UISettingsLoadStringIndex((UISettingID)Type, Index).c_str()); -} - EXPORT void CALL Java_emu_project64_jni_NativeExports_StopEmulation(JNIEnv* env, jclass cls) { WriteTrace(TraceUserInterface, TraceDebug, "Start"); diff --git a/Source/Android/Bridge/jniBridgeSettings.cpp b/Source/Android/Bridge/jniBridgeSettings.cpp index 789062b33..5869b0763 100644 --- a/Source/Android/Bridge/jniBridgeSettings.cpp +++ b/Source/Android/Bridge/jniBridgeSettings.cpp @@ -1,5 +1,10 @@ #include "jniBridgeSettings.h" +#include "UISettings.h" #include +#include +#ifdef ANDROID +#include +#endif int CJniBridegSettings::m_RefCount = 0; bool CJniBridegSettings::m_bCPURunning; @@ -13,7 +18,9 @@ CJniBridegSettings::CJniBridegSettings() RefreshSettings(NULL); } -#define ADD_SETTING(ID) m_SettingNameList.insert(SettingNameList::value_type(#ID,ID)); +#define ADD_SETTING(ID) m_SettingNameList.insert(SettingNameList::value_type("Core." #ID,ID)); +#define ADD_UI_SETTING(ID) m_SettingNameList.insert(SettingNameList::value_type("UISettingID." #ID,(SettingID)ID)); +#define ADD_VIDEO_SETTING(ID) m_SettingNameList.insert(SettingNameList::value_type("VideoSettingID." #ID,(SettingID)(FirstGfxSettings + ID))); ADD_SETTING(Cmd_BaseDirectory); ADD_SETTING(Cmd_RomFile); @@ -331,6 +338,132 @@ CJniBridegSettings::CJniBridegSettings() ADD_SETTING(Logging_LogCache); ADD_SETTING(Logging_LogRomHeader); ADD_SETTING(Logging_LogUnknown); + + ADD_UI_SETTING(AssertsVersion); + ADD_UI_SETTING(BuildVersion); + ADD_UI_SETTING(ScreenOrientation); + + //Recent Game + ADD_UI_SETTING(FileRecentGameFileCount); + ADD_UI_SETTING(FileRecentGameFileIndex); + + //Touch Screen + ADD_UI_SETTING(TouchScreenButtonScale); + ADD_UI_SETTING(TouchScreenLayout); + + //Controller Config + ADD_UI_SETTING(ControllerConfigFile); + ADD_UI_SETTING(ControllerCurrentProfile); + ADD_UI_SETTING(ControllerDeadzone); + ADD_UI_SETTING(ControllerSensitivity); + + //App Info + ADD_UI_SETTING(AppInfoRunCount); + + // General Settings + ADD_VIDEO_SETTING(Set_vsync); + ADD_VIDEO_SETTING(Set_Rotate); + ADD_VIDEO_SETTING(Set_texenh_options); + ADD_VIDEO_SETTING(Set_wrpVRAM); + ADD_VIDEO_SETTING(Set_wrpFBO); + ADD_VIDEO_SETTING(Set_wrpAnisotropic); + ADD_VIDEO_SETTING(Set_autodetect_ucode); + ADD_VIDEO_SETTING(Set_ucode); + ADD_VIDEO_SETTING(Set_wireframe); + ADD_VIDEO_SETTING(Set_wfmode); + ADD_VIDEO_SETTING(Set_ghq_fltr); + ADD_VIDEO_SETTING(Set_ghq_cmpr); + ADD_VIDEO_SETTING(Set_ghq_enht); + ADD_VIDEO_SETTING(Set_ghq_hirs); + ADD_VIDEO_SETTING(Set_ghq_enht_cmpr); + ADD_VIDEO_SETTING(Set_ghq_enht_f16bpp); + ADD_VIDEO_SETTING(Set_ghq_enht_gz); + ADD_VIDEO_SETTING(Set_ghq_enht_nobg); + ADD_VIDEO_SETTING(Set_ghq_hirs_cmpr); + ADD_VIDEO_SETTING(Set_ghq_hirs_tile); + ADD_VIDEO_SETTING(Set_ghq_hirs_f16bpp); + ADD_VIDEO_SETTING(Set_ghq_hirs_gz); + ADD_VIDEO_SETTING(Set_ghq_hirs_altcrc); + ADD_VIDEO_SETTING(Set_ghq_cache_save); + ADD_VIDEO_SETTING(Set_ghq_cache_size); + ADD_VIDEO_SETTING(Set_ghq_hirs_let_texartists_fly); + ADD_VIDEO_SETTING(Set_ghq_hirs_dump); + ADD_VIDEO_SETTING(Set_Resolution); + + // Default Game Settings + ADD_VIDEO_SETTING(Set_optimize_texrect_default); + ADD_VIDEO_SETTING(Set_filtering_default); + ADD_VIDEO_SETTING(Set_lodmode_default); + ADD_VIDEO_SETTING(Set_fog_default); + ADD_VIDEO_SETTING(Set_buff_clear_default); + ADD_VIDEO_SETTING(Set_swapmode_default); + ADD_VIDEO_SETTING(Set_aspect_default); + ADD_VIDEO_SETTING(Set_fb_smart_default); + ADD_VIDEO_SETTING(Set_fb_hires_default); + ADD_VIDEO_SETTING(Set_fb_read_always_default); + ADD_VIDEO_SETTING(Set_read_back_to_screen_default); + ADD_VIDEO_SETTING(Set_detect_cpu_write_default); + ADD_VIDEO_SETTING(Set_fb_get_info_default); + ADD_VIDEO_SETTING(Set_fb_render_default); + + //Game Settings + ADD_VIDEO_SETTING(Set_alt_tex_size); + ADD_VIDEO_SETTING(Set_use_sts1_only); + ADD_VIDEO_SETTING(Set_force_calc_sphere); + ADD_VIDEO_SETTING(Set_correct_viewport); + ADD_VIDEO_SETTING(Set_increase_texrect_edge); + ADD_VIDEO_SETTING(Set_decrease_fillrect_edge); + ADD_VIDEO_SETTING(Set_texture_correction); + ADD_VIDEO_SETTING(Set_pal230); + ADD_VIDEO_SETTING(Set_stipple_mode); + ADD_VIDEO_SETTING(Set_stipple_pattern); + ADD_VIDEO_SETTING(Set_force_microcheck); + ADD_VIDEO_SETTING(Set_force_quad3d); + ADD_VIDEO_SETTING(Set_clip_zmin); + ADD_VIDEO_SETTING(Set_clip_zmax); + ADD_VIDEO_SETTING(Set_fast_crc); + ADD_VIDEO_SETTING(Set_adjust_aspect); + ADD_VIDEO_SETTING(Set_zmode_compare_less); + ADD_VIDEO_SETTING(Set_old_style_adither); + ADD_VIDEO_SETTING(Set_n64_z_scale); + ADD_VIDEO_SETTING(Set_optimize_texrect); + ADD_VIDEO_SETTING(Set_ignore_aux_copy); + ADD_VIDEO_SETTING(Set_hires_buf_clear); + ADD_VIDEO_SETTING(Set_fb_read_alpha); + ADD_VIDEO_SETTING(Set_useless_is_useless); + ADD_VIDEO_SETTING(Set_fb_crc_mode); + ADD_VIDEO_SETTING(Set_filtering); + ADD_VIDEO_SETTING(Set_fog); + ADD_VIDEO_SETTING(Set_buff_clear); + ADD_VIDEO_SETTING(Set_swapmode); + ADD_VIDEO_SETTING(Set_aspect); + ADD_VIDEO_SETTING(Set_lodmode); + ADD_VIDEO_SETTING(Set_fb_smart); + ADD_VIDEO_SETTING(Set_fb_hires); + ADD_VIDEO_SETTING(Set_fb_read_always); + ADD_VIDEO_SETTING(Set_read_back_to_screen); + ADD_VIDEO_SETTING(Set_detect_cpu_write); + ADD_VIDEO_SETTING(Set_fb_get_info); + ADD_VIDEO_SETTING(Set_fb_render); + + //RDB Setting + ADD_VIDEO_SETTING(Set_ucodeLookup); + + //Logging Settings + ADD_VIDEO_SETTING(Set_Logging_MD5); + ADD_VIDEO_SETTING(Set_Logging_Thread); + ADD_VIDEO_SETTING(Set_Logging_Path); + ADD_VIDEO_SETTING(Set_Logging_Settings); + ADD_VIDEO_SETTING(Set_Logging_Unknown); + ADD_VIDEO_SETTING(Set_Logging_Glide64); + ADD_VIDEO_SETTING(Set_Logging_Interface); + ADD_VIDEO_SETTING(Set_Logging_Resolution); + ADD_VIDEO_SETTING(Set_Logging_Glitch); + ADD_VIDEO_SETTING(Set_Logging_VideoRDP); + ADD_VIDEO_SETTING(Set_Logging_TLUT); + ADD_VIDEO_SETTING(Set_Logging_PNG); + ADD_VIDEO_SETTING(Set_Logging_OGLWrapper); + ADD_VIDEO_SETTING(Set_Logging_RDPCommands); } CJniBridegSettings::~CJniBridegSettings() diff --git a/Source/Android/Bridge/jniBridgeSettings.h b/Source/Android/Bridge/jniBridgeSettings.h index bc00d7411..b34fc0347 100644 --- a/Source/Android/Bridge/jniBridgeSettings.h +++ b/Source/Android/Bridge/jniBridgeSettings.h @@ -1,17 +1,25 @@ #pragma once +#include +#include +#include class CJniBridegSettings { + typedef std::map SettingNameList; + public: - CJniBridegSettings(); - ~CJniBridegSettings(); - - static inline bool bCPURunning ( void) { return m_bCPURunning; } + CJniBridegSettings(); + ~CJniBridegSettings(); + + SettingID TranslateSettingID(const char * SettingName); + static inline bool bCPURunning ( void) { return m_bCPURunning; } private: - static void RefreshSettings (void *); + SettingNameList m_SettingNameList; - static bool m_bCPURunning; - - static int m_RefCount; + static void RefreshSettings (void *); + + static bool m_bCPURunning; + + static int m_RefCount; };