Common: Refactor PointerWrap

This commit is contained in:
Dentomologist 2022-05-17 22:29:05 -07:00
parent 7fcc866c41
commit f6b9acccfc
38 changed files with 108 additions and 106 deletions

View File

@ -40,32 +40,37 @@ class PointerWrap
public: public:
enum Mode enum Mode
{ {
MODE_READ = 1, // load MODE_READ,
MODE_WRITE, // save MODE_WRITE,
MODE_MEASURE, // calculate size MODE_MEASURE,
MODE_VERIFY, // compare MODE_VERIFY,
}; };
private: private:
u8** m_ptr_current; u8** m_ptr_current;
u8* m_ptr_end; u8* m_ptr_end;
Mode mode; Mode m_mode;
public: public:
PointerWrap(u8** ptr, size_t size, Mode mode_) PointerWrap(u8** ptr, size_t size, Mode mode)
: m_ptr_current(ptr), m_ptr_end(*ptr + size), mode(mode_) : m_ptr_current(ptr), m_ptr_end(*ptr + size), m_mode(mode)
{ {
} }
void SetMode(Mode mode_) { mode = mode_; } void SetMeasureMode() { m_mode = Mode::MODE_MEASURE; }
Mode GetMode() const { return mode; } void SetVerifyMode() { m_mode = Mode::MODE_VERIFY; }
bool IsReadMode() const { return m_mode == Mode::MODE_READ; }
bool IsWriteMode() const { return m_mode == Mode::MODE_WRITE; }
bool IsMeasureMode() const { return m_mode == Mode::MODE_MEASURE; }
bool IsVerifyMode() const { return m_mode == Mode::MODE_VERIFY; }
template <typename K, class V> template <typename K, class V>
void Do(std::map<K, V>& x) void Do(std::map<K, V>& x)
{ {
u32 count = (u32)x.size(); u32 count = (u32)x.size();
Do(count); Do(count);
switch (mode) switch (m_mode)
{ {
case MODE_READ: case MODE_READ:
for (x.clear(); count != 0; --count) for (x.clear(); count != 0; --count)
@ -95,7 +100,7 @@ public:
u32 count = (u32)x.size(); u32 count = (u32)x.size();
Do(count); Do(count);
switch (mode) switch (m_mode)
{ {
case MODE_READ: case MODE_READ:
for (x.clear(); count != 0; --count) for (x.clear(); count != 0; --count)
@ -154,7 +159,7 @@ public:
bool present = x.has_value(); bool present = x.has_value();
Do(present); Do(present);
switch (mode) switch (m_mode)
{ {
case MODE_READ: case MODE_READ:
if (present) if (present)
@ -216,10 +221,10 @@ public:
Do(count); Do(count);
u8* current = *m_ptr_current; u8* current = *m_ptr_current;
*m_ptr_current += count; *m_ptr_current += count;
if (mode != MODE_MEASURE && *m_ptr_current > m_ptr_end) if (!IsMeasureMode() && *m_ptr_current > m_ptr_end)
{ {
// trying to read/write past the end of the buffer, prevent this // trying to read/write past the end of the buffer, prevent this
mode = MODE_MEASURE; SetMeasureMode();
} }
return current; return current;
} }
@ -228,7 +233,7 @@ public:
{ {
bool s = flag.IsSet(); bool s = flag.IsSet();
Do(s); Do(s);
if (mode == MODE_READ) if (IsReadMode())
flag.Set(s); flag.Set(s);
} }
@ -237,7 +242,7 @@ public:
{ {
T temp = atomic.load(std::memory_order_relaxed); T temp = atomic.load(std::memory_order_relaxed);
Do(temp); Do(temp);
if (mode == MODE_READ) if (IsReadMode())
atomic.store(temp, std::memory_order_relaxed); atomic.store(temp, std::memory_order_relaxed);
} }
@ -267,7 +272,7 @@ public:
Do(stable); Do(stable);
if (mode == MODE_READ) if (IsReadMode())
x = stable != 0; x = stable != 0;
} }
@ -278,7 +283,7 @@ public:
// much range // much range
ptrdiff_t offset = x - base; ptrdiff_t offset = x - base;
Do(offset); Do(offset);
if (mode == MODE_READ) if (IsReadMode())
{ {
x = base + offset; x = base + offset;
} }
@ -289,13 +294,13 @@ public:
u32 cookie = arbitraryNumber; u32 cookie = arbitraryNumber;
Do(cookie); Do(cookie);
if (mode == PointerWrap::MODE_READ && cookie != arbitraryNumber) if (IsReadMode() && cookie != arbitraryNumber)
{ {
PanicAlertFmtT( PanicAlertFmtT(
"Error: After \"{0}\", found {1} ({2:#x}) instead of save marker {3} ({4:#x}). Aborting " "Error: After \"{0}\", found {1} ({2:#x}) instead of save marker {3} ({4:#x}). Aborting "
"savestate load...", "savestate load...",
prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); prevName, cookie, cookie, arbitraryNumber, arbitraryNumber);
mode = PointerWrap::MODE_MEASURE; SetMeasureMode();
} }
} }
@ -330,13 +335,13 @@ private:
DOLPHIN_FORCE_INLINE void DoVoid(void* data, u32 size) DOLPHIN_FORCE_INLINE void DoVoid(void* data, u32 size)
{ {
if (mode != MODE_MEASURE && (*m_ptr_current + size) > m_ptr_end) if (!IsMeasureMode() && (*m_ptr_current + size) > m_ptr_end)
{ {
// trying to read/write past the end of the buffer, prevent this // trying to read/write past the end of the buffer, prevent this
mode = MODE_MEASURE; SetMeasureMode();
} }
switch (mode) switch (m_mode)
{ {
case MODE_READ: case MODE_READ:
memcpy(data, *m_ptr_current, size); memcpy(data, *m_ptr_current, size);

View File

@ -192,11 +192,11 @@ void DoState(PointerWrap& p)
// order (or at all) every time. // order (or at all) every time.
// so, we savestate the event's type's name, and derive ev.type from that when loading. // so, we savestate the event's type's name, and derive ev.type from that when loading.
std::string name; std::string name;
if (pw.GetMode() != PointerWrap::MODE_READ) if (!pw.IsReadMode())
name = *ev.type->name; name = *ev.type->name;
pw.Do(name); pw.Do(name);
if (pw.GetMode() == PointerWrap::MODE_READ) if (pw.IsReadMode())
{ {
auto itr = s_event_types.find(name); auto itr = s_event_types.find(name);
if (itr != s_event_types.end()) if (itr != s_event_types.end())
@ -217,7 +217,7 @@ void DoState(PointerWrap& p)
// When loading from a save state, we must assume the Event order is random and meaningless. // When loading from a save state, we must assume the Event order is random and meaningless.
// The exact layout of the heap in memory is implementation defined, therefore it is platform // The exact layout of the heap in memory is implementation defined, therefore it is platform
// and library version specific. // and library version specific.
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
std::make_heap(s_event_queue.begin(), s_event_queue.end(), std::greater<Event>()); std::make_heap(s_event_queue.begin(), s_event_queue.end(), std::greater<Event>());
} }

View File

@ -398,7 +398,7 @@ void SDSP::DoState(PointerWrap& p)
Common::WriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false); Common::WriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false);
// TODO: This uses the wrong endianness (producing bad disassembly) // TODO: This uses the wrong endianness (producing bad disassembly)
// and a bogus byte count (producing bad hashes) // and a bogus byte count (producing bad hashes)
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
Host::CodeLoaded(m_dsp_core, reinterpret_cast<const u8*>(iram), DSP_IRAM_BYTE_SIZE); Host::CodeLoaded(m_dsp_core, reinterpret_cast<const u8*>(iram), DSP_IRAM_BYTE_SIZE);
p.DoArray(dram, DSP_DRAM_SIZE); p.DoArray(dram, DSP_DRAM_SIZE);
} }

View File

@ -95,11 +95,11 @@ void DSPHLE::DoState(PointerWrap& p)
{ {
bool is_hle = true; bool is_hle = true;
p.Do(is_hle); p.Do(is_hle);
if (!is_hle && p.GetMode() == PointerWrap::MODE_READ) if (!is_hle && p.IsReadMode())
{ {
Core::DisplayMessage("State is incompatible with current DSP engine. Aborting load state.", Core::DisplayMessage("State is incompatible with current DSP engine. Aborting load state.",
3000); 3000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }

View File

@ -91,7 +91,7 @@ void CMailHandler::Halt(bool _Halt)
void CMailHandler::DoState(PointerWrap& p) void CMailHandler::DoState(PointerWrap& p)
{ {
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
Clear(); Clear();
int sz = 0; int sz = 0;

View File

@ -747,15 +747,14 @@ void AXUCode::DoAXState(PointerWrap& p)
auto old_checksum = m_coeffs_checksum; auto old_checksum = m_coeffs_checksum;
p.Do(m_coeffs_checksum); p.Do(m_coeffs_checksum);
if (p.GetMode() == PointerWrap::MODE_READ && m_coeffs_checksum && if (p.IsReadMode() && m_coeffs_checksum && old_checksum != m_coeffs_checksum)
old_checksum != m_coeffs_checksum)
{ {
if (!LoadResamplingCoefficients(true, *m_coeffs_checksum)) if (!LoadResamplingCoefficients(true, *m_coeffs_checksum))
{ {
Core::DisplayMessage("Could not find the DSP polyphase resampling coefficients used by the " Core::DisplayMessage("Could not find the DSP polyphase resampling coefficients used by the "
"savestate. Aborting load state.", "savestate. Aborting load state.",
3000); 3000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }
} }

View File

@ -42,11 +42,11 @@ void DSPLLE::DoState(PointerWrap& p)
{ {
bool is_hle = false; bool is_hle = false;
p.Do(is_hle); p.Do(is_hle);
if (is_hle && p.GetMode() == PointerWrap::MODE_READ) if (is_hle && p.IsReadMode())
{ {
Core::DisplayMessage("State is incompatible with current DSP engine. Aborting load state.", Core::DisplayMessage("State is incompatible with current DSP engine. Aborting load state.",
3000); 3000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }
m_dsp_core.DoState(p); m_dsp_core.DoState(p);

View File

@ -651,7 +651,7 @@ void Core::DoState(PointerWrap& p)
{ {
::Core::DisplayMessage(fmt::format("GBA{} core not started. Aborting.", m_device_number + 1), ::Core::DisplayMessage(fmt::format("GBA{} core not started. Aborting.", m_device_number + 1),
3000); 3000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }
@ -662,14 +662,13 @@ void Core::DoState(PointerWrap& p)
auto old_title = m_game_title; auto old_title = m_game_title;
p.Do(m_game_title); p.Do(m_game_title);
if (p.GetMode() == PointerWrap::MODE_READ && if (p.IsReadMode() && (has_rom != !m_rom_path.empty() ||
(has_rom != !m_rom_path.empty() || (has_rom && (old_hash != m_rom_hash || old_title != m_game_title))))
(has_rom && (old_hash != m_rom_hash || old_title != m_game_title))))
{ {
::Core::DisplayMessage( ::Core::DisplayMessage(
fmt::format("Incompatible ROM state in GBA{}. Aborting load state.", m_device_number + 1), fmt::format("Incompatible ROM state in GBA{}. Aborting load state.", m_device_number + 1),
3000); 3000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }
@ -684,14 +683,14 @@ void Core::DoState(PointerWrap& p)
std::vector<u8> core_state; std::vector<u8> core_state;
core_state.resize(m_core->stateSize(m_core)); core_state.resize(m_core->stateSize(m_core));
if (p.GetMode() == PointerWrap::MODE_WRITE || p.GetMode() == PointerWrap::MODE_VERIFY) if (p.IsWriteMode() || p.IsVerifyMode())
{ {
m_core->saveState(m_core, core_state.data()); m_core->saveState(m_core, core_state.data());
} }
p.Do(core_state); p.Do(core_state);
if (p.GetMode() == PointerWrap::MODE_READ && m_core->stateSize(m_core) == core_state.size()) if (p.IsReadMode() && m_core->stateSize(m_core) == core_state.size())
{ {
m_core->loadState(m_core, core_state.data()); m_core->loadState(m_core, core_state.data());
if (auto host = m_host.lock()) if (auto host = m_host.lock())

View File

@ -428,7 +428,7 @@ void DoState(PointerWrap& p)
Core::DisplayMessage("State is incompatible with current memory settings (MMU and/or memory " Core::DisplayMessage("State is incompatible with current memory settings (MMU and/or memory "
"overrides). Aborting load state.", "overrides). Aborting load state.",
3000); 3000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }

View File

@ -226,7 +226,7 @@ void DoState(PointerWrap& p)
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p); static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
} }
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// If using a real wiimote or the save-state source does not match the current source, // If using a real wiimote or the save-state source does not match the current source,
// then force a reconnection on load. // then force a reconnection on load.

View File

@ -559,7 +559,7 @@ void Wiimote::DoState(PointerWrap& p)
m_speaker_logic.DoState(p); m_speaker_logic.DoState(p);
m_camera_logic.DoState(p); m_camera_logic.DoState(p);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
m_camera_logic.SetEnabled(m_status.ir); m_camera_logic.SetEnabled(m_status.ir);
p.Do(m_is_motion_plus_attached); p.Do(m_is_motion_plus_attached);

View File

@ -136,7 +136,7 @@ void EncryptedExtension::DoState(PointerWrap& p)
{ {
p.Do(m_reg); p.Do(m_reg);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// No need to sync the key when we can just regenerate it. // No need to sync the key when we can just regenerate it.
m_is_key_dirty = true; m_is_key_dirty = true;

View File

@ -260,7 +260,7 @@ void HostFileSystem::DoState(PointerWrap& p)
// handle /tmp // handle /tmp
std::string Path = BuildFilename("/tmp").host_path; std::string Path = BuildFilename("/tmp").host_path;
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
File::DeleteDirRecursively(Path); File::DeleteDirRecursively(Path);
File::CreateDir(Path); File::CreateDir(Path);

View File

@ -807,7 +807,7 @@ void Kernel::DoState(PointerWrap& p)
for (const auto& entry : m_device_map) for (const auto& entry : m_device_map)
entry.second->DoState(p); entry.second->DoState(p);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
for (u32 i = 0; i < IPC_MAX_FDS; i++) for (u32 i = 0; i < IPC_MAX_FDS; i++)
{ {

View File

@ -994,8 +994,7 @@ void WiiSockMan::Convert(sockaddr_in const& from, WiiSockAddrIn& to, s32 addrlen
void WiiSockMan::DoState(PointerWrap& p) void WiiSockMan::DoState(PointerWrap& p)
{ {
bool saving = p.GetMode() == PointerWrap::Mode::MODE_WRITE || bool saving = p.IsWriteMode() || p.IsMeasureMode();
p.GetMode() == PointerWrap::Mode::MODE_MEASURE;
auto size = pending_polls.size(); auto size = pending_polls.size();
p.Do(size); p.Do(size);
if (!saving) if (!saving)

View File

@ -57,7 +57,7 @@ void SDIOSlot0Device::RefreshConfig()
void SDIOSlot0Device::DoState(PointerWrap& p) void SDIOSlot0Device::DoState(PointerWrap& p)
{ {
DoStateShared(p); DoStateShared(p);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
OpenInternal(); OpenInternal();
} }

View File

@ -90,10 +90,10 @@ void BluetoothEmuDevice::DoState(PointerWrap& p)
{ {
bool passthrough_bluetooth = false; bool passthrough_bluetooth = false;
p.Do(passthrough_bluetooth); p.Do(passthrough_bluetooth);
if (passthrough_bluetooth && p.GetMode() == PointerWrap::MODE_READ) if (passthrough_bluetooth && p.IsReadMode())
{ {
Core::DisplayMessage("State needs Bluetooth passthrough to be enabled. Aborting load.", 4000); Core::DisplayMessage("State needs Bluetooth passthrough to be enabled. Aborting load.", 4000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }

View File

@ -268,28 +268,28 @@ void BluetoothRealDevice::DoState(PointerWrap& p)
{ {
bool passthrough_bluetooth = true; bool passthrough_bluetooth = true;
p.Do(passthrough_bluetooth); p.Do(passthrough_bluetooth);
if (!passthrough_bluetooth && p.GetMode() == PointerWrap::MODE_READ) if (!passthrough_bluetooth && p.IsReadMode())
{ {
Core::DisplayMessage("State needs Bluetooth passthrough to be disabled. Aborting load.", 4000); Core::DisplayMessage("State needs Bluetooth passthrough to be disabled. Aborting load.", 4000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
return; return;
} }
// Prevent the transfer callbacks from messing with m_current_transfers after we have started // Prevent the transfer callbacks from messing with m_current_transfers after we have started
// writing a savestate. We cannot use a scoped lock here because DoState is called twice and // writing a savestate. We cannot use a scoped lock here because DoState is called twice and
// we would lose the lock between the two calls. // we would lose the lock between the two calls.
if (p.GetMode() == PointerWrap::MODE_MEASURE || p.GetMode() == PointerWrap::MODE_VERIFY) if (p.IsMeasureMode() || p.IsVerifyMode())
m_transfers_mutex.lock(); m_transfers_mutex.lock();
std::vector<u32> addresses_to_discard; std::vector<u32> addresses_to_discard;
if (p.GetMode() != PointerWrap::MODE_READ) if (!p.IsReadMode())
{ {
// Save addresses of transfer commands to discard on savestate load. // Save addresses of transfer commands to discard on savestate load.
for (const auto& transfer : m_current_transfers) for (const auto& transfer : m_current_transfers)
addresses_to_discard.push_back(transfer.second.command->ios_request.address); addresses_to_discard.push_back(transfer.second.command->ios_request.address);
} }
p.Do(addresses_to_discard); p.Do(addresses_to_discard);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// On load, discard any pending transfer to make sure the emulated software is not stuck // On load, discard any pending transfer to make sure the emulated software is not stuck
// waiting for the previous request to complete. This is usually not an issue as long as // waiting for the previous request to complete. This is usually not an issue as long as
@ -305,7 +305,7 @@ void BluetoothRealDevice::DoState(PointerWrap& p)
OSD::Duration::NORMAL); OSD::Duration::NORMAL);
} }
if (!s_has_shown_savestate_warning && p.GetMode() == PointerWrap::MODE_WRITE) if (!s_has_shown_savestate_warning && p.IsWriteMode())
{ {
OSD::AddMessage("Savestates may not work with Bluetooth passthrough in all cases.\n" OSD::AddMessage("Savestates may not work with Bluetooth passthrough in all cases.\n"
"They will only work if no remote is connected when restoring the state,\n" "They will only work if no remote is connected when restoring the state,\n"
@ -315,7 +315,7 @@ void BluetoothRealDevice::DoState(PointerWrap& p)
} }
// We have finished the savestate now, so the transfers mutex can be unlocked. // We have finished the savestate now, so the transfers mutex can be unlocked.
if (p.GetMode() == PointerWrap::MODE_WRITE) if (p.IsWriteMode())
m_transfers_mutex.unlock(); m_transfers_mutex.unlock();
} }

View File

@ -19,6 +19,6 @@ std::optional<IPCReply> BluetoothStubDevice::Open(const OpenRequest& request)
void BluetoothStubDevice::DoState(PointerWrap& p) void BluetoothStubDevice::DoState(PointerWrap& p)
{ {
Core::DisplayMessage("The current IPC_HLE_Device_usb is a stub. Aborting load.", 4000); Core::DisplayMessage("The current IPC_HLE_Device_usb is a stub. Aborting load.", 4000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
} }
} // namespace IOS::HLE } // namespace IOS::HLE

View File

@ -55,7 +55,7 @@ void USBHost::UpdateWantDeterminism(const bool new_want_determinism)
void USBHost::DoState(PointerWrap& p) void USBHost::DoState(PointerWrap& p)
{ {
if (IsOpened() && p.GetMode() == PointerWrap::MODE_READ) if (IsOpened() && p.IsReadMode())
{ {
// After a state has loaded, there may be insertion hooks for devices that were // After a state has loaded, there may be insertion hooks for devices that were
// already plugged in, and which need to be triggered. // already plugged in, and which need to be triggered.

View File

@ -75,7 +75,7 @@ std::optional<IPCReply> OH0::IOCtlV(const IOCtlVRequest& request)
void OH0::DoState(PointerWrap& p) void OH0::DoState(PointerWrap& p)
{ {
if (p.GetMode() == PointerWrap::MODE_READ && !m_devices.empty()) if (p.IsReadMode() && !m_devices.empty())
{ {
Core::DisplayMessage("It is suggested that you unplug and replug all connected USB devices.", Core::DisplayMessage("It is suggested that you unplug and replug all connected USB devices.",
5000); 5000);

View File

@ -47,7 +47,7 @@ void SetJit(JitBase* jit)
} }
void DoState(PointerWrap& p) void DoState(PointerWrap& p)
{ {
if (g_jit && p.GetMode() == PointerWrap::MODE_READ) if (g_jit && p.IsReadMode())
g_jit->ClearCache(); g_jit->ClearCache();
} }
CPUCoreBase* InitJitCore(PowerPC::CPUCore core) CPUCoreBase* InitJitCore(PowerPC::CPUCore core)

View File

@ -132,7 +132,7 @@ void DoState(PointerWrap& p)
ppcState.iCache.DoState(p); ppcState.iCache.DoState(p);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
RoundingModeUpdated(); RoundingModeUpdated();
IBATUpdated(); IBATUpdated();

View File

@ -156,7 +156,7 @@ static void DoState(PointerWrap& p)
"This savestate was created using an incompatible version of Dolphin" : "This savestate was created using an incompatible version of Dolphin" :
"This savestate was created using the incompatible version " + version_created_by; "This savestate was created using the incompatible version " + version_created_by;
Core::DisplayMessage(message, OSD::Duration::NORMAL); Core::DisplayMessage(message, OSD::Duration::NORMAL);
p.SetMode(PointerWrap::MODE_MEASURE); p.SetMeasureMode();
return; return;
} }
@ -168,7 +168,7 @@ static void DoState(PointerWrap& p)
OSD::AddMessage(fmt::format("Cannot load a savestate created under {} mode in {} mode", OSD::AddMessage(fmt::format("Cannot load a savestate created under {} mode in {} mode",
is_wii ? "Wii" : "GC", is_wii_currently ? "Wii" : "GC"), is_wii ? "Wii" : "GC", is_wii_currently ? "Wii" : "GC"),
OSD::Duration::NORMAL, OSD::Color::RED); OSD::Duration::NORMAL, OSD::Color::RED);
p.SetMode(PointerWrap::MODE_MEASURE); p.SetMeasureMode();
return; return;
} }
@ -186,7 +186,7 @@ static void DoState(PointerWrap& p)
Memory::GetExRamSizeReal(), Memory::GetExRamSizeReal() / 0x100000U, Memory::GetExRamSizeReal(), Memory::GetExRamSizeReal() / 0x100000U,
state_mem1_size, state_mem1_size / 0x100000U, state_mem2_size, state_mem1_size, state_mem1_size / 0x100000U, state_mem2_size,
state_mem2_size / 0x100000U)); state_mem2_size / 0x100000U));
p.SetMode(PointerWrap::MODE_MEASURE); p.SetMeasureMode();
return; return;
} }
@ -226,7 +226,7 @@ void LoadFromBuffer(std::vector<u8>& buffer)
Core::RunOnCPUThread( Core::RunOnCPUThread(
[&] { [&] {
u8* ptr = buffer.data(); u8* ptr = buffer.data();
PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ); PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ);
DoState(p); DoState(p);
}, },
true); true);
@ -237,14 +237,14 @@ void SaveToBuffer(std::vector<u8>& buffer)
Core::RunOnCPUThread( Core::RunOnCPUThread(
[&] { [&] {
u8* ptr = nullptr; u8* ptr = nullptr;
PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE); PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE);
DoState(p_measure); DoState(p_measure);
const size_t buffer_size = reinterpret_cast<size_t>(ptr); const size_t buffer_size = reinterpret_cast<size_t>(ptr);
buffer.resize(buffer_size); buffer.resize(buffer_size);
ptr = buffer.data(); ptr = buffer.data();
PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE); PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::MODE_WRITE);
DoState(p); DoState(p);
}, },
true); true);
@ -412,22 +412,22 @@ void SaveAs(const std::string& filename, bool wait)
[&] { [&] {
// Measure the size of the buffer. // Measure the size of the buffer.
u8* ptr = nullptr; u8* ptr = nullptr;
PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE); PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE);
DoState(p_measure); DoState(p_measure);
const size_t buffer_size = reinterpret_cast<size_t>(ptr); const size_t buffer_size = reinterpret_cast<size_t>(ptr);
// Then actually do the write. // Then actually do the write.
PointerWrap::Mode p_mode; bool is_write_mode;
{ {
std::lock_guard lk(g_cs_current_buffer); std::lock_guard lk(g_cs_current_buffer);
g_current_buffer.resize(buffer_size); g_current_buffer.resize(buffer_size);
ptr = g_current_buffer.data(); ptr = g_current_buffer.data();
PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE); PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::MODE_WRITE);
DoState(p); DoState(p);
p_mode = p.GetMode(); is_write_mode = p.IsWriteMode();
} }
if (p_mode == PointerWrap::MODE_WRITE) if (is_write_mode)
{ {
Core::DisplayMessage("Saving State...", 1000); Core::DisplayMessage("Saving State...", 1000);
@ -591,10 +591,10 @@ void LoadAs(const std::string& filename)
if (!buffer.empty()) if (!buffer.empty())
{ {
u8* ptr = buffer.data(); u8* ptr = buffer.data();
PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ); PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ);
DoState(p); DoState(p);
loaded = true; loaded = true;
loadedSuccessfully = (p.GetMode() == PointerWrap::MODE_READ); loadedSuccessfully = p.IsReadMode();
} }
} }

View File

@ -230,14 +230,14 @@ bool GameFileCache::SyncCacheFile(bool save)
{ {
// Measure the size of the buffer. // Measure the size of the buffer.
u8* ptr = nullptr; u8* ptr = nullptr;
PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE); PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE);
DoState(&p_measure); DoState(&p_measure);
const size_t buffer_size = reinterpret_cast<size_t>(ptr); const size_t buffer_size = reinterpret_cast<size_t>(ptr);
// Then actually do the write. // Then actually do the write.
std::vector<u8> buffer(buffer_size); std::vector<u8> buffer(buffer_size);
ptr = buffer.data(); ptr = buffer.data();
PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE); PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::MODE_WRITE);
DoState(&p, buffer_size); DoState(&p, buffer_size);
if (f.WriteBytes(buffer.data(), buffer.size())) if (f.WriteBytes(buffer.data(), buffer.size()))
success = true; success = true;
@ -248,9 +248,9 @@ bool GameFileCache::SyncCacheFile(bool save)
if (!buffer.empty() && f.ReadBytes(buffer.data(), buffer.size())) if (!buffer.empty() && f.ReadBytes(buffer.data(), buffer.size()))
{ {
u8* ptr = buffer.data(); u8* ptr = buffer.data();
PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ); PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ);
DoState(&p, buffer.size()); DoState(&p, buffer.size());
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
success = true; success = true;
} }
} }
@ -271,16 +271,16 @@ void GameFileCache::DoState(PointerWrap* p, u64 size)
u64 expected_size; u64 expected_size;
} header = {CACHE_REVISION, size}; } header = {CACHE_REVISION, size};
p->Do(header); p->Do(header);
if (p->GetMode() == PointerWrap::MODE_READ) if (p->IsReadMode())
{ {
if (header.revision != CACHE_REVISION || header.expected_size != size) if (header.revision != CACHE_REVISION || header.expected_size != size)
{ {
p->SetMode(PointerWrap::MODE_MEASURE); p->SetMeasureMode();
return; return;
} }
} }
p->DoEachElement(m_cached_files, [](PointerWrap& state, std::shared_ptr<GameFile>& elem) { p->DoEachElement(m_cached_files, [](PointerWrap& state, std::shared_ptr<GameFile>& elem) {
if (state.GetMode() == PointerWrap::MODE_READ) if (state.IsReadMode())
elem = std::make_shared<GameFile>(); elem = std::make_shared<GameFile>();
elem->DoState(state); elem->DoState(state);
}); });

View File

@ -104,7 +104,7 @@ void BoundingBox::DoState(PointerWrap& p)
// We handle saving the backend values specially rather than using Readback() and Flush() so that // We handle saving the backend values specially rather than using Readback() and Flush() so that
// we don't mess up the current cache state // we don't mess up the current cache state
std::vector<BBoxType> backend_values(NUM_BBOX_VALUES); std::vector<BBoxType> backend_values(NUM_BBOX_VALUES);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
p.Do(backend_values); p.Do(backend_values);

View File

@ -26,7 +26,7 @@ void DoCPState(PointerWrap& p)
p.Do(g_main_cp_state.vtx_desc); p.Do(g_main_cp_state.vtx_desc);
p.DoArray(g_main_cp_state.vtx_attr); p.DoArray(g_main_cp_state.vtx_attr);
p.DoMarker("CP Memory"); p.DoMarker("CP Memory");
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
CopyPreprocessCPStateFromMain(); CopyPreprocessCPStateFromMain();
VertexLoaderManager::g_bases_dirty = true; VertexLoaderManager::g_bases_dirty = true;

View File

@ -94,7 +94,7 @@ void DoState(PointerWrap& p)
p.DoPointer(write_ptr, s_video_buffer); p.DoPointer(write_ptr, s_video_buffer);
s_video_buffer_write_ptr = write_ptr; s_video_buffer_write_ptr = write_ptr;
p.DoPointer(s_video_buffer_read_ptr, s_video_buffer); p.DoPointer(s_video_buffer_read_ptr, s_video_buffer);
if (p.GetMode() == PointerWrap::MODE_READ && s_use_deterministic_gpu_thread) if (p.IsReadMode() && s_use_deterministic_gpu_thread)
{ {
// We're good and paused, right? // We're good and paused, right?
s_video_buffer_seen_ptr = s_video_buffer_pp_read_ptr = s_video_buffer_read_ptr; s_video_buffer_seen_ptr = s_video_buffer_pp_read_ptr = s_video_buffer_read_ptr;

View File

@ -482,7 +482,7 @@ void FrameDump::CloseVideoFile()
void FrameDump::DoState(PointerWrap& p) void FrameDump::DoState(PointerWrap& p)
{ {
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
++m_savestate_index; ++m_savestate_index;
} }

View File

@ -910,7 +910,7 @@ void FramebufferManager::DoState(PointerWrap& p)
if (!save_efb_state) if (!save_efb_state)
return; return;
if (p.GetMode() == PointerWrap::MODE_WRITE || p.GetMode() == PointerWrap::MODE_MEASURE) if (p.IsWriteMode() || p.IsMeasureMode())
DoSaveState(p); DoSaveState(p);
else else
DoLoadState(p); DoLoadState(p);

View File

@ -298,7 +298,7 @@ Common::Vec2 FreeLookCamera::GetFieldOfViewMultiplier() const
void FreeLookCamera::DoState(PointerWrap& p) void FreeLookCamera::DoState(PointerWrap& p)
{ {
if (p.GetMode() == PointerWrap::MODE_WRITE || p.GetMode() == PointerWrap::MODE_MEASURE) if (p.IsWriteMode() || p.IsMeasureMode())
{ {
p.Do(m_current_type); p.Do(m_current_type);
if (m_camera_controller) if (m_camera_controller)
@ -314,7 +314,7 @@ void FreeLookCamera::DoState(PointerWrap& p)
{ {
m_camera_controller->DoState(p); m_camera_controller->DoState(p);
} }
else if (p.GetMode() == PointerWrap::MODE_READ) else if (p.IsReadMode())
{ {
const std::string old_type_name = old_type ? to_string(*old_type) : ""; const std::string old_type_name = old_type ? to_string(*old_type) : "";
const std::string loaded_type_name = m_current_type ? to_string(*m_current_type) : ""; const std::string loaded_type_name = m_current_type ? to_string(*m_current_type) : "";
@ -323,7 +323,7 @@ void FreeLookCamera::DoState(PointerWrap& p)
"'{}'. Aborting load state", "'{}'. Aborting load state",
old_type_name, loaded_type_name); old_type_name, loaded_type_name);
Core::DisplayMessage(message, 5000); Core::DisplayMessage(message, 5000);
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
} }
} }
} }

View File

@ -111,7 +111,7 @@ void GeometryShaderManager::DoState(PointerWrap& p)
p.Do(constants); p.Do(constants);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// Fixup the current state from global GPU state // Fixup the current state from global GPU state
// NOTE: This requires that all GPU memory has been loaded already. // NOTE: This requires that all GPU memory has been loaded already.

View File

@ -542,7 +542,7 @@ void PixelShaderManager::DoState(PointerWrap& p)
p.Do(constants); p.Do(constants);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// Fixup the current state from global GPU state // Fixup the current state from global GPU state
// NOTE: This requires that all GPU memory has been loaded already. // NOTE: This requires that all GPU memory has been loaded already.

View File

@ -1810,7 +1810,7 @@ void Renderer::DoState(PointerWrap& p)
m_bounding_box->DoState(p); m_bounding_box->DoState(p);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// Force the next xfb to be displayed. // Force the next xfb to be displayed.
m_last_xfb_id = std::numeric_limits<u64>::max(); m_last_xfb_id = std::numeric_limits<u64>::max();

View File

@ -432,7 +432,7 @@ void TextureCacheBase::SerializeTexture(AbstractTexture* tex, const TextureConfi
PointerWrap& p) PointerWrap& p)
{ {
// If we're in measure mode, skip the actual readback to save some time. // If we're in measure mode, skip the actual readback to save some time.
const bool skip_readback = p.GetMode() == PointerWrap::MODE_MEASURE; const bool skip_readback = p.IsMeasureMode();
p.DoPOD(config); p.DoPOD(config);
if (skip_readback || CheckReadbackTexture(config.width, config.height, config.format)) if (skip_readback || CheckReadbackTexture(config.width, config.height, config.format))
@ -459,7 +459,7 @@ void TextureCacheBase::SerializeTexture(AbstractTexture* tex, const TextureConfi
// needing to allocate/free an extra buffer. // needing to allocate/free an extra buffer.
u8* texture_data = p.DoExternal(total_size); u8* texture_data = p.DoExternal(total_size);
if (!skip_readback && p.GetMode() == PointerWrap::MODE_MEASURE) if (!skip_readback && p.IsMeasureMode())
{ {
ERROR_LOG_FMT(VIDEO, "Couldn't acquire {} bytes for serializing texture.", total_size); ERROR_LOG_FMT(VIDEO, "Couldn't acquire {} bytes for serializing texture.", total_size);
return; return;
@ -502,7 +502,7 @@ std::optional<TextureCacheBase::TexPoolEntry> TextureCacheBase::DeserializeTextu
u32 total_size = 0; u32 total_size = 0;
u8* texture_data = p.DoExternal(total_size); u8* texture_data = p.DoExternal(total_size);
if (p.GetMode() != PointerWrap::MODE_READ || total_size == 0) if (!p.IsReadMode() || total_size == 0)
return std::nullopt; return std::nullopt;
auto tex = AllocateTexture(config); auto tex = AllocateTexture(config);
@ -542,7 +542,7 @@ void TextureCacheBase::DoState(PointerWrap& p)
p.Do(last_entry_id); p.Do(last_entry_id);
if (p.GetMode() == PointerWrap::MODE_WRITE || p.GetMode() == PointerWrap::MODE_MEASURE) if (p.IsWriteMode() || p.IsMeasureMode())
DoSaveState(p); DoSaveState(p);
else else
DoLoadState(p); DoLoadState(p);
@ -673,7 +673,7 @@ void TextureCacheBase::DoLoadState(PointerWrap& p)
// Only clear out state when actually restoring/loading. // Only clear out state when actually restoring/loading.
// Since we throw away entries when not in loading mode now, we don't need to check // Since we throw away entries when not in loading mode now, we don't need to check
// before inserting entries into the cache, as GetEntry will always return null. // before inserting entries into the cache, as GetEntry will always return null.
const bool commit_state = p.GetMode() == PointerWrap::MODE_READ; const bool commit_state = p.IsReadMode();
if (commit_state) if (commit_state)
Invalidate(); Invalidate();

View File

@ -519,7 +519,7 @@ void VertexManagerBase::Flush()
void VertexManagerBase::DoState(PointerWrap& p) void VertexManagerBase::DoState(PointerWrap& p)
{ {
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// Flush old vertex data before loading state. // Flush old vertex data before loading state.
Flush(); Flush();

View File

@ -635,7 +635,7 @@ void VertexShaderManager::DoState(PointerWrap& p)
p.Do(constants); p.Do(constants);
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
Dirty(); Dirty();
} }

View File

@ -27,10 +27,10 @@ void VideoCommon_DoState(PointerWrap& p)
bool software = false; bool software = false;
p.Do(software); p.Do(software);
if (p.GetMode() == PointerWrap::MODE_READ && software == true) if (p.IsReadMode() && software == true)
{ {
// change mode to abort load of incompatible save state. // change mode to abort load of incompatible save state.
p.SetMode(PointerWrap::MODE_VERIFY); p.SetVerifyMode();
} }
// BP Memory // BP Memory
@ -86,7 +86,7 @@ void VideoCommon_DoState(PointerWrap& p)
p.DoMarker("Renderer"); p.DoMarker("Renderer");
// Refresh state. // Refresh state.
if (p.GetMode() == PointerWrap::MODE_READ) if (p.IsReadMode())
{ {
// Inform backend of new state from registers. // Inform backend of new state from registers.
BPReload(); BPReload();