From 5aa2a4cd1cfc1c708767d6408473de38459ac1f9 Mon Sep 17 00:00:00 2001 From: lynxnb Date: Tue, 12 Jul 2022 12:22:10 +0200 Subject: [PATCH] Rename `SettingsValues` to `NativeSettings` The previous name was chosen as an afterthought and didn't clearly indicate what the purpose of the class is. We needed a separate, simple class without delegates members (like PreferenceSettings), so that its fields can be easily accessed via JNI to get settings values from native code. --- app/src/main/cpp/emu_jni.cpp | 4 ++-- app/src/main/java/emu/skyline/EmulationActivity.kt | 8 ++++---- .../java/emu/skyline/preference/LogLevelPreference.kt | 4 ++-- .../utils/{SettingsValues.kt => NativeSettings.kt} | 9 +++++---- 4 files changed, 13 insertions(+), 12 deletions(-) rename app/src/main/java/emu/skyline/utils/{SettingsValues.kt => NativeSettings.kt} (77%) diff --git a/app/src/main/cpp/emu_jni.cpp b/app/src/main/cpp/emu_jni.cpp index d2d56486..0522db98 100644 --- a/app/src/main/cpp/emu_jni.cpp +++ b/app/src/main/cpp/emu_jni.cpp @@ -231,13 +231,13 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setTouchSta env->ReleaseIntArrayElements(pointsJni, reinterpret_cast(points.data()), JNI_ABORT); } -extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_SettingsValues_updateNative(JNIEnv *env, jobject) { +extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_NativeSettings_updateNative(JNIEnv *env, jobject) { auto settings{SettingsWeak.lock()}; if (!settings) return; // We don't mind if we miss settings updates while settings haven't been initialized settings->Update(); } -extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_SettingsValues_00024Companion_setLogLevel(JNIEnv *, jobject, jint logLevel) { +extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_NativeSettings_00024Companion_setLogLevel(JNIEnv *, jobject, jint logLevel) { skyline::Logger::configLevel = static_cast(logLevel); } diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index 2066ec49..9a071335 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -30,7 +30,7 @@ import emu.skyline.input.* import emu.skyline.loader.getRomFormat import emu.skyline.utils.PreferenceSettings import emu.skyline.utils.ByteBufferSerializable -import emu.skyline.utils.SettingsValues +import emu.skyline.utils.NativeSettings import java.nio.ByteBuffer import java.nio.ByteOrder import java.util.concurrent.FutureTask @@ -85,13 +85,13 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo * @param romUri The URI of the ROM as a string, used to print out in the logs * @param romType The type of the ROM as an enum value * @param romFd The file descriptor of the ROM object - * @param settingsValues The SettingsValues instance + * @param nativeSettings The settings to be used by libskyline * @param publicAppFilesPath The full path to the public app files directory * @param privateAppFilesPath The full path to the private app files directory * @param nativeLibraryPath The full path to the app native library directory * @param assetManager The asset manager used for accessing app assets */ - private external fun executeApplication(romUri : String, romType : Int, romFd : Int, settingsValues : SettingsValues, publicAppFilesPath : String, privateAppFilesPath : String, nativeLibraryPath : String, assetManager : AssetManager) + private external fun executeApplication(romUri : String, romType : Int, romFd : Int, nativeSettings : NativeSettings, publicAppFilesPath : String, privateAppFilesPath : String, nativeLibraryPath : String, assetManager : AssetManager) /** * @param join If the function should only return after all the threads join or immediately @@ -249,7 +249,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo val romFd = contentResolver.openFileDescriptor(rom, "r")!! emulationThread = Thread { - executeApplication(rom.toString(), romType, romFd.detachFd(), SettingsValues(preferenceSettings), applicationContext.getPublicFilesDir().canonicalPath + "/", applicationContext.filesDir.canonicalPath + "/", applicationInfo.nativeLibraryDir + "/", assets) + executeApplication(rom.toString(), romType, romFd.detachFd(), NativeSettings(preferenceSettings), applicationContext.getPublicFilesDir().canonicalPath + "/", applicationContext.filesDir.canonicalPath + "/", applicationInfo.nativeLibraryDir + "/", assets) returnFromEmulation() } diff --git a/app/src/main/java/emu/skyline/preference/LogLevelPreference.kt b/app/src/main/java/emu/skyline/preference/LogLevelPreference.kt index 98f2ac02..42883a15 100644 --- a/app/src/main/java/emu/skyline/preference/LogLevelPreference.kt +++ b/app/src/main/java/emu/skyline/preference/LogLevelPreference.kt @@ -8,12 +8,12 @@ package emu.skyline.preference import android.content.Context import android.util.AttributeSet import androidx.preference.R -import emu.skyline.utils.SettingsValues +import emu.skyline.utils.NativeSettings class LogLevelPreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.dialogPreferenceStyle) : IntegerListPreference(context, attrs, defStyleAttr) { init { setOnPreferenceChangeListener { _, newValue -> - SettingsValues.setLogLevel(newValue as Int) + NativeSettings.setLogLevel(newValue as Int) true } } diff --git a/app/src/main/java/emu/skyline/utils/SettingsValues.kt b/app/src/main/java/emu/skyline/utils/NativeSettings.kt similarity index 77% rename from app/src/main/java/emu/skyline/utils/SettingsValues.kt rename to app/src/main/java/emu/skyline/utils/NativeSettings.kt index d9b2691a..15f52da8 100644 --- a/app/src/main/java/emu/skyline/utils/SettingsValues.kt +++ b/app/src/main/java/emu/skyline/utils/NativeSettings.kt @@ -5,9 +5,10 @@ package emu.skyline.utils -import java.io.Serializable - -class SettingsValues(pref: PreferenceSettings) : Serializable { +/** + * The settings that will be passed to libskyline when running and executable + */ +class NativeSettings(pref: PreferenceSettings) { var isDocked : Boolean = pref.isDocked var usernameValue : String = pref.usernameValue var systemLanguage : Int = pref.systemLanguage @@ -21,7 +22,7 @@ class SettingsValues(pref: PreferenceSettings) : Serializable { companion object { /** - * Setter for native log level + * Sets libskyline logger level to the given one */ external fun setLogLevel(logLevel : Int) }