diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index 9fd785459e..5a9cf1823e 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -38,36 +38,41 @@ class PointerWrap { public: - enum Mode + enum class Mode { - MODE_READ = 1, // load - MODE_WRITE, // save - MODE_MEASURE, // calculate size - MODE_VERIFY, // compare + Read, + Write, + Measure, + Verify, }; private: u8** m_ptr_current; u8* m_ptr_end; - Mode mode; + Mode m_mode; public: - PointerWrap(u8** ptr, size_t size, Mode mode_) - : m_ptr_current(ptr), m_ptr_end(*ptr + size), mode(mode_) + PointerWrap(u8** ptr, size_t size, Mode mode) + : m_ptr_current(ptr), m_ptr_end(*ptr + size), m_mode(mode) { } - void SetMode(Mode mode_) { mode = mode_; } - Mode GetMode() const { return mode; } + void SetMeasureMode() { m_mode = Mode::Measure; } + void SetVerifyMode() { m_mode = Mode::Verify; } + bool IsReadMode() const { return m_mode == Mode::Read; } + bool IsWriteMode() const { return m_mode == Mode::Write; } + bool IsMeasureMode() const { return m_mode == Mode::Measure; } + bool IsVerifyMode() const { return m_mode == Mode::Verify; } + template void Do(std::map& x) { u32 count = (u32)x.size(); Do(count); - switch (mode) + switch (m_mode) { - case MODE_READ: + case Mode::Read: for (x.clear(); count != 0; --count) { std::pair pair; @@ -77,9 +82,9 @@ public: } break; - case MODE_WRITE: - case MODE_MEASURE: - case MODE_VERIFY: + case Mode::Write: + case Mode::Measure: + case Mode::Verify: for (auto& elem : x) { Do(elem.first); @@ -95,9 +100,9 @@ public: u32 count = (u32)x.size(); Do(count); - switch (mode) + switch (m_mode) { - case MODE_READ: + case Mode::Read: for (x.clear(); count != 0; --count) { V value; @@ -106,9 +111,9 @@ public: } break; - case MODE_WRITE: - case MODE_MEASURE: - case MODE_VERIFY: + case Mode::Write: + case Mode::Measure: + case Mode::Verify: for (const V& val : x) { Do(val); @@ -154,9 +159,9 @@ public: bool present = x.has_value(); Do(present); - switch (mode) + switch (m_mode) { - case MODE_READ: + case Mode::Read: if (present) { x = std::make_optional(); @@ -168,9 +173,9 @@ public: } break; - case MODE_WRITE: - case MODE_MEASURE: - case MODE_VERIFY: + case Mode::Write: + case Mode::Measure: + case Mode::Verify: if (present) Do(x.value()); @@ -216,10 +221,10 @@ public: Do(count); u8* current = *m_ptr_current; *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 - mode = MODE_MEASURE; + SetMeasureMode(); } return current; } @@ -228,7 +233,7 @@ public: { bool s = flag.IsSet(); Do(s); - if (mode == MODE_READ) + if (IsReadMode()) flag.Set(s); } @@ -237,7 +242,7 @@ public: { T temp = atomic.load(std::memory_order_relaxed); Do(temp); - if (mode == MODE_READ) + if (IsReadMode()) atomic.store(temp, std::memory_order_relaxed); } @@ -267,7 +272,7 @@ public: Do(stable); - if (mode == MODE_READ) + if (IsReadMode()) x = stable != 0; } @@ -278,7 +283,7 @@ public: // much range ptrdiff_t offset = x - base; Do(offset); - if (mode == MODE_READ) + if (IsReadMode()) { x = base + offset; } @@ -289,13 +294,13 @@ public: u32 cookie = arbitraryNumber; Do(cookie); - if (mode == PointerWrap::MODE_READ && cookie != arbitraryNumber) + if (IsReadMode() && cookie != arbitraryNumber) { PanicAlertFmtT( "Error: After \"{0}\", found {1} ({2:#x}) instead of save marker {3} ({4:#x}). Aborting " "savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); - mode = PointerWrap::MODE_MEASURE; + SetMeasureMode(); } } @@ -330,26 +335,26 @@ private: 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 - mode = MODE_MEASURE; + SetMeasureMode(); } - switch (mode) + switch (m_mode) { - case MODE_READ: + case Mode::Read: memcpy(data, *m_ptr_current, size); break; - case MODE_WRITE: + case Mode::Write: memcpy(*m_ptr_current, data, size); break; - case MODE_MEASURE: + case Mode::Measure: break; - case MODE_VERIFY: + case Mode::Verify: DEBUG_ASSERT_MSG(COMMON, !memcmp(data, *m_ptr_current, size), "Savestate verification failure: buf {} != {} (size {}).\n", fmt::ptr(data), fmt::ptr(*m_ptr_current), size); diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index 8f07510588..74247e442c 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -192,11 +192,11 @@ void DoState(PointerWrap& p) // order (or at all) every time. // so, we savestate the event's type's name, and derive ev.type from that when loading. std::string name; - if (pw.GetMode() != PointerWrap::MODE_READ) + if (!pw.IsReadMode()) name = *ev.type->name; pw.Do(name); - if (pw.GetMode() == PointerWrap::MODE_READ) + if (pw.IsReadMode()) { auto itr = s_event_types.find(name); 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. // The exact layout of the heap in memory is implementation defined, therefore it is platform // 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()); } diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index acef7e507a..e20d570fcc 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -398,7 +398,7 @@ void SDSP::DoState(PointerWrap& p) Common::WriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false); // TODO: This uses the wrong endianness (producing bad disassembly) // and a bogus byte count (producing bad hashes) - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) Host::CodeLoaded(m_dsp_core, reinterpret_cast(iram), DSP_IRAM_BYTE_SIZE); p.DoArray(dram, DSP_DRAM_SIZE); } diff --git a/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp b/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp index 10ab940314..1176568d7b 100644 --- a/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp +++ b/Source/Core/Core/HW/DSPHLE/DSPHLE.cpp @@ -95,11 +95,11 @@ void DSPHLE::DoState(PointerWrap& p) { bool is_hle = true; 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.", 3000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } diff --git a/Source/Core/Core/HW/DSPHLE/MailHandler.cpp b/Source/Core/Core/HW/DSPHLE/MailHandler.cpp index bede5130c3..ce6b8f8a1a 100644 --- a/Source/Core/Core/HW/DSPHLE/MailHandler.cpp +++ b/Source/Core/Core/HW/DSPHLE/MailHandler.cpp @@ -91,7 +91,7 @@ void CMailHandler::Halt(bool _Halt) void CMailHandler::DoState(PointerWrap& p) { - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { Clear(); int sz = 0; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp index f1f716390a..ee64a96659 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp @@ -747,15 +747,14 @@ void AXUCode::DoAXState(PointerWrap& p) auto old_checksum = m_coeffs_checksum; p.Do(m_coeffs_checksum); - if (p.GetMode() == PointerWrap::MODE_READ && m_coeffs_checksum && - old_checksum != m_coeffs_checksum) + if (p.IsReadMode() && m_coeffs_checksum && old_checksum != m_coeffs_checksum) { if (!LoadResamplingCoefficients(true, *m_coeffs_checksum)) { Core::DisplayMessage("Could not find the DSP polyphase resampling coefficients used by the " "savestate. Aborting load state.", 3000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } } diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp index ebe529bfe7..c555ff4b9a 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp @@ -42,11 +42,11 @@ void DSPLLE::DoState(PointerWrap& p) { bool is_hle = false; 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.", 3000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } m_dsp_core.DoState(p); diff --git a/Source/Core/Core/HW/GBACore.cpp b/Source/Core/Core/HW/GBACore.cpp index 13eb74b720..f755345807 100644 --- a/Source/Core/Core/HW/GBACore.cpp +++ b/Source/Core/Core/HW/GBACore.cpp @@ -651,7 +651,7 @@ void Core::DoState(PointerWrap& p) { ::Core::DisplayMessage(fmt::format("GBA{} core not started. Aborting.", m_device_number + 1), 3000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } @@ -662,14 +662,13 @@ void Core::DoState(PointerWrap& p) auto old_title = m_game_title; p.Do(m_game_title); - if (p.GetMode() == PointerWrap::MODE_READ && - (has_rom != !m_rom_path.empty() || - (has_rom && (old_hash != m_rom_hash || old_title != m_game_title)))) + if (p.IsReadMode() && (has_rom != !m_rom_path.empty() || + (has_rom && (old_hash != m_rom_hash || old_title != m_game_title)))) { ::Core::DisplayMessage( fmt::format("Incompatible ROM state in GBA{}. Aborting load state.", m_device_number + 1), 3000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } @@ -684,14 +683,14 @@ void Core::DoState(PointerWrap& p) std::vector core_state; 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()); } 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()); if (auto host = m_host.lock()) diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index 8f98ffd7b5..4f2aaa1a5d 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -428,7 +428,7 @@ void DoState(PointerWrap& p) Core::DisplayMessage("State is incompatible with current memory settings (MMU and/or memory " "overrides). Aborting load state.", 3000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 675e533346..476a265f76 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -226,7 +226,7 @@ void DoState(PointerWrap& p) static_cast(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, // then force a reconnection on load. diff --git a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp index 8f0cce590f..4d1d84da9d 100644 --- a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp @@ -559,7 +559,7 @@ void Wiimote::DoState(PointerWrap& p) m_speaker_logic.DoState(p); m_camera_logic.DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) m_camera_logic.SetEnabled(m_status.ir); p.Do(m_is_motion_plus_attached); diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/Extension.cpp b/Source/Core/Core/HW/WiimoteEmu/Extension/Extension.cpp index 80b547ef7f..aa9d419977 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/Extension.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/Extension.cpp @@ -136,7 +136,7 @@ void EncryptedExtension::DoState(PointerWrap& p) { 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. m_is_key_dirty = true; diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp index 2e2fee3f87..ef1e983b2a 100644 --- a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp +++ b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp @@ -260,7 +260,7 @@ void HostFileSystem::DoState(PointerWrap& p) // handle /tmp std::string Path = BuildFilename("/tmp").host_path; - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { File::DeleteDirRecursively(Path); File::CreateDir(Path); diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index 364e647839..42fb3632d3 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -807,7 +807,7 @@ void Kernel::DoState(PointerWrap& p) for (const auto& entry : m_device_map) entry.second->DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { for (u32 i = 0; i < IPC_MAX_FDS; i++) { diff --git a/Source/Core/Core/IOS/Network/Socket.cpp b/Source/Core/Core/IOS/Network/Socket.cpp index 20220c2968..9537c8cdff 100644 --- a/Source/Core/Core/IOS/Network/Socket.cpp +++ b/Source/Core/Core/IOS/Network/Socket.cpp @@ -994,8 +994,7 @@ void WiiSockMan::Convert(sockaddr_in const& from, WiiSockAddrIn& to, s32 addrlen void WiiSockMan::DoState(PointerWrap& p) { - bool saving = p.GetMode() == PointerWrap::Mode::MODE_WRITE || - p.GetMode() == PointerWrap::Mode::MODE_MEASURE; + bool saving = p.IsWriteMode() || p.IsMeasureMode(); auto size = pending_polls.size(); p.Do(size); if (!saving) diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp index 8cb17f3267..d12121ce8b 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp @@ -57,7 +57,7 @@ void SDIOSlot0Device::RefreshConfig() void SDIOSlot0Device::DoState(PointerWrap& p) { DoStateShared(p); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { OpenInternal(); } diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp index 44b317c806..5994c9640a 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp @@ -90,10 +90,10 @@ void BluetoothEmuDevice::DoState(PointerWrap& p) { bool passthrough_bluetooth = false; 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); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index d4bb7041b3..12def23084 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -268,28 +268,28 @@ void BluetoothRealDevice::DoState(PointerWrap& p) { bool passthrough_bluetooth = true; 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); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); return; } // 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 // 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(); std::vector addresses_to_discard; - if (p.GetMode() != PointerWrap::MODE_READ) + if (!p.IsReadMode()) { // Save addresses of transfer commands to discard on savestate load. for (const auto& transfer : m_current_transfers) addresses_to_discard.push_back(transfer.second.command->ios_request.address); } 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 // 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); } - 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" "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. - if (p.GetMode() == PointerWrap::MODE_WRITE) + if (p.IsWriteMode()) m_transfers_mutex.unlock(); } diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTStub.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTStub.cpp index 70a98d782b..5eb0be05ce 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTStub.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTStub.cpp @@ -19,6 +19,6 @@ std::optional BluetoothStubDevice::Open(const OpenRequest& request) void BluetoothStubDevice::DoState(PointerWrap& p) { Core::DisplayMessage("The current IPC_HLE_Device_usb is a stub. Aborting load.", 4000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); } } // namespace IOS::HLE diff --git a/Source/Core/Core/IOS/USB/Host.cpp b/Source/Core/Core/IOS/USB/Host.cpp index 42442ddea5..0fdaafb611 100644 --- a/Source/Core/Core/IOS/USB/Host.cpp +++ b/Source/Core/Core/IOS/USB/Host.cpp @@ -55,7 +55,7 @@ void USBHost::UpdateWantDeterminism(const bool new_want_determinism) 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 // already plugged in, and which need to be triggered. diff --git a/Source/Core/Core/IOS/USB/OH0/OH0.cpp b/Source/Core/Core/IOS/USB/OH0/OH0.cpp index 7fc3702e96..cfda8b6cf8 100644 --- a/Source/Core/Core/IOS/USB/OH0/OH0.cpp +++ b/Source/Core/Core/IOS/USB/OH0/OH0.cpp @@ -75,7 +75,7 @@ std::optional OH0::IOCtlV(const IOCtlVRequest& request) 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.", 5000); diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index e39efd143b..8e31441b4f 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -47,7 +47,7 @@ void SetJit(JitBase* jit) } void DoState(PointerWrap& p) { - if (g_jit && p.GetMode() == PointerWrap::MODE_READ) + if (g_jit && p.IsReadMode()) g_jit->ClearCache(); } CPUCoreBase* InitJitCore(PowerPC::CPUCore core) diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index e45706f199..aa6f7fbe11 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -100,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, CPUCore core) void DoState(PointerWrap& p) { // some of this code has been disabled, because - // it changes registers even in MODE_MEASURE (which is suspicious and seems like it could cause + // it changes registers even in Mode::Measure (which is suspicious and seems like it could cause // desyncs) // and because the values it's changing have been added to CoreTiming::DoState, so it might // conflict to mess with them here. @@ -132,7 +132,7 @@ void DoState(PointerWrap& p) ppcState.iCache.DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { RoundingModeUpdated(); IBATUpdated(); diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 4b79a76d71..9387adf72c 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -156,7 +156,7 @@ static void DoState(PointerWrap& p) "This savestate was created using an incompatible version of Dolphin" : "This savestate was created using the incompatible version " + version_created_by; Core::DisplayMessage(message, OSD::Duration::NORMAL); - p.SetMode(PointerWrap::MODE_MEASURE); + p.SetMeasureMode(); return; } @@ -168,7 +168,7 @@ static void DoState(PointerWrap& p) OSD::AddMessage(fmt::format("Cannot load a savestate created under {} mode in {} mode", is_wii ? "Wii" : "GC", is_wii_currently ? "Wii" : "GC"), OSD::Duration::NORMAL, OSD::Color::RED); - p.SetMode(PointerWrap::MODE_MEASURE); + p.SetMeasureMode(); return; } @@ -186,7 +186,7 @@ static void DoState(PointerWrap& p) Memory::GetExRamSizeReal(), Memory::GetExRamSizeReal() / 0x100000U, state_mem1_size, state_mem1_size / 0x100000U, state_mem2_size, state_mem2_size / 0x100000U)); - p.SetMode(PointerWrap::MODE_MEASURE); + p.SetMeasureMode(); return; } @@ -226,7 +226,7 @@ void LoadFromBuffer(std::vector& buffer) Core::RunOnCPUThread( [&] { u8* ptr = buffer.data(); - PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ); + PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::Read); DoState(p); }, true); @@ -237,14 +237,14 @@ void SaveToBuffer(std::vector& buffer) Core::RunOnCPUThread( [&] { u8* ptr = nullptr; - PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE); + PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::Measure); DoState(p_measure); const size_t buffer_size = reinterpret_cast(ptr); buffer.resize(buffer_size); ptr = buffer.data(); - PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE); + PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::Write); DoState(p); }, true); @@ -412,22 +412,22 @@ void SaveAs(const std::string& filename, bool wait) [&] { // Measure the size of the buffer. u8* ptr = nullptr; - PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE); + PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::Measure); DoState(p_measure); const size_t buffer_size = reinterpret_cast(ptr); // Then actually do the write. - PointerWrap::Mode p_mode; + bool is_write_mode; { std::lock_guard lk(g_cs_current_buffer); g_current_buffer.resize(buffer_size); ptr = g_current_buffer.data(); - PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE); + PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::Write); 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); @@ -591,10 +591,10 @@ void LoadAs(const std::string& filename) if (!buffer.empty()) { u8* ptr = buffer.data(); - PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ); + PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::Read); DoState(p); loaded = true; - loadedSuccessfully = (p.GetMode() == PointerWrap::MODE_READ); + loadedSuccessfully = p.IsReadMode(); } } diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp index a41c07553c..dbb349dad9 100644 --- a/Source/Core/UICommon/GameFileCache.cpp +++ b/Source/Core/UICommon/GameFileCache.cpp @@ -230,14 +230,14 @@ bool GameFileCache::SyncCacheFile(bool save) { // Measure the size of the buffer. u8* ptr = nullptr; - PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE); + PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::Measure); DoState(&p_measure); const size_t buffer_size = reinterpret_cast(ptr); // Then actually do the write. std::vector buffer(buffer_size); ptr = buffer.data(); - PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE); + PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::Write); DoState(&p, buffer_size); if (f.WriteBytes(buffer.data(), buffer.size())) success = true; @@ -248,9 +248,9 @@ bool GameFileCache::SyncCacheFile(bool save) if (!buffer.empty() && f.ReadBytes(buffer.data(), buffer.size())) { u8* ptr = buffer.data(); - PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ); + PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::Read); DoState(&p, buffer.size()); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) success = true; } } @@ -271,16 +271,16 @@ void GameFileCache::DoState(PointerWrap* p, u64 size) u64 expected_size; } header = {CACHE_REVISION, size}; p->Do(header); - if (p->GetMode() == PointerWrap::MODE_READ) + if (p->IsReadMode()) { if (header.revision != CACHE_REVISION || header.expected_size != size) { - p->SetMode(PointerWrap::MODE_MEASURE); + p->SetMeasureMode(); return; } } p->DoEachElement(m_cached_files, [](PointerWrap& state, std::shared_ptr& elem) { - if (state.GetMode() == PointerWrap::MODE_READ) + if (state.IsReadMode()) elem = std::make_shared(); elem->DoState(state); }); diff --git a/Source/Core/VideoCommon/BoundingBox.cpp b/Source/Core/VideoCommon/BoundingBox.cpp index 33cffef469..f5ecc8478b 100644 --- a/Source/Core/VideoCommon/BoundingBox.cpp +++ b/Source/Core/VideoCommon/BoundingBox.cpp @@ -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 don't mess up the current cache state std::vector backend_values(NUM_BBOX_VALUES); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { p.Do(backend_values); diff --git a/Source/Core/VideoCommon/CPMemory.cpp b/Source/Core/VideoCommon/CPMemory.cpp index 3a2ee54bc6..401c37bc00 100644 --- a/Source/Core/VideoCommon/CPMemory.cpp +++ b/Source/Core/VideoCommon/CPMemory.cpp @@ -26,7 +26,7 @@ void DoCPState(PointerWrap& p) p.Do(g_main_cp_state.vtx_desc); p.DoArray(g_main_cp_state.vtx_attr); p.DoMarker("CP Memory"); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { CopyPreprocessCPStateFromMain(); VertexLoaderManager::g_bases_dirty = true; diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index 18ef1b432f..5b31589e82 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -94,7 +94,7 @@ void DoState(PointerWrap& p) p.DoPointer(write_ptr, s_video_buffer); s_video_buffer_write_ptr = write_ptr; 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? s_video_buffer_seen_ptr = s_video_buffer_pp_read_ptr = s_video_buffer_read_ptr; diff --git a/Source/Core/VideoCommon/FrameDump.cpp b/Source/Core/VideoCommon/FrameDump.cpp index 92296e8794..55e0e3daa6 100644 --- a/Source/Core/VideoCommon/FrameDump.cpp +++ b/Source/Core/VideoCommon/FrameDump.cpp @@ -482,7 +482,7 @@ void FrameDump::CloseVideoFile() void FrameDump::DoState(PointerWrap& p) { - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) ++m_savestate_index; } diff --git a/Source/Core/VideoCommon/FramebufferManager.cpp b/Source/Core/VideoCommon/FramebufferManager.cpp index c6cb2fd29e..d4fdfd0ff2 100644 --- a/Source/Core/VideoCommon/FramebufferManager.cpp +++ b/Source/Core/VideoCommon/FramebufferManager.cpp @@ -910,7 +910,7 @@ void FramebufferManager::DoState(PointerWrap& p) if (!save_efb_state) return; - if (p.GetMode() == PointerWrap::MODE_WRITE || p.GetMode() == PointerWrap::MODE_MEASURE) + if (p.IsWriteMode() || p.IsMeasureMode()) DoSaveState(p); else DoLoadState(p); diff --git a/Source/Core/VideoCommon/FreeLookCamera.cpp b/Source/Core/VideoCommon/FreeLookCamera.cpp index 34677acbb8..2bc7d11bb9 100644 --- a/Source/Core/VideoCommon/FreeLookCamera.cpp +++ b/Source/Core/VideoCommon/FreeLookCamera.cpp @@ -298,7 +298,7 @@ Common::Vec2 FreeLookCamera::GetFieldOfViewMultiplier() const 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); if (m_camera_controller) @@ -314,7 +314,7 @@ void FreeLookCamera::DoState(PointerWrap& 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 loaded_type_name = m_current_type ? to_string(*m_current_type) : ""; @@ -323,7 +323,7 @@ void FreeLookCamera::DoState(PointerWrap& p) "'{}'. Aborting load state", old_type_name, loaded_type_name); Core::DisplayMessage(message, 5000); - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); } } } diff --git a/Source/Core/VideoCommon/GeometryShaderManager.cpp b/Source/Core/VideoCommon/GeometryShaderManager.cpp index f488ed7343..f71a687ce8 100644 --- a/Source/Core/VideoCommon/GeometryShaderManager.cpp +++ b/Source/Core/VideoCommon/GeometryShaderManager.cpp @@ -111,7 +111,7 @@ void GeometryShaderManager::DoState(PointerWrap& p) p.Do(constants); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { // Fixup the current state from global GPU state // NOTE: This requires that all GPU memory has been loaded already. diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp index 675bcceca5..4e6ce9ff6f 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/PixelShaderManager.cpp @@ -542,7 +542,7 @@ void PixelShaderManager::DoState(PointerWrap& p) p.Do(constants); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { // Fixup the current state from global GPU state // NOTE: This requires that all GPU memory has been loaded already. diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index d895d648ed..dbad9711f1 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -1810,7 +1810,7 @@ void Renderer::DoState(PointerWrap& p) m_bounding_box->DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { // Force the next xfb to be displayed. m_last_xfb_id = std::numeric_limits::max(); diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 406a7bef21..dc08fd90bc 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -432,7 +432,7 @@ void TextureCacheBase::SerializeTexture(AbstractTexture* tex, const TextureConfi PointerWrap& p) { // 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); 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. 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); return; @@ -502,7 +502,7 @@ std::optional TextureCacheBase::DeserializeTextu u32 total_size = 0; 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; auto tex = AllocateTexture(config); @@ -542,7 +542,7 @@ void TextureCacheBase::DoState(PointerWrap& p) p.Do(last_entry_id); - if (p.GetMode() == PointerWrap::MODE_WRITE || p.GetMode() == PointerWrap::MODE_MEASURE) + if (p.IsWriteMode() || p.IsMeasureMode()) DoSaveState(p); else DoLoadState(p); @@ -673,7 +673,7 @@ void TextureCacheBase::DoLoadState(PointerWrap& p) // 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 // 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) Invalidate(); diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index bb23a468ea..72f02927b5 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -519,7 +519,7 @@ void VertexManagerBase::Flush() void VertexManagerBase::DoState(PointerWrap& p) { - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { // Flush old vertex data before loading state. Flush(); diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 2b5fc68185..6a7636d587 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -635,7 +635,7 @@ void VertexShaderManager::DoState(PointerWrap& p) p.Do(constants); - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { Dirty(); } diff --git a/Source/Core/VideoCommon/VideoState.cpp b/Source/Core/VideoCommon/VideoState.cpp index c348649da5..538c3d0904 100644 --- a/Source/Core/VideoCommon/VideoState.cpp +++ b/Source/Core/VideoCommon/VideoState.cpp @@ -27,10 +27,10 @@ void VideoCommon_DoState(PointerWrap& p) bool software = false; 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. - p.SetMode(PointerWrap::MODE_VERIFY); + p.SetVerifyMode(); } // BP Memory @@ -86,7 +86,7 @@ void VideoCommon_DoState(PointerWrap& p) p.DoMarker("Renderer"); // Refresh state. - if (p.GetMode() == PointerWrap::MODE_READ) + if (p.IsReadMode()) { // Inform backend of new state from registers. BPReload();