Partially revert "Revert "Audit uses of IsRunning and GetState""

This reverts the revert commit bc67fc97c3,
except for the changes in BaseConfigLoader.cpp, which caused the bug
that made us revert 72cf2bdb87. PR 12917
contains an improved change to BaseConfigLoader.cpp, which can be merged
(or rejected) independently.

A few changes have also been made based on review comments.
This commit is contained in:
JosJuice
2024-07-02 17:27:04 +02:00
parent 2da3e49b1e
commit 6ca2da53e8
33 changed files with 143 additions and 114 deletions

View File

@ -381,10 +381,16 @@ 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
*/

View File

@ -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)
}
}

View File

@ -20,5 +20,5 @@ class RunRunnable(
override val setting: AbstractSetting? = null
override val isEditable: Boolean
get() = worksDuringEmulation || !NativeLibrary.IsRunning()
get() = worksDuringEmulation || NativeLibrary.IsUninitialized()
}

View File

@ -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
}

View File

@ -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(

View File

@ -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) {

View File

@ -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

View File

@ -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);
}
}
@ -276,13 +275,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()));
}
@ -293,6 +285,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)
{