mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 13:49:53 -06:00
Optionally delete savestate that gets loaded at boot
This commit is contained in:
@ -343,7 +343,7 @@ public final class NativeLibrary
|
|||||||
/**
|
/**
|
||||||
* Begins emulation from the specified savestate.
|
* Begins emulation from the specified savestate.
|
||||||
*/
|
*/
|
||||||
public static native void Run(String path, String savestatePath);
|
public static native void Run(String path, String savestatePath, boolean deleteSavestate);
|
||||||
|
|
||||||
// Surface Handling
|
// Surface Handling
|
||||||
public static native void SurfaceChanged(Surface surf);
|
public static native void SurfaceChanged(Surface surf);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "ButtonManager.h"
|
#include "ButtonManager.h"
|
||||||
|
|
||||||
@ -482,8 +483,8 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env,
|
|||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
|
||||||
JNIEnv* env, jobject obj, jstring jFile);
|
JNIEnv* env, jobject obj, jstring jFile);
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2(
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
|
||||||
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate);
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate);
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
||||||
jobject obj,
|
jobject obj,
|
||||||
jobject surf);
|
jobject surf);
|
||||||
@ -805,7 +806,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimo
|
|||||||
WiimoteReal::Refresh();
|
WiimoteReal::Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Run(const std::string& path, std::optional<std::string> savestate_path = {})
|
static void Run(const std::string& path, std::optional<std::string> savestate_path = {},
|
||||||
|
bool delete_savestate = false)
|
||||||
{
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", path.c_str());
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", path.c_str());
|
||||||
|
|
||||||
@ -823,7 +825,9 @@ static void Run(const std::string& path, std::optional<std::string> savestate_pa
|
|||||||
|
|
||||||
// No use running the loop when booting fails
|
// No use running the loop when booting fails
|
||||||
s_have_wm_user_stop = false;
|
s_have_wm_user_stop = false;
|
||||||
if (BootManager::BootCore(BootParameters::GenerateFromFile(path, savestate_path)))
|
std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(path, savestate_path);
|
||||||
|
boot->delete_savestate = delete_savestate;
|
||||||
|
if (BootManager::BootCore(std::move(boot)))
|
||||||
{
|
{
|
||||||
static constexpr int TIMEOUT = 10000;
|
static constexpr int TIMEOUT = 10000;
|
||||||
static constexpr int WAIT_STEP = 25;
|
static constexpr int WAIT_STEP = 25;
|
||||||
@ -861,10 +865,10 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_l
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2(
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
|
||||||
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate)
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate)
|
||||||
{
|
{
|
||||||
Run(GetJString(env, jFile), GetJString(env, jSavestate));
|
Run(GetJString(env, jFile), GetJString(env, jSavestate), jDeleteSavestate);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -76,6 +76,7 @@ struct BootParameters
|
|||||||
|
|
||||||
Parameters parameters;
|
Parameters parameters;
|
||||||
std::optional<std::string> savestate_path;
|
std::optional<std::string> savestate_path;
|
||||||
|
bool delete_savestate = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBoot
|
class CBoot
|
||||||
|
@ -318,7 +318,7 @@ static void CPUSetInitialExecutionState()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the CPU thread, which is a CPU + Video thread in Single Core mode.
|
// Create the CPU thread, which is a CPU + Video thread in Single Core mode.
|
||||||
static void CpuThread(const std::optional<std::string>& savestate_path)
|
static void CpuThread(const std::optional<std::string>& savestate_path, bool delete_savestate)
|
||||||
{
|
{
|
||||||
DeclareAsCPUThread();
|
DeclareAsCPUThread();
|
||||||
|
|
||||||
@ -342,7 +342,13 @@ static void CpuThread(const std::optional<std::string>& savestate_path)
|
|||||||
EMM::InstallExceptionHandler(); // Let's run under memory watch
|
EMM::InstallExceptionHandler(); // Let's run under memory watch
|
||||||
|
|
||||||
if (savestate_path)
|
if (savestate_path)
|
||||||
QueueHostJob([&savestate_path] { ::State::LoadAs(*savestate_path); });
|
{
|
||||||
|
QueueHostJob([&savestate_path, delete_savestate] {
|
||||||
|
::State::LoadAs(*savestate_path);
|
||||||
|
if (delete_savestate)
|
||||||
|
File::Delete(*savestate_path);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
s_is_started = true;
|
s_is_started = true;
|
||||||
CPUSetInitialExecutionState();
|
CPUSetInitialExecutionState();
|
||||||
@ -380,7 +386,8 @@ static void CpuThread(const std::optional<std::string>& savestate_path)
|
|||||||
EMM::UninstallExceptionHandler();
|
EMM::UninstallExceptionHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FifoPlayerThread(const std::optional<std::string>& savestate_path)
|
static void FifoPlayerThread(const std::optional<std::string>& savestate_path,
|
||||||
|
bool delete_savestate)
|
||||||
{
|
{
|
||||||
DeclareAsCPUThread();
|
DeclareAsCPUThread();
|
||||||
const SConfig& _CoreParameter = SConfig::GetInstance();
|
const SConfig& _CoreParameter = SConfig::GetInstance();
|
||||||
@ -517,6 +524,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::optional<std::string> savestate_path = boot->savestate_path;
|
const std::optional<std::string> savestate_path = boot->savestate_path;
|
||||||
|
const bool delete_savestate = boot->delete_savestate;
|
||||||
|
|
||||||
// Load and Init Wiimotes - only if we are booting in Wii mode
|
// Load and Init Wiimotes - only if we are booting in Wii mode
|
||||||
if (core_parameter.bWii && !SConfig::GetInstance().m_bt_passthrough_enabled)
|
if (core_parameter.bWii && !SConfig::GetInstance().m_bt_passthrough_enabled)
|
||||||
@ -556,7 +564,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
|
|||||||
PowerPC::SetMode(PowerPC::CoreMode::Interpreter);
|
PowerPC::SetMode(PowerPC::CoreMode::Interpreter);
|
||||||
|
|
||||||
// Determine the CPU thread function
|
// Determine the CPU thread function
|
||||||
void (*cpuThreadFunc)(const std::optional<std::string>& savestate_path);
|
void (*cpuThreadFunc)(const std::optional<std::string>& savestate_path, bool delete_savestate);
|
||||||
if (std::holds_alternative<BootParameters::DFF>(boot->parameters))
|
if (std::holds_alternative<BootParameters::DFF>(boot->parameters))
|
||||||
cpuThreadFunc = FifoPlayerThread;
|
cpuThreadFunc = FifoPlayerThread;
|
||||||
else
|
else
|
||||||
@ -597,7 +605,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
|
|||||||
Host_Message(WM_USER_CREATE);
|
Host_Message(WM_USER_CREATE);
|
||||||
|
|
||||||
// Spawn the CPU thread
|
// Spawn the CPU thread
|
||||||
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path);
|
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate);
|
||||||
|
|
||||||
// become the GPU thread
|
// become the GPU thread
|
||||||
Fifo::RunGpuLoop();
|
Fifo::RunGpuLoop();
|
||||||
@ -615,7 +623,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
|
|||||||
Common::SetCurrentThreadName("Emuthread - Idle");
|
Common::SetCurrentThreadName("Emuthread - Idle");
|
||||||
|
|
||||||
// Spawn the CPU+GPU thread
|
// Spawn the CPU+GPU thread
|
||||||
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path);
|
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate);
|
||||||
|
|
||||||
while (CPU::GetState() != CPU::State::PowerDown)
|
while (CPU::GetState() != CPU::State::PowerDown)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user