Clean up future save states from the old rewind timeline

pull/3590/head
mariobob 2 weeks ago
parent fe0e493483
commit a3d7f6f5e9

@ -1614,9 +1614,16 @@ void ImGuiManager::RenderRewindSelector()
{
// Queue the state load to run on the CPU thread
const std::string state_path = states[current_index].state_path;
Host::RunOnCPUThread([state_path]() {
const u32 selected_frame = states[current_index].frame_number;
Host::RunOnCPUThread([state_path, selected_frame]() {
Error error;
if (!System::LoadState(state_path.c_str(), &error, true, false))
if (System::LoadState(state_path.c_str(), &error, true, false))
{
// Delete all states that occurred after this one (future states from old timeline)
System::DeleteRewindStatesAfter(selected_frame);
}
else
{
Host::AddIconOSDMessage("RewindLoadState", ICON_EMOJI_WARNING,
fmt::format("Failed to load rewind state: {}", error.GetDescription()),

@ -5215,6 +5215,27 @@ void System::SaveRewindState()
}
}
void System::DeleteRewindStatesAfter(u32 frame_number)
{
const std::string rewind_dir = GetRewindStateSaveDirectory();
if (rewind_dir.empty())
return;
std::vector<RewindStateInfo> existing_states = GetAvailableRewindStates();
for (const RewindStateInfo& state : existing_states)
{
// Delete all states with frame numbers greater than the selected one (more recent states)
if (state.frame_number > frame_number)
{
DEBUG_LOG("Deleting future rewind state: {} (frame {})", state.state_path, state.frame_number);
if (FileSystem::FileExists(state.state_path.c_str()))
FileSystem::DeleteFile(state.state_path.c_str());
if (FileSystem::FileExists(state.screenshot_path.c_str()))
FileSystem::DeleteFile(state.screenshot_path.c_str());
}
}
}
void System::OpenRewindStateSelector()
{
if (!IsValid() || !g_settings.rewind_enable || !g_settings.rewind_use_save_states)

@ -374,6 +374,9 @@ std::vector<RewindStateInfo> GetAvailableRewindStates();
/// Saves a rewind state to disk (only when using save state-based rewinding).
void SaveRewindState();
/// Deletes all rewind states with frame numbers greater than the specified frame.
void DeleteRewindStatesAfter(u32 frame_number);
/// Opens the rewind state selector UI.
void OpenRewindStateSelector();

Loading…
Cancel
Save