Common: Refactor PointerWrap
This commit is contained in:
parent
7fcc866c41
commit
f6b9acccfc
|
@ -40,32 +40,37 @@ class PointerWrap
|
|||
public:
|
||||
enum Mode
|
||||
{
|
||||
MODE_READ = 1, // load
|
||||
MODE_WRITE, // save
|
||||
MODE_MEASURE, // calculate size
|
||||
MODE_VERIFY, // compare
|
||||
MODE_READ,
|
||||
MODE_WRITE,
|
||||
MODE_MEASURE,
|
||||
MODE_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::MODE_MEASURE; }
|
||||
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>
|
||||
void Do(std::map<K, V>& x)
|
||||
{
|
||||
u32 count = (u32)x.size();
|
||||
Do(count);
|
||||
|
||||
switch (mode)
|
||||
switch (m_mode)
|
||||
{
|
||||
case MODE_READ:
|
||||
for (x.clear(); count != 0; --count)
|
||||
|
@ -95,7 +100,7 @@ public:
|
|||
u32 count = (u32)x.size();
|
||||
Do(count);
|
||||
|
||||
switch (mode)
|
||||
switch (m_mode)
|
||||
{
|
||||
case MODE_READ:
|
||||
for (x.clear(); count != 0; --count)
|
||||
|
@ -154,7 +159,7 @@ public:
|
|||
bool present = x.has_value();
|
||||
Do(present);
|
||||
|
||||
switch (mode)
|
||||
switch (m_mode)
|
||||
{
|
||||
case MODE_READ:
|
||||
if (present)
|
||||
|
@ -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,13 +335,13 @@ 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:
|
||||
memcpy(data, *m_ptr_current, size);
|
||||
|
|
|
@ -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<Event>());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<const u8*>(iram), DSP_IRAM_BYTE_SIZE);
|
||||
p.DoArray(dram, DSP_DRAM_SIZE);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<u8> 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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ void DoState(PointerWrap& 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,
|
||||
// then force a reconnection on load.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -57,7 +57,7 @@ void SDIOSlot0Device::RefreshConfig()
|
|||
void SDIOSlot0Device::DoState(PointerWrap& p)
|
||||
{
|
||||
DoStateShared(p);
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
if (p.IsReadMode())
|
||||
{
|
||||
OpenInternal();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<u32> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,6 @@ std::optional<IPCReply> 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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -75,7 +75,7 @@ std::optional<IPCReply> 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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -132,7 +132,7 @@ void DoState(PointerWrap& p)
|
|||
|
||||
ppcState.iCache.DoState(p);
|
||||
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
if (p.IsReadMode())
|
||||
{
|
||||
RoundingModeUpdated();
|
||||
IBATUpdated();
|
||||
|
|
|
@ -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<u8>& buffer)
|
|||
Core::RunOnCPUThread(
|
||||
[&] {
|
||||
u8* ptr = buffer.data();
|
||||
PointerWrap p(&ptr, buffer.size(), PointerWrap::MODE_READ);
|
||||
PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ);
|
||||
DoState(p);
|
||||
},
|
||||
true);
|
||||
|
@ -237,14 +237,14 @@ void SaveToBuffer(std::vector<u8>& buffer)
|
|||
Core::RunOnCPUThread(
|
||||
[&] {
|
||||
u8* ptr = nullptr;
|
||||
PointerWrap p_measure(&ptr, 0, PointerWrap::MODE_MEASURE);
|
||||
PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE);
|
||||
|
||||
DoState(p_measure);
|
||||
const size_t buffer_size = reinterpret_cast<size_t>(ptr);
|
||||
buffer.resize(buffer_size);
|
||||
|
||||
ptr = buffer.data();
|
||||
PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE);
|
||||
PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::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::MODE_MEASURE);
|
||||
DoState(p_measure);
|
||||
const size_t buffer_size = reinterpret_cast<size_t>(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::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::MODE_READ);
|
||||
DoState(p);
|
||||
loaded = true;
|
||||
loadedSuccessfully = (p.GetMode() == PointerWrap::MODE_READ);
|
||||
loadedSuccessfully = p.IsReadMode();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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::MODE_MEASURE);
|
||||
DoState(&p_measure);
|
||||
const size_t buffer_size = reinterpret_cast<size_t>(ptr);
|
||||
|
||||
// Then actually do the write.
|
||||
std::vector<u8> buffer(buffer_size);
|
||||
ptr = buffer.data();
|
||||
PointerWrap p(&ptr, buffer_size, PointerWrap::MODE_WRITE);
|
||||
PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::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::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<GameFile>& elem) {
|
||||
if (state.GetMode() == PointerWrap::MODE_READ)
|
||||
if (state.IsReadMode())
|
||||
elem = std::make_shared<GameFile>();
|
||||
elem->DoState(state);
|
||||
});
|
||||
|
|
|
@ -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<BBoxType> backend_values(NUM_BBOX_VALUES);
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
if (p.IsReadMode())
|
||||
{
|
||||
p.Do(backend_values);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -482,7 +482,7 @@ void FrameDump::CloseVideoFile()
|
|||
|
||||
void FrameDump::DoState(PointerWrap& p)
|
||||
{
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
if (p.IsReadMode())
|
||||
++m_savestate_index;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<u64>::max();
|
||||
|
|
|
@ -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::TexPoolEntry> 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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -635,7 +635,7 @@ void VertexShaderManager::DoState(PointerWrap& p)
|
|||
|
||||
p.Do(constants);
|
||||
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
if (p.IsReadMode())
|
||||
{
|
||||
Dirty();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue