diff options
| author | JosJuice <josjuice@gmail.com> | 2024-06-02 16:45:30 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2024-06-21 20:52:55 +0200 |
| commit | 72cf2bdb87f09deff22e1085de3290126aa4ad05 (patch) | |
| tree | a3c399edfaa7ee17bf9b08cf95f2862a5d8edff9 /Source/Android | |
| parent | 962230f91e06a60b2395de6f0974fdd213854d4c (diff) | |
Audit uses of IsRunning and GetState
Some pieces of code are calling IsRunning because there's some
particular action that only makes sense when emulation is running, for
instance showing the state of the emulated CPU. IsRunning is appropriate
to use for this. Then there are pieces of code that are calling
IsRunning because there's some particular thing they must avoid doing
e.g. when the CPU thread is running or IOS is running. IsRunning isn't
quite appropriate for this. Such code should also be checking for the
states Starting and Stopping. Keep in mind that:
* When the state is Starting, the state can asynchronously change to
Running at any time.
* When we try to stop the core, the state gets set to Stopping before we
take any action to actually stop things.
This commit adds a new method Core::IsUninitialized, and changes all
callers of IsRunning and GetState that look to me like they should be
changed.
Diffstat (limited to 'Source/Android')
8 files changed, 26 insertions, 21 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 43880bd0ba..1cdd9fa473 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -381,11 +381,17 @@ public final class NativeLibrary */ public static native boolean IsRunning(); - public static native boolean IsRunningAndStarted(); - + /** + * Returns true if emulation is running and not paused. + */ public static native boolean IsRunningAndUnpaused(); /** + * Returns true if emulation is fully shut down. + */ + public static native boolean IsUninitialized(); + + /** * Writes out the JitBlock Cache log dump */ public static native void WriteJitBlockLogDump(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt index c5c1851e5d..eedc1405ff 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.kt @@ -36,7 +36,7 @@ class Settings : Closeable { if (isGameSpecific) { // Loading game INIs while the core is running will mess with the game INIs loaded by the core - check(!NativeLibrary.IsRunning()) { "Attempted to load game INI while emulating" } + check(NativeLibrary.IsUninitialized()) { "Attempted to load game INI while emulating" } NativeConfig.loadGameInis(gameId, revision) } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.kt index f9d5786e22..c52964ff0b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RunRunnable.kt @@ -20,5 +20,5 @@ class RunRunnable( override val setting: AbstractSetting? = null override val isEditable: Boolean - get() = worksDuringEmulation || !NativeLibrary.IsRunning() + get() = worksDuringEmulation || NativeLibrary.IsUninitialized() } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.kt index 3209400ff6..01c4796e68 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SettingsItem.kt @@ -54,7 +54,7 @@ abstract class SettingsItem { open val isEditable: Boolean get() { - if (!NativeLibrary.IsRunning()) return true + if (NativeLibrary.IsUninitialized()) return true val setting = setting return setting != null && setting.isRuntimeEditable } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt index 6de39ed1e9..1573b6408c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt @@ -69,7 +69,7 @@ class SettingsFragmentPresenter( } else if ( menuTag == MenuTag.GRAPHICS && this.gameId.isNullOrEmpty() - && !NativeLibrary.IsRunning() + && NativeLibrary.IsUninitialized() && GpuDriverHelper.supportsCustomDriverLoading() ) { this.gpuDriver = @@ -1303,7 +1303,7 @@ class SettingsFragmentPresenter( if ( this.gpuDriver != null && this.gameId.isNullOrEmpty() - && !NativeLibrary.IsRunning() + && NativeLibrary.IsUninitialized() && GpuDriverHelper.supportsCustomDriverLoading() ) { sl.add( diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt index 637f4fb924..eeb223c3db 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt @@ -180,11 +180,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { private fun run(isActivityRecreated: Boolean) { if (isActivityRecreated) { - if (NativeLibrary.IsRunning()) { + if (NativeLibrary.IsUninitialized()) { + loadPreviousTemporaryState = true + } else { loadPreviousTemporaryState = false deleteFile(temporaryStateFilePath) - } else { - loadPreviousTemporaryState = true } } else { Log.debug("[EmulationFragment] activity resumed or fresh start") @@ -203,7 +203,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { private fun runWithValidSurface() { runWhenSurfaceIsValid = false - if (!NativeLibrary.IsRunning()) { + if (NativeLibrary.IsUninitialized()) { NativeLibrary.SetIsBooting() val emulationThread = Thread({ if (loadPreviousTemporaryState) { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.kt index dfe557e712..7964cc1ebc 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.kt @@ -83,7 +83,7 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex fun initTouchPointer() { // Check if we have all the data we need yet - val aspectRatioAvailable = NativeLibrary.IsRunningAndStarted() + val aspectRatioAvailable = NativeLibrary.IsRunning() if (!aspectRatioAvailable || surfacePosition == null) return diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 66a0694a94..8febc6f633 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -118,8 +118,7 @@ void Host_Message(HostMessageID id) } else if (id == HostMessageID::WMUserStop) { - if (Core::IsRunning(Core::System::GetInstance())) - Core::QueueHostJob(&Core::Stop); + Core::QueueHostJob(&Core::Stop); } } @@ -272,13 +271,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetIsBooting JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass) { - return s_is_booting.IsSet() || - static_cast<jboolean>(Core::IsRunning(Core::System::GetInstance())); -} - -JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*, - jclass) -{ return static_cast<jboolean>(Core::IsRunning(Core::System::GetInstance())); } @@ -288,6 +280,13 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndUnpaused(JNIEnv*, jclas return static_cast<jboolean>(Core::GetState(Core::System::GetInstance()) == Core::State::Running); } +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsUninitialized(JNIEnv*, + jclass) +{ + return static_cast<jboolean>(Core::IsUninitialized(Core::System::GetInstance()) && + !s_is_booting.IsSet()); +} + JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, jclass) { |
