diff --git a/pcsx2/SaveState.h b/pcsx2/SaveState.h index f250ccf19e..7926f63af3 100644 --- a/pcsx2/SaveState.h +++ b/pcsx2/SaveState.h @@ -15,9 +15,12 @@ #pragma once +#include +#include #include #include "System.h" +#include "common/Assertions.h" #include "common/Exceptions.h" enum class FreezeAction @@ -33,7 +36,7 @@ enum class FreezeAction // [SAVEVERSION+] // This informs the auto updater that the users savestates will be invalidated. -static const u32 g_SaveVersion = (0x9A32 << 16) | 0x0000; +static const u32 g_SaveVersion = (0x9A33 << 16) | 0x0000; // the freezing data between submodules and core @@ -118,6 +121,36 @@ public: void PrepBlock( int size ); + template + void FreezeDeque(std::deque& q) + { + // overwritten when loading + u32 count = static_cast(q.size()); + Freeze(count); + + // have to use a temp array, because deque doesn't have a contiguous block of memory + std::unique_ptr temp; + if (count > 0) + { + temp = std::make_unique(count); + if (IsSaving()) + { + u32 pos = 0; + for (const T& it : q) + temp[pos++] = it; + } + + FreezeMem(temp.get(), static_cast(sizeof(T) * count)); + } + + if (IsLoading()) + { + q.clear(); + for (u32 i = 0; i < count; i++) + q.push_back(temp[i]); + } + } + uint GetCurrentPos() const { return m_idx; diff --git a/pcsx2/Sio.cpp b/pcsx2/Sio.cpp index 84ac57b16b..8ef767c732 100644 --- a/pcsx2/Sio.cpp +++ b/pcsx2/Sio.cpp @@ -868,53 +868,9 @@ void SaveStateBase::sio2Freeze() { FreezeTag("sio2"); - if (IsSaving()) - { - std::deque::iterator iter; - size_t backupSize; - - // Copy fifoIn - if (fifoIn.size()) - { - sio2.fifoInBackup = std::make_unique(fifoIn.size()); - iter = fifoIn.begin(); - backupSize = 0; - - while (iter != fifoIn.end()) - { - const u8 val = *iter++; - sio2.fifoInBackup.get()[backupSize++] = val; - } - - sio2.fifoInBackupSize = backupSize; - } - else - { - sio2.fifoInBackupSize = 0; - } - - // Copy fifoOut - if (fifoOut.size()) - { - sio2.fifoOutBackup = std::make_unique(fifoOut.size()); - iter = fifoOut.begin(); - backupSize = 0; - - while (iter != fifoOut.end()) - { - const u8 val = *iter++; - sio2.fifoOutBackup.get()[backupSize++] = val; - } - - sio2.fifoOutBackupSize = backupSize; - } - else - { - sio2.fifoOutBackupSize = 0; - } - } - Freeze(sio2); + FreezeDeque(fifoIn); + FreezeDeque(fifoOut); // CRCs for memory cards. // If the memory card hasn't changed when loading state, we can safely skip ejecting it. @@ -944,28 +900,6 @@ void SaveStateBase::sio2Freeze() } } } - - // Restore fifoIn - fifoIn.clear(); - - if (sio2.fifoInBackupSize) - { - for (size_t i = 0; i < sio2.fifoInBackupSize; i++) - { - fifoIn.push_back(sio2.fifoInBackup.get()[i]); - } - } - - // Restore fifoOut - fifoOut.clear(); - - if (sio2.fifoOutBackupSize) - { - for (size_t j = 0; j < sio2.fifoOutBackupSize; j++) - { - fifoOut.push_back(sio2.fifoOutBackup.get()[j]); - } - } } } diff --git a/pcsx2/Sio.h b/pcsx2/Sio.h index a4cf5c84da..3ede33433d 100644 --- a/pcsx2/Sio.h +++ b/pcsx2/Sio.h @@ -198,11 +198,6 @@ public: size_t dmaBlockSize = 0; bool send3Complete = false; - std::unique_ptr fifoInBackup; - size_t fifoInBackupSize; - std::unique_ptr fifoOutBackup; - size_t fifoOutBackupSize; - Sio2(); ~Sio2();