Savestates: Warn on savestate load and saves without mcd activity

[SAVEVERSION+]
This commit is contained in:
Ty Lamontagne 2024-12-17 14:39:50 -05:00 committed by Ty
parent 72a9f18456
commit a2c7542e48
6 changed files with 31 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#include "SIO/SioTypes.h"
#include "SIO/Memcard/MemoryCardProtocol.h"
#include "Counters.h"
#include "Host.h"
#include "IconsPromptFont.h"
@ -128,6 +129,8 @@ void AutoEject::ClearAll()
// unsafe to shutdown the VM due to memcard access.
static std::atomic_uint32_t currentBusyTicks = 0;
uint32_t sioLastFrameMcdBusy = 0;
void MemcardBusy::Decrement()
{
if (currentBusyTicks.load(std::memory_order_relaxed) == 0)
@ -139,6 +142,7 @@ void MemcardBusy::Decrement()
void MemcardBusy::SetBusy()
{
currentBusyTicks.store(300, std::memory_order_release);
sioLastFrameMcdBusy = g_FrameCount;
}
bool MemcardBusy::IsBusy()
@ -149,4 +153,15 @@ bool MemcardBusy::IsBusy()
void MemcardBusy::ClearBusy()
{
currentBusyTicks.store(0, std::memory_order_release);
sioLastFrameMcdBusy = 0;
}
#include "common/Console.h"
void MemcardBusy::CheckSaveStateDependency()
{
if (g_FrameCount - sioLastFrameMcdBusy > NUM_FRAMES_BEFORE_SAVESTATE_DEPENDENCY_WARNING)
{
Host::AddIconOSDMessage("MemcardBusy", ICON_PF_MEMORY_CARD,
TRANSLATE_SV("MemoryCard", "The virtual console hasn't saved to your memory card for quite some time. Savestates should not be used in place of in-game saves."), Host::OSD_INFO_DURATION);
}
}

View File

@ -118,10 +118,19 @@ namespace AutoEject
extern void ClearAll();
} // namespace AutoEject
// ~1 hour of memory card inactivity.
constexpr u32 NUM_FRAMES_BEFORE_SAVESTATE_DEPENDENCY_WARNING = 60 * 60 * 60;
// Set to the current frame count when there is memory card activity.
// Used to detect the last frame when memory card activity was detected,
// and if it exceeds a certain threshold, warns on savestate save/load.
extern uint32_t sioLastFrameMcdBusy;
namespace MemcardBusy
{
extern void Decrement();
extern void SetBusy();
extern bool IsBusy();
extern void ClearBusy();
extern void CheckSaveStateDependency();
}

View File

@ -541,5 +541,6 @@ bool Sio2::DoState(StateWrapper& sw)
}
}
sw.Do(&sioLastFrameMcdBusy);
return sw.IsGood();
}

View File

@ -15,12 +15,13 @@
#include "Host.h"
#include "MTGS.h"
#include "MTVU.h"
#include "SIO/Pad/Pad.h"
#include "Patch.h"
#include "R3000A.h"
#include "SIO/Multitap/MultitapProtocol.h"
#include "SIO/Pad/Pad.h"
#include "SIO/Sio.h"
#include "SIO/Sio0.h"
#include "SIO/Sio2.h"
#include "SIO/Multitap/MultitapProtocol.h"
#include "SPU2/spu2.h"
#include "SaveState.h"
#include "StateWrapper.h"

View File

@ -25,7 +25,7 @@ enum class FreezeAction
// [SAVEVERSION+]
// This informs the auto updater that the users savestates will be invalidated.
static const u32 g_SaveVersion = (0x9A51 << 16) | 0x0000;
static const u32 g_SaveVersion = (0x9A52 << 16) | 0x0000;
// the freezing data between submodules and core

View File

@ -1818,6 +1818,7 @@ bool VMManager::DoLoadState(const char* filename)
MTGS::PresentCurrentFrame();
}
MemcardBusy::CheckSaveStateDependency();
return true;
}
@ -1866,6 +1867,7 @@ bool VMManager::DoSaveState(const char* filename, s32 slot_for_message, bool zip
}
Host::OnSaveStateSaved(filename);
MemcardBusy::CheckSaveStateDependency();
return true;
}