From d2f61fa1556ca0867a7d58b72bba63f8e7531180 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Thu, 15 Dec 2011 09:22:16 -0800 Subject: [PATCH] some movie playback fixes --- .../Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp | 11 ++-- Source/Core/Core/Src/Movie.cpp | 53 +++++++++++++------ Source/Core/Core/Src/Movie.h | 9 +++- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp index 10084d9c39..5afc5b522d 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp @@ -638,10 +638,9 @@ void Wiimote::Update() Movie::SetPolledDevice(); const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE]; - if (!Movie::IsPlayingInput() || !Movie::PlayWiimote(m_index, data, rptf_size, rptf.core?(data+rptf.core):NULL, rptf.accel?(data+rptf.accel):NULL, rptf.ir?(data+rptf.ir):NULL)) + rptf_size = rptf.size; + if (!Movie::IsPlayingInput() || !Movie::PlayWiimote(m_index, data, rptf, m_reg_ir.mode)) { - rptf_size = rptf.size; - data[0] = 0xA1; data[1] = m_reporting_mode; @@ -661,8 +660,8 @@ void Wiimote::Update() if (rptf.ext) GetExtData(data + rptf.ext); - // hybrid wiimote stuff - if (WIIMOTE_SRC_HYBRID == g_wiimote_sources[m_index]) + // hybrid wiimote stuff (for now, it's not supported while recording) + if (WIIMOTE_SRC_HYBRID == g_wiimote_sources[m_index] && !Movie::IsRecordingInput()) { using namespace WiimoteReal; @@ -744,7 +743,7 @@ void Wiimote::Update() } if (Movie::IsRecordingInput()) { - Movie::RecordWiimote(m_index, data, rptf_size, rptf.core?(data+rptf.core):NULL, rptf.accel?(data+rptf.accel):NULL, rptf.ir?(data+rptf.ir):NULL); + Movie::RecordWiimote(m_index, data, rptf, m_reg_ir.mode); } } diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index 46923dae9a..5438f1e5eb 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -457,7 +457,8 @@ void RecordInput(SPADStatus *PadStatus, int controllerID) g_padState.CStickX = PadStatus->substickX; g_padState.CStickY = PadStatus->substickY; - + + memcpy(&(tmpInput[g_currentByte]), &g_padState, 8); g_currentByte += 8; g_totalBytes = g_currentByte; @@ -465,12 +466,18 @@ void RecordInput(SPADStatus *PadStatus, int controllerID) SetInputDisplayString(g_padState, controllerID); } -void RecordWiimote(int wiimote, u8 *data, s8 size, u8* const coreData, u8* const accelData, u8* const irData) +void RecordWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf, int irMode) { if(!IsRecordingInput() || !IsUsingWiimote(wiimote)) return; + + u8* const coreData = rptf.core?(data+rptf.core):NULL; + u8* const accelData = rptf.accel?(data+rptf.accel):NULL; + u8* const irData = rptf.ir?(data+rptf.ir):NULL; + u8 size = rptf.size; + InputUpdate(); - tmpInput[g_currentByte++] = (u8) size; + tmpInput[g_currentByte++] = size; memcpy(&(tmpInput[g_currentByte]), data, size); g_currentByte += size; g_totalBytes = g_currentByte; @@ -526,6 +533,10 @@ bool PlayInput(const char *filename) g_totalLagCount = tmpHeader.lagCount; g_totalInputCount = tmpHeader.inputCount; + g_currentFrame = 0; + g_currentLagCount = 0; + g_currentInputCount = 0; + g_playMode = MODE_PLAYING; g_totalBytes = g_recordfd.GetSize() - 256; @@ -687,7 +698,8 @@ void PlayController(SPADStatus *PadStatus, int controllerID) signed char e = PadStatus->err; memset(PadStatus, 0, sizeof(SPADStatus)); PadStatus->err = e; - + + memcpy(&g_padState, &(tmpInput[g_currentByte]), 8); g_currentByte += 8; @@ -740,32 +752,43 @@ void PlayController(SPADStatus *PadStatus, int controllerID) CheckInputEnd(); } -bool PlayWiimote(int wiimote, u8 *data, s8 &size, u8* const coreData, u8* const accelData, u8* const irData) +bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf, int irMode) { - s8 count = 0; - if(!IsPlayingInput() || !IsUsingWiimote(wiimote) || tmpInput == NULL) return false; - + if (g_currentByte > g_totalBytes) { PanicAlertT("Premature movie end in PlayWiimote. %u > %u", (u32)g_currentByte, (u32)g_totalBytes); EndPlayInput(!g_bReadOnly); return false; } - - count = (s8) (tmpInput[g_currentByte++]); - if (g_currentByte + count > g_totalBytes) + u8* const coreData = rptf.core?(data+rptf.core):NULL; + u8* const accelData = rptf.accel?(data+rptf.accel):NULL; + u8* const irData = rptf.ir?(data+rptf.ir):NULL; + u8 size = rptf.size; + + u8 sizeInMovie = tmpInput[g_currentByte]; + + if (size != sizeInMovie) { - PanicAlertT("Premature movie end in PlayWiimote. %u + %d > %u", (u32)g_currentByte, count, (u32)g_totalBytes); + PanicAlertT("Error in PlayWiimote. %u != %u, byte %d.\nSorry, Wii recording is temporarily broken.", sizeInMovie, size, g_currentByte); + EndPlayInput(!g_bReadOnly); + return false; + } + + g_currentByte++; + + if (g_currentByte + size > g_totalBytes) + { + PanicAlertT("Premature movie end in PlayWiimote. %u + %d > %u", (u32)g_currentByte, size, (u32)g_totalBytes); EndPlayInput(!g_bReadOnly); return false; } - memcpy(data, &(tmpInput[g_currentByte]), count); - g_currentByte += count; - size = (count > size) ? size : count; + memcpy(data, &(tmpInput[g_currentByte]), size); + g_currentByte += size; SetWiiInputDisplayString(wiimote, coreData, accelData, irData); diff --git a/Source/Core/Core/Src/Movie.h b/Source/Core/Core/Src/Movie.h index 080c608b29..3df376270e 100644 --- a/Source/Core/Core/Src/Movie.h +++ b/Source/Core/Core/Src/Movie.h @@ -26,6 +26,11 @@ #include "ChunkFile.h" +namespace WiimoteEmu +{ +struct ReportFeatures; +} + // Per-(video )Movie actions namespace Movie { @@ -127,12 +132,12 @@ void FrameSkipping(); bool BeginRecordingInput(int controllers); void RecordInput(SPADStatus *PadStatus, int controllerID); -void RecordWiimote(int wiimote, u8* data, s8 size, u8* const coreData, u8* const accelData, u8* const irData); +void RecordWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int irMode); bool PlayInput(const char *filename); void LoadInput(const char *filename); void PlayController(SPADStatus *PadStatus, int controllerID); -bool PlayWiimote(int wiimote, u8* data, s8 &size, u8* const coreData, u8* const accelData, u8* const irData); +bool PlayWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int irMode); void EndPlayInput(bool cont); void SaveRecording(const char *filename); void DoState(PointerWrap &p, bool doNot=false);