diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 28a5aea7f7..d015e44ca4 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -60,23 +60,15 @@ namespace SaveState void *cbUserData; }; - static int timer; static bool needsProcess = false; static std::vector pending; static std::recursive_mutex mutex; - void Process(u64 userdata, int cyclesLate); - void SaveStart::DoState(PointerWrap &p) { // Gotta do CoreTiming first since we'll restore into it. CoreTiming::DoState(p); - // This save state even saves its own state. - p.Do(timer); - CoreTiming::RestoreRegisterEvent(timer, "SaveState", Process); - p.DoMarker("SaveState"); - Memory::DoState(p); MemoryStick_DoState(p); currentMIPS->DoState(p); @@ -96,10 +88,8 @@ namespace SaveState if (Core_IsInactive() && __KernelIsRunning()) { // Warning: this may run on a different thread. - Process(0, 0); + Process(); } - else if (__KernelIsRunning()) - CoreTiming::ScheduleEvent_Threadsafe(0, timer); else needsProcess = true; } @@ -210,8 +200,12 @@ namespace SaveState return copy; } - void Process(u64 userdata, int cyclesLate) + void Process() { + if (!needsProcess) + return; + needsProcess = false; + if (!__KernelIsRunning()) { ERROR_LOG(COMMON, "Savestate failure: Unable to load without kernel, this should never happen."); @@ -272,15 +266,9 @@ namespace SaveState void Init() { - timer = CoreTiming::RegisterEvent("SaveState", Process); // Make sure there's a directory for save slots pspFileSystem.MkDir("ms0:/PSP/PPSSPP_STATE"); std::lock_guard guard(mutex); - if (needsProcess) - { - CoreTiming::ScheduleEvent(0, timer); - needsProcess = false; - } } } diff --git a/Core/SaveState.h b/Core/SaveState.h index eb3e075a11..8327122100 100644 --- a/Core/SaveState.h +++ b/Core/SaveState.h @@ -31,7 +31,9 @@ namespace SaveState void SaveSlot(int slot, Callback callback, void *cbUserData = 0); void LoadSlot(int slot, Callback callback, void *cbUserData = 0); + // Checks whether there's an existing save in the specified slot. bool HasSaveInSlot(int slot); + // Returns -1 if there's no newest slot. int GetNewestSlot(); // Load the specified file into the current state (async.) @@ -45,4 +47,7 @@ namespace SaveState // For testing / automated tests. Runs a save state verification pass (async.) // Warning: callback will be called on a different thread. void Verify(Callback callback = 0, void *cbUserData = 0); + + // Check if there's any save stating needing to be done. Normally called once per frame. + void Process(); }; diff --git a/Core/System.cpp b/Core/System.cpp index ad90ca04e5..ea434b71bc 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -38,6 +38,7 @@ #include "Core/Loaders.h" #include "Core/PSPLoaders.h" #include "Core/ELF/ParamSFO.h" +#include "Core/SaveState.h" #include "Common/LogManager.h" MetaFileSystem pspFileSystem; @@ -151,6 +152,7 @@ void PSP_Shutdown() } void PSP_RunLoopUntil(u64 globalticks) { + SaveState::Process(); mipsr4k.RunLoopUntil(globalticks); }