From 94d02a23de83f87cd57a5347c24addcec4eeaaf8 Mon Sep 17 00:00:00 2001 From: smelenchuk Date: Sat, 12 Feb 2011 08:25:09 +0000 Subject: [PATCH] Tweaks to Wii rerecording for general stability and reliability. * Better control over which Wiimotes save/load input from input files (general sync improvement). * Wiimote save stores the ACLQ, allowing maintaining control across save/load (thanks to skid for the idea). * Wiimote reconnect on save/load now an option - enabled by default to preserve present behaviour. Disabling this allows the above change to be effective. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7147 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/ConfigManager.cpp | 2 + Source/Core/Core/Src/ConfigManager.h | 1 + Source/Core/Core/Src/HW/Wiimote.cpp | 2 +- .../Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp | 10 ++-- .../Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp | 47 ++++++++++++++----- Source/Core/Core/Src/OnFrame.cpp | 11 +++-- Source/Core/Core/Src/OnFrame.h | 4 +- Source/Core/DolphinWX/Src/ConfigMain.cpp | 7 +++ Source/Core/DolphinWX/Src/ConfigMain.h | 2 + 9 files changed, 60 insertions(+), 26 deletions(-) diff --git a/Source/Core/Core/Src/ConfigManager.cpp b/Source/Core/Core/Src/ConfigManager.cpp index aee1c8964a..3b784b7b27 100644 --- a/Source/Core/Core/Src/ConfigManager.cpp +++ b/Source/Core/Core/Src/ConfigManager.cpp @@ -239,6 +239,7 @@ void SConfig::SaveSettings() ini.Set("Core", "WiiSDCard", m_WiiSDCard); ini.Set("Core", "WiiKeyboard", m_WiiKeyboard); + ini.Set("Core", "WiimoteReconnectOnLoad", m_WiimoteReconnectOnLoad); ini.Set("Core", "RunCompareServer", m_LocalCoreStartupParameter.bRunCompareServer); ini.Set("Core", "RunCompareClient", m_LocalCoreStartupParameter.bRunCompareClient); ini.Set("Core", "FrameLimit", m_Framelimit); @@ -364,6 +365,7 @@ void SConfig::LoadSettings() ini.Get("Core", "WiiSDCard", &m_WiiSDCard, false); ini.Get("Core", "WiiKeyboard", &m_WiiKeyboard, false); + ini.Get("Core", "WiimoteReconnectOnLoad", &m_WiimoteReconnectOnLoad, true); ini.Get("Core", "RunCompareServer", &m_LocalCoreStartupParameter.bRunCompareServer, false); ini.Get("Core", "RunCompareClient", &m_LocalCoreStartupParameter.bRunCompareClient, false); ini.Get("Core", "MMU", &m_LocalCoreStartupParameter.bMMU, false); diff --git a/Source/Core/Core/Src/ConfigManager.h b/Source/Core/Core/Src/ConfigManager.h index 6c1f5417f7..b5c183daa2 100644 --- a/Source/Core/Core/Src/ConfigManager.h +++ b/Source/Core/Core/Src/ConfigManager.h @@ -33,6 +33,7 @@ struct SConfig : NonCopyable bool m_WiiKeyboard; bool m_WiiAutoReconnect[4]; bool m_WiiAutoUnpair; + bool m_WiimoteReconnectOnLoad; // name of the last used filename std::string m_LastFilename; diff --git a/Source/Core/Core/Src/HW/Wiimote.cpp b/Source/Core/Core/Src/HW/Wiimote.cpp index a81dd5298d..0712196327 100644 --- a/Source/Core/Core/Src/HW/Wiimote.cpp +++ b/Source/Core/Core/Src/HW/Wiimote.cpp @@ -104,7 +104,7 @@ void Update(int _number) } _last_number = _number; - if ((Frame::IsPlayingInput() && Frame::IsUsingWiimote(_number)) || (!Frame::IsPlayingInput() && (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]))) + if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) ((WiimoteEmu::Wiimote*)g_plugin.controllers[_number])->Update(); else WiimoteReal::Update(_number); diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp index 19c711ddc8..8896d48ff7 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp @@ -668,13 +668,9 @@ void Wiimote::Update() memset(data, 0, sizeof(data)); // figure out what data we need - s8 rptf_size = MAX_PAYLOAD;; + s8 rptf_size = MAX_PAYLOAD; - if (Frame::IsPlayingInput()) - { - Frame::PlayWiimote(data, rptf_size); - } - else + if (!Frame::IsPlayingInput() || !Frame::PlayWiimote(m_index, data, rptf_size)) { const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE]; rptf_size = rptf.size; @@ -782,7 +778,7 @@ void Wiimote::Update() } if (Frame::IsRecordingInput()) { - Frame::RecordWiimote(data, rptf_size); + Frame::RecordWiimote(m_index, data, rptf_size); } } 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 01b92e5072..840f304637 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 @@ -111,20 +111,45 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) p.Do(m_NumCompPackets_Freq); p.Do(m_WiimoteUpdate_Freq); + u32 size; if (p.GetMode() == PointerWrap::MODE_READ) { - // Reset the connection of all connected wiimotes - for (unsigned int i = 0; i < 4; i++) + u8 buf[sizeof(ACLQ)]; + p.Do(size); + while (!m_ACLQ.empty()) + m_ACLQ.pop(); + for (u32 i = 0; i < size; i++) { - if (m_WiiMotes[i].IsConnected()) - { - m_WiiMotes[i].Activate(false); - m_WiiMotes[i].Activate(true); - } - else - { - m_WiiMotes[i].Activate(false); - } + p.DoVoid((void *)buf, sizeof(ACLQ)); + m_ACLQ.push(*(ACLQ *)buf); + } + if (SConfig::GetInstance().m_WiimoteReconnectOnLoad) + { + // Reset the connection of all connected wiimotes + for (unsigned int i = 0; i < 4; i++) + { + if (m_WiiMotes[i].IsConnected()) + { + m_WiiMotes[i].Activate(false); + m_WiiMotes[i].Activate(true); + } + else + { + m_WiiMotes[i].Activate(false); + } + } + } + } + else + { + size = m_ACLQ.size(); + p.Do(size); + for (u32 i = 0; i < size; i++) + { + ACLQ tmp = m_ACLQ.front(); + m_ACLQ.pop(); + m_ACLQ.push(tmp); + p.DoVoid((void *)&tmp, sizeof(ACLQ)); } } } diff --git a/Source/Core/Core/Src/OnFrame.cpp b/Source/Core/Core/Src/OnFrame.cpp index dea58d65ae..bd88c92012 100644 --- a/Source/Core/Core/Src/OnFrame.cpp +++ b/Source/Core/Core/Src/OnFrame.cpp @@ -239,9 +239,9 @@ void RecordInput(SPADStatus *PadStatus, int controllerID) fwrite(&g_padState, sizeof(ControllerState), 1, g_recordfd); } -void RecordWiimote(u8 *data, s8 size) +void RecordWiimote(int wiimote, u8 *data, s8 size) { - if(!IsRecordingInput()) + if(!IsRecordingInput() || !IsUsingWiimote(wiimote)) return; fwrite(&size, 1, 1, g_recordfd); @@ -409,11 +409,11 @@ void PlayController(SPADStatus *PadStatus, int controllerID) } } -void PlayWiimote(u8 *data, s8 &size) +bool PlayWiimote(int wiimote, u8 *data, s8 &size) { s8 count = 0; - if(!IsPlayingInput()) - return; + if(!IsPlayingInput() || !IsUsingWiimote(wiimote)) + return false; fread(&count, 1, 1, g_recordfd); size = (count > size) ? size : count; @@ -425,6 +425,7 @@ void PlayWiimote(u8 *data, s8 &size) Core::DisplayMessage("Movie End", 2000); EndPlayInput(); } + return true; } void EndPlayInput() { diff --git a/Source/Core/Core/Src/OnFrame.h b/Source/Core/Core/Src/OnFrame.h index 3a5316955b..c7eabe4fbd 100644 --- a/Source/Core/Core/Src/OnFrame.h +++ b/Source/Core/Core/Src/OnFrame.h @@ -114,12 +114,12 @@ void FrameSkipping(); bool BeginRecordingInput(int controllers); void RecordInput(SPADStatus *PadStatus, int controllerID); -void RecordWiimote(u8* data, s8 size); +void RecordWiimote(int wiimote, u8* data, s8 size); bool PlayInput(const char *filename); void LoadInput(const char *filename); void PlayController(SPADStatus *PadStatus, int controllerID); -void PlayWiimote(u8* data, s8 &size); +bool PlayWiimote(int wiimote, u8* data, s8 &size); void EndPlayInput(); void SaveRecording(const char *filename); diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index ee588e6687..2679d24c70 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -163,6 +163,7 @@ EVT_CHOICE(ID_WII_IPL_LNG, CConfigMain::WiiSettingsChanged) EVT_CHECKBOX(ID_WII_SD_CARD, CConfigMain::WiiSettingsChanged) EVT_CHECKBOX(ID_WII_KEYBOARD, CConfigMain::WiiSettingsChanged) +EVT_CHECKBOX(ID_WII_WIIMOTE_RECONNECT, CConfigMain::WiiSettingsChanged) EVT_LISTBOX(ID_ISOPATHS, CConfigMain::ISOPathsSelectionChanged) @@ -500,6 +501,7 @@ void CConfigMain::InitializeGUIValues() WiiSensBarPos->SetSelection(SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR")); WiiSensBarSens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.SENS")); WiimoteMotor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData("BT.MOT")); + WiimoteReconnectOnLoad->SetValue(SConfig::GetInstance().m_WiimoteReconnectOnLoad); // Wii - Misc WiiScreenSaver->SetValue(!!SConfig::GetInstance().m_SYSCONF->GetData("IPL.SSV")); @@ -821,6 +823,7 @@ void CConfigMain::CreateGUIControls() WiiSensBarPos = new wxChoice(WiiPage, ID_WII_BT_BAR, wxDefaultPosition, wxDefaultSize, arrayStringFor_WiiSensBarPos, 0, wxDefaultValidator); WiiSensBarSens = new wxSlider(WiiPage, ID_WII_BT_SENS, 0, 0, 4); WiimoteMotor = new wxCheckBox(WiiPage, ID_WII_BT_MOT, _("Wiimote Motor"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + WiimoteReconnectOnLoad = new wxCheckBox(WiiPage, ID_WII_KEYBOARD, _("Reconnect Wiimote On Load State"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); // Misc Settings WiiScreenSaver = new wxCheckBox(WiiPage, ID_WII_IPL_SSV, _("Enable Screen Saver (burn-in reduction)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); @@ -841,6 +844,7 @@ void CConfigMain::CreateGUIControls() wxGBPosition(1, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL|wxALL, 5); sWiimoteSettings->Add(WiiSensBarSens, wxGBPosition(1, 1), wxDefaultSpan, wxEXPAND|wxALL, 5); sWiimoteSettings->Add(WiimoteMotor, wxGBPosition(2, 0), wxGBSpan(1, 2), wxALL, 5); + sWiimoteSettings->Add(WiimoteReconnectOnLoad, wxGBPosition(3, 0), wxGBSpan(1, 2), wxALL, 5); sbWiimoteSettings = new wxStaticBoxSizer(wxHORIZONTAL, WiiPage, _("Wiimote Settings")); sbWiimoteSettings->Add(sWiimoteSettings); @@ -1261,6 +1265,9 @@ void CConfigMain::WiiSettingsChanged(wxCommandEvent& event) case ID_WII_BT_MOT: SConfig::GetInstance().m_SYSCONF->SetData("BT.MOT", WiimoteMotor->IsChecked()); break; + case ID_WII_WIIMOTE_RECONNECT: + SConfig::GetInstance().m_WiimoteReconnectOnLoad = WiimoteReconnectOnLoad->IsChecked(); + break; // SYSCONF settings case ID_WII_IPL_SSV: SConfig::GetInstance().m_SYSCONF->SetData("IPL.SSV", WiiScreenSaver->IsChecked()); diff --git a/Source/Core/DolphinWX/Src/ConfigMain.h b/Source/Core/DolphinWX/Src/ConfigMain.h index 7397f841b0..007978b43a 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.h +++ b/Source/Core/DolphinWX/Src/ConfigMain.h @@ -117,6 +117,7 @@ private: ID_WII_BT_BAR, ID_WII_BT_SENS, ID_WII_BT_MOT, + ID_WII_WIIMOTE_RECONNECT, ID_WII_IPL_SSV, ID_WII_IPL_E60, @@ -218,6 +219,7 @@ private: wxChoice* WiiSensBarPos; wxSlider* WiiSensBarSens; wxCheckBox* WiimoteMotor; + wxCheckBox* WiimoteReconnectOnLoad; // Misc wxCheckBox* WiiScreenSaver;