Merge pull request #13594 from jordan-woyak/state-cleanups

State: Simplify interthread communication and general cleanups.
This commit is contained in:
Jordan Woyak
2026-02-03 16:50:52 -06:00
committed by GitHub
14 changed files with 581 additions and 373 deletions

View File

@@ -233,19 +233,17 @@ object NativeLibrary {
* Saves a game state to the slot number.
*
* @param slot The slot location to save state to.
* @param wait If false, returns as early as possible. If true, returns once the savestate has been written to disk.
*/
@JvmStatic
external fun SaveState(slot: Int, wait: Boolean)
external fun SaveState(slot: Int)
/**
* Saves a game state to the specified path.
*
* @param path The path to save state to.
* @param wait If false, returns as early as possible. If true, returns once the savestate has been written to disk.
*/
@JvmStatic
external fun SaveStateAs(path: String, wait: Boolean)
external fun SaveStateAs(path: String)
/**
* Loads a game state from the slot number.

View File

@@ -494,16 +494,16 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
}
MENU_ACTION_TAKE_SCREENSHOT -> NativeLibrary.SaveScreenShot()
MENU_ACTION_QUICK_SAVE -> NativeLibrary.SaveState(9, false)
MENU_ACTION_QUICK_SAVE -> NativeLibrary.SaveState(9)
MENU_ACTION_QUICK_LOAD -> NativeLibrary.LoadState(9)
MENU_ACTION_SAVE_ROOT -> showSubMenu(SaveOrLoad.SAVE)
MENU_ACTION_LOAD_ROOT -> showSubMenu(SaveOrLoad.LOAD)
MENU_ACTION_SAVE_SLOT1 -> NativeLibrary.SaveState(0, false)
MENU_ACTION_SAVE_SLOT2 -> NativeLibrary.SaveState(1, false)
MENU_ACTION_SAVE_SLOT3 -> NativeLibrary.SaveState(2, false)
MENU_ACTION_SAVE_SLOT4 -> NativeLibrary.SaveState(3, false)
MENU_ACTION_SAVE_SLOT5 -> NativeLibrary.SaveState(4, false)
MENU_ACTION_SAVE_SLOT6 -> NativeLibrary.SaveState(5, false)
MENU_ACTION_SAVE_SLOT1 -> NativeLibrary.SaveState(0)
MENU_ACTION_SAVE_SLOT2 -> NativeLibrary.SaveState(1)
MENU_ACTION_SAVE_SLOT3 -> NativeLibrary.SaveState(2)
MENU_ACTION_SAVE_SLOT4 -> NativeLibrary.SaveState(3)
MENU_ACTION_SAVE_SLOT5 -> NativeLibrary.SaveState(4)
MENU_ACTION_SAVE_SLOT6 -> NativeLibrary.SaveState(5)
MENU_ACTION_LOAD_SLOT1 -> NativeLibrary.LoadState(0)
MENU_ACTION_LOAD_SLOT2 -> NativeLibrary.LoadState(1)
MENU_ACTION_LOAD_SLOT3 -> NativeLibrary.LoadState(2)

View File

@@ -232,7 +232,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
}
}
fun saveTemporaryState() = NativeLibrary.SaveStateAs(temporaryStateFilePath, true)
fun saveTemporaryState() = NativeLibrary.SaveStateAs(temporaryStateFilePath)
private val temporaryStateFilePath: String
get() = "${requireContext().filesDir}${File.separator}temp.sav"

View File

@@ -56,10 +56,21 @@ class ActivityTracker : ActivityLifecycleCallbacks {
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
override fun onActivityPostSaveInstanceState(activity: Activity, bundle: Bundle) {
if (DirectoryInitialization.areDolphinDirectoriesReady() &&
!activity.isChangingConfigurations
) {
flushUnsavedData()
}
}
override fun onActivityDestroyed(activity: Activity) {}
companion object {
@JvmStatic
external fun setBackgroundExecutionAllowedNative(allowed: Boolean)
@JvmStatic
external fun flushUnsavedData()
}
}