mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-04 20:06:41 +01:00
Android: Speed up game settings saving
Previously would take several seconds to save, sometimes causing ANRs, which was made worse when adding all the controller values. Now we only load/save each section instead of doing it for each setting. Also added a method to save an individual setting.
This commit is contained in:
parent
5d93a10c60
commit
405b37deaa
@ -244,6 +244,10 @@ public final class NativeLibrary
|
|||||||
Rumble.checkRumble(padID, state);
|
Rumble.checkRumble(padID, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static native void LoadGameIniFile(String gameId);
|
||||||
|
|
||||||
|
public static native void SaveGameIniFile(String gameId);
|
||||||
|
|
||||||
public static native String GetUserSetting(String gameID, String Section, String Key);
|
public static native String GetUserSetting(String gameID, String Section, String Key);
|
||||||
|
|
||||||
public static native void SetUserSetting(String gameID, String Section, String Key, String Value);
|
public static native void SetUserSetting(String gameID, String Section, String Key, String Value);
|
||||||
|
@ -443,13 +443,27 @@ public final class SettingsFile
|
|||||||
HashMap<String, Setting> settings = section.getSettings();
|
HashMap<String, Setting> settings = section.getSettings();
|
||||||
Set<String> sortedKeySet = new TreeSet<>(settings.keySet());
|
Set<String> sortedKeySet = new TreeSet<>(settings.keySet());
|
||||||
|
|
||||||
|
// Profile options(wii extension) are not saved, only used to properly display values
|
||||||
|
if (sectionKey.contains(Settings.SECTION_PROFILE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NativeLibrary.LoadGameIniFile(gameId);
|
||||||
|
}
|
||||||
for (String settingKey : sortedKeySet)
|
for (String settingKey : sortedKeySet)
|
||||||
{
|
{
|
||||||
Setting setting = settings.get(settingKey);
|
Setting setting = settings.get(settingKey);
|
||||||
// Special case. Extension gets saved into a controller profile
|
// Special case. Extension gets saved into a controller profile
|
||||||
if (settingKey.contains(SettingsFile.KEY_WIIMOTE_EXTENSION))
|
if (settingKey.contains(SettingsFile.KEY_WIIMOTE_EXTENSION))
|
||||||
{
|
{
|
||||||
saveCustomWiimoteSetting(gameId, setting);
|
String padId =
|
||||||
|
setting.getKey()
|
||||||
|
.substring(setting.getKey().length() - 1, setting.getKey().length());
|
||||||
|
|
||||||
|
saveCustomWiimoteSetting(gameId, KEY_WIIMOTE_EXTENSION, setting.getValueAsString(),
|
||||||
|
padId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -457,30 +471,42 @@ public final class SettingsFile
|
|||||||
setting.getKey(), setting.getValueAsString());
|
setting.getKey(), setting.getValueAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NativeLibrary.SaveGameIniFile(gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void saveSingleCustomSetting(final String gameId, final String section,
|
||||||
|
final String key,
|
||||||
|
final String value)
|
||||||
|
{
|
||||||
|
NativeLibrary.LoadGameIniFile(gameId);
|
||||||
|
NativeLibrary.SetUserSetting(gameId, section,
|
||||||
|
key, value);
|
||||||
|
NativeLibrary.SaveGameIniFile(gameId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the extension value in a profile and enables that profile. Extension is the only
|
* Saves the wiimote setting in a profile and enables that profile.
|
||||||
* controller setting that is not saved in the main config.
|
|
||||||
*
|
*
|
||||||
* @param gameId
|
* @param gameId
|
||||||
* @param setting
|
* @param key
|
||||||
|
* @param value
|
||||||
|
* @param padId
|
||||||
*/
|
*/
|
||||||
public static void saveCustomWiimoteSetting(final String gameId, final Setting setting)
|
public static void saveCustomWiimoteSetting(final String gameId, final String key,
|
||||||
|
final String value,
|
||||||
|
final String padId)
|
||||||
{
|
{
|
||||||
if (setting.getSection().equals(Settings.SECTION_PROFILE))
|
|
||||||
return;
|
|
||||||
String padId =
|
|
||||||
setting.getKey().substring(setting.getKey().length() - 1, setting.getKey().length());
|
|
||||||
String profile = gameId + "_Wii" + padId;
|
String profile = gameId + "_Wii" + padId;
|
||||||
|
|
||||||
NativeLibrary.SetProfileSetting(profile, Settings.SECTION_PROFILE, KEY_WIIMOTE_EXTENSION,
|
NativeLibrary.SetProfileSetting(profile, Settings.SECTION_PROFILE, key,
|
||||||
setting.getValueAsString());
|
value);
|
||||||
|
|
||||||
// Enable the profile
|
// Enable the profile
|
||||||
|
NativeLibrary.LoadGameIniFile(gameId);
|
||||||
NativeLibrary.SetUserSetting(gameId, Settings.SECTION_CONTROLS,
|
NativeLibrary.SetUserSetting(gameId, Settings.SECTION_CONTROLS,
|
||||||
KEY_WIIMOTE_PROFILE + (Integer.valueOf(padId) + 1), profile);
|
KEY_WIIMOTE_PROFILE + (Integer.valueOf(padId) + 1), profile);
|
||||||
|
NativeLibrary.SaveGameIniFile(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String mapSectionNameFromIni(String generalSectionName)
|
private static String mapSectionNameFromIni(String generalSectionName)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
|
#include <UICommon/GameFile.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android/native_window_jni.h>
|
#include <android/native_window_jni.h>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
@ -15,7 +16,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <UICommon/GameFile.h>
|
|
||||||
|
|
||||||
#include "Common/AndroidAnalytics.h"
|
#include "Common/AndroidAnalytics.h"
|
||||||
#include "Common/CPUDetect.h"
|
#include "Common/CPUDetect.h"
|
||||||
@ -61,6 +61,7 @@ namespace
|
|||||||
static constexpr char DOLPHIN_TAG[] = "DolphinEmuNative";
|
static constexpr char DOLPHIN_TAG[] = "DolphinEmuNative";
|
||||||
|
|
||||||
ANativeWindow* s_surf;
|
ANativeWindow* s_surf;
|
||||||
|
IniFile s_ini;
|
||||||
|
|
||||||
// The Core only supports using a single Host thread.
|
// The Core only supports using a single Host thread.
|
||||||
// If multiple threads want to call host functions then they need to queue
|
// If multiple threads want to call host functions then they need to queue
|
||||||
@ -361,27 +362,38 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserSe
|
|||||||
return ToJString(env, value.c_str());
|
return ToJString(env, value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadGameIniFile(JNIEnv* env,
|
||||||
|
jobject obj,
|
||||||
|
jstring jGameID)
|
||||||
|
{
|
||||||
|
std::string gameid = GetJString(env, jGameID);
|
||||||
|
s_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveGameIniFile(JNIEnv* env,
|
||||||
|
jobject obj,
|
||||||
|
jstring jGameID)
|
||||||
|
{
|
||||||
|
std::string gameid = GetJString(env, jGameID);
|
||||||
|
s_ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserSetting(
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserSetting(
|
||||||
JNIEnv* env, jobject obj, jstring jGameID, jstring jSection, jstring jKey, jstring jValue)
|
JNIEnv* env, jobject obj, jstring jGameID, jstring jSection, jstring jKey, jstring jValue)
|
||||||
{
|
{
|
||||||
IniFile ini;
|
|
||||||
std::string gameid = GetJString(env, jGameID);
|
std::string gameid = GetJString(env, jGameID);
|
||||||
std::string section = GetJString(env, jSection);
|
std::string section = GetJString(env, jSection);
|
||||||
std::string key = GetJString(env, jKey);
|
std::string key = GetJString(env, jKey);
|
||||||
std::string val = GetJString(env, jValue);
|
std::string val = GetJString(env, jValue);
|
||||||
|
|
||||||
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
||||||
|
|
||||||
if (val != "-1")
|
if (val != "-1")
|
||||||
{
|
{
|
||||||
ini.GetOrCreateSection(section)->Set(key, val);
|
s_ini.GetOrCreateSection(section)->Set(key, val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ini.GetOrCreateSection(section)->Delete(key);
|
s_ini.GetOrCreateSection(section)->Delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfileSetting(
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfileSetting(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user