From 470a4eee8b9c75d231c2f6840b0b8559325b1375 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Mon, 3 Dec 2012 21:14:25 -0500 Subject: [PATCH] Fixing wiimote savestate and recording. --- .../Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp | 2 +- .../Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp | 100 +++++------------- Source/Core/Core/Src/State.cpp | 2 +- 3 files changed, 28 insertions(+), 76 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp index e5ed088b66..91882b2cb7 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp @@ -613,7 +613,7 @@ void Wiimote::DoState(PointerWrap& p) p.Do(m_status); p.Do(m_adpcm_state); p.Do(m_ext_key); - p.Do(m_eeprom); + p.DoArray(m_eeprom, sizeof(m_eeprom)); p.Do(m_reg_motion_plus); p.Do(m_reg_ir); p.Do(m_reg_ext); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index 0b6de9b4f6..a6ea9fb577 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -104,14 +104,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::~CWII_IPC_HLE_Device_usb_oh1_57e_305() void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) { -/* - //things that do not get saved: (why not?) - - std::vector m_WiiMotes; - - std::deque m_EventQueue; - */ - + p.Do(m_Active); p.Do(m_ControllerBD); p.Do(m_CtrlSetup); p.Do(m_ACLSetup); @@ -120,75 +113,34 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) p.Do(m_last_ticks); p.DoArray(m_PacketCount,4); p.Do(m_ScanEnable); + p.Do(m_EventQueue); m_acl_pool.DoState(p); - bool storeFullData = (Movie::IsRecordingInput() || Movie::IsPlayingInput()); - p.Do(storeFullData); - p.DoMarker("storeFullData in CWII_IPC_HLE_Device_usb_oh1_57e_305"); - - if (!storeFullData) - { - if (p.GetMode() == PointerWrap::MODE_READ) - { - m_EventQueue.clear(); - - if (SConfig::GetInstance().m_WiimoteReconnectOnLoad) - { - // Reset the connection of all connected wiimotes - for (unsigned int i = 0; i < 4; i++) - { - if (!m_WiiMotes[i].IsInactive()) - { - m_WiiMotes[i].Activate(false); - m_WiiMotes[i].Activate(true); - } - else - { - m_WiiMotes[i].Activate(false); - } - } - } - } + for (unsigned int i = 0; i < 4; i++) + { + if (p.GetMode() == PointerWrap::MODE_READ && !(WIIMOTE_SRC_EMU == g_wiimote_sources[i] || WIIMOTE_SRC_NONE == g_wiimote_sources[i])) + continue; + m_WiiMotes[i].DoState(p); + } + + // Reset the connection of real and hybrid wiimotes + if (p.GetMode() == PointerWrap::MODE_READ && SConfig::GetInstance().m_WiimoteReconnectOnLoad) + { + for (unsigned int i = 0; i < 4; i++) + { + if (WIIMOTE_SRC_EMU == g_wiimote_sources[i] || WIIMOTE_SRC_NONE == g_wiimote_sources[i]) + continue; + // TODO: Selectively clear real wiimote messages if possible. Or create a real wiimote channel and reporting mode pre-setup to vacate the need for m_WiimoteReconnectOnLoad. + m_EventQueue.clear(); + if (!m_WiiMotes[i].IsInactive()) + { + m_WiiMotes[i].Activate(false); + m_WiiMotes[i].Activate(true); + } + else + m_WiiMotes[i].Activate(false); + } } - else - { - // I'm not sure why these things aren't normally saved, but I think they can affect the emulation state, - // so if sync matters (e.g. if a movie is active), we really should save them. - // also, it's definitely not safe to do the above auto-reconnect hack either. - // (unless we can do it without changing anything that affects emulation state, which is not currently the case) - - p.Do(m_EventQueue); - p.DoMarker("m_EventQueue"); - - // m_WiiMotes is kind of annoying to save. maybe this could be done in a more general way. - u32 vec_size = (u32)m_WiiMotes.size(); - p.Do(vec_size); - for (u32 i = 0; i < vec_size; ++i) - { - if (i < m_WiiMotes.size()) - { - CWII_IPC_HLE_WiiMote& wiimote = m_WiiMotes[i]; - wiimote.DoState(p); - } - else - { - bdaddr_t tmpBD = BDADDR_ANY; - CWII_IPC_HLE_WiiMote wiimote = CWII_IPC_HLE_WiiMote(this, i, tmpBD, false); - wiimote.DoState(p); - if (p.GetMode() == PointerWrap::MODE_READ) - { - m_WiiMotes.push_back(wiimote); - _dbg_assert_(WII_IPC_WIIMOTE, m_WiiMotes.size() == i); - } - } - } - if (p.GetMode() == PointerWrap::MODE_READ) - while ((u32)m_WiiMotes.size() > vec_size) - m_WiiMotes.pop_back(); - p.DoMarker("m_WiiMotes"); - } - - DoStateShared(p); } bool CWII_IPC_HLE_Device_usb_oh1_57e_305::RemoteDisconnect(u16 _connectionHandle) diff --git a/Source/Core/Core/Src/State.cpp b/Source/Core/Core/Src/State.cpp index e93b133413..d9ad3c6b5c 100644 --- a/Source/Core/Core/Src/State.cpp +++ b/Source/Core/Core/Src/State.cpp @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const int STATE_VERSION = 9; +static const int STATE_VERSION = 10; struct StateHeader {