From aece5310f34ec17c967e62b73ec3c0616ba9298d Mon Sep 17 00:00:00 2001 From: rog Date: Sun, 21 Oct 2012 17:48:45 -0400 Subject: [PATCH] more movie cleanup. Removes the remaining globals that didn't need to be global, rearranges some code to make more sense, and removes some redundant code. --- Source/Core/Core/Src/BootManager.cpp | 2 +- Source/Core/Core/Src/Core.cpp | 2 +- .../Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp | 2 +- Source/Core/Core/Src/Movie.cpp | 83 +++++++++++-------- Source/Core/Core/Src/Movie.h | 8 +- 5 files changed, 55 insertions(+), 42 deletions(-) diff --git a/Source/Core/Core/Src/BootManager.cpp b/Source/Core/Core/Src/BootManager.cpp index 709053a5e2..187baf415c 100644 --- a/Source/Core/Core/Src/BootManager.cpp +++ b/Source/Core/Core/Src/BootManager.cpp @@ -124,7 +124,7 @@ bool BootCore(const std::string& _rFilename) StartUp.bDSPHLE = Movie::IsDSPHLE(); StartUp.bProgressive = Movie::IsProgressive(); StartUp.bFastDiscSpeed = Movie::IsFastDiscSpeed(); - if (Movie::g_bMemcard && Movie::g_bBlankMC) + if (Movie::IsUsingMemcard() && Movie::IsBlankMemcard()) { if (File::Exists("Movie.raw")) File::Delete("Movie.raw"); diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index da9b5795fa..d3c9fb7033 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -434,7 +434,7 @@ void EmuThread() CBoot::BootUp(); // Setup our core, but can't use dynarec if we are compare server - if (Movie::g_CPUCore && (!_CoreParameter.bRunCompareServer || + if (Movie::GetCPUMode() && (!_CoreParameter.bRunCompareServer || _CoreParameter.bRunCompareClient)) PowerPC::SetMode(PowerPC::MODE_JIT); else diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp index 106e41b16c..f65d8c6b8b 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp @@ -52,7 +52,7 @@ CEXIMemoryCard::CEXIMemoryCard(const int index) , m_bDirty(false) { m_strFilename = (card_index == 0) ? SConfig::GetInstance().m_strMemoryCardA : SConfig::GetInstance().m_strMemoryCardB; - if (Movie::g_bMemcard && Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::g_bBlankMC) + if (Movie::IsUsingMemcard() && Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsBlankMemcard()) m_strFilename = "Movie.raw"; // we're potentially leaking events here, since there's no UnregisterEvent until emu shutdown, but I guess it's inconsequential diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index e17190e1c5..4c142a5820 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -66,10 +66,10 @@ bool bDualCore = false; bool bProgressive = false; bool bDSPHLE = false; bool bFastDiscSpeed = false; -std::string g_videoBackend = "opengl"; -int g_CPUCore = 1; -bool g_bMemcard; -bool g_bBlankMC = false; +std::string videoBackend = "opengl"; +int iCPUCore = 1; +bool bMemcard; +bool bBlankMC = false; bool g_bDiscChange = false; std::string g_discChange = ""; std::string author = ""; @@ -138,7 +138,7 @@ void Init() } g_frameSkipCounter = g_framesToSkip; memset(&g_padState, 0, sizeof(g_padState)); - if (!tmpHeader.bFromSaveState) + if (!tmpHeader.bFromSaveState || !IsPlayingInput()) Core::SetStateFileName(""); for (int i = 0; i < 8; ++i) g_InputDisplay[i].clear(); @@ -245,7 +245,7 @@ bool IsJustStartingRecordingInputFromSaveState() bool IsJustStartingPlayingInputFromSaveState() { - return tmpHeader.bFromSaveState && g_currentFrame == 1; + return IsRecordingInputFromSaveState() && g_currentFrame == 1 && IsPlayingInput(); } bool IsPlayingInput() @@ -304,7 +304,17 @@ bool IsFastDiscSpeed() int GetCPUMode() { - return g_CPUCore; + return iCPUCore; +} + +bool IsBlankMemcard() +{ + return bBlankMC; +} + +bool IsUsingMemcard() +{ + return bMemcard; } void ChangePads(bool instantly) @@ -374,8 +384,9 @@ bool BeginRecordingInput(int controllers) bProgressive = SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive; bDSPHLE = SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE; bFastDiscSpeed = SConfig::GetInstance().m_LocalCoreStartupParameter.bFastDiscSpeed; - g_videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend; - g_CPUCore = SConfig::GetInstance().m_LocalCoreStartupParameter.iCPUCore; + videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend; + iCPUCore = SConfig::GetInstance().m_LocalCoreStartupParameter.iCPUCore; + bBlankMC = !File::Exists(SConfig::GetInstance().m_strMemoryCardA); delete [] tmpInput; tmpInput = new u8[MAX_DTM_LENGTH]; @@ -604,7 +615,7 @@ void ReadHeader() { g_numPads = tmpHeader.numControllers; g_recordingStartTime = tmpHeader.recordingStartTime; - if (g_rerecords < tmpHeader.numRerecords); + if (g_rerecords < tmpHeader.numRerecords) g_rerecords = tmpHeader.numRerecords; if (tmpHeader.bSaveConfig) @@ -615,24 +626,26 @@ void ReadHeader() bProgressive = tmpHeader.bProgressive; bDSPHLE = tmpHeader.bDSPHLE; bFastDiscSpeed = tmpHeader.bFastDiscSpeed; - g_CPUCore = tmpHeader.CPUCore; + iCPUCore = tmpHeader.CPUCore; + bBlankMC = tmpHeader.bBlankMC; } else { - bSaveConfig = true; + bSaveConfig = false; bSkipIdle = SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle; bDualCore = SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread; bProgressive = SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive; bDSPHLE = SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE; bFastDiscSpeed = SConfig::GetInstance().m_LocalCoreStartupParameter.bFastDiscSpeed; - g_videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend; + videoBackend = SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend; + bBlankMC = !File::Exists(SConfig::GetInstance().m_strMemoryCardA); } - g_videoBackend.resize(ARRAYSIZE(tmpHeader.videoBackend)); + videoBackend.resize(ARRAYSIZE(tmpHeader.videoBackend)); for (int i = 0; i < ARRAYSIZE(tmpHeader.videoBackend);i++) { - g_videoBackend[i] = tmpHeader.videoBackend[i]; + videoBackend[i] = tmpHeader.videoBackend[i]; } g_discChange.resize(ARRAYSIZE(tmpHeader.discChange)); @@ -655,19 +668,19 @@ bool PlayInput(const char *filename) if(!File::Exists(filename)) return false; - + File::IOFile g_recordfd; - + if (!g_recordfd.Open(filename, "rb")) return false; - + g_recordfd.ReadArray(&tmpHeader, 1); if(tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A) { PanicAlertT("Invalid recording file"); goto cleanup; } - + // Load savestate (and skip to frame data) if(tmpHeader.bFromSaveState) { @@ -676,16 +689,15 @@ bool PlayInput(const char *filename) Core::SetStateFileName(stateFilename); g_bRecordingFromSaveState = true; Movie::LoadInput(filename); - g_currentFrame = 0; } - + /* TODO: Put this verification somewhere we have the gameID of the played game // TODO: Replace with Unique ID if(tmpHeader.uniqueID != 0) { PanicAlert("Recording Unique ID Verification Failed"); goto cleanup; } - + if(strncmp((char *)tmpHeader.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6)) { PanicAlert("The recorded game (%s) is not the same as the selected game (%s)", header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str()); goto cleanup; @@ -708,9 +720,9 @@ bool PlayInput(const char *filename) g_recordfd.ReadArray(tmpInput, (size_t)g_totalBytes); g_currentByte = 0; g_recordfd.Close(); - + return true; - + cleanup: g_recordfd.Close(); return false; @@ -736,7 +748,7 @@ void LoadInput(const char *filename) File::IOFile t_record(filename, "r+b"); t_record.ReadArray(&tmpHeader, 1); - + if(tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A) { PanicAlertT("Savestate movie %s is corrupted, movie recording stopping...", filename); @@ -871,7 +883,12 @@ static void CheckInputEnd() void PlayController(SPADStatus *PadStatus, int controllerID) { - if (IsPlayingInput() && IsConfigSaved()) + // Correct playback is entirely dependent on the emulator polling the controllers + // in the same order done during recording + if (!IsPlayingInput() || !IsUsingPad(controllerID) || tmpInput == NULL) + return; + + if (IsConfigSaved()) { SetGraphicsConfig(); } @@ -886,10 +903,6 @@ void PlayController(SPADStatus *PadStatus, int controllerID) ExpansionInterface::ChangeDevice(0, EXIDEVICE_NONE, 0); } } - // Correct playback is entirely dependent on the emulator polling the controllers - // in the same order done during recording - if (!IsPlayingInput() || !IsUsingPad(controllerID) || tmpInput == NULL) - return; if (g_currentByte + 8 > g_totalBytes) { @@ -1044,7 +1057,7 @@ void EndPlayInput(bool cont) g_currentByte = 0; g_playMode = MODE_NONE; Core::DisplayMessage("Movie End.", 2000); - tmpHeader.bFromSaveState = 0; + g_bRecordingFromSaveState = 0; // we don't clear these things because otherwise we can't resume playback if we load a movie state later //g_totalFrames = g_totalBytes = 0; //delete tmpInput; @@ -1077,8 +1090,8 @@ void SaveRecording(const char *filename) header.bProgressive = bProgressive; header.bDSPHLE = bDSPHLE; header.bFastDiscSpeed = bFastDiscSpeed; - strncpy((char *)header.videoBackend, g_videoBackend.c_str(),ARRAYSIZE(header.videoBackend)); - header.CPUCore = g_CPUCore; + strncpy((char *)header.videoBackend, videoBackend.c_str(),ARRAYSIZE(header.videoBackend)); + header.CPUCore = iCPUCore; header.bEFBAccessEnable = g_ActiveConfig.bEFBAccessEnable; header.bEFBCopyEnable = g_ActiveConfig.bEFBCopyEnable; header.bCopyEFBToTexture = g_ActiveConfig.bCopyEFBToTexture; @@ -1086,8 +1099,8 @@ void SaveRecording(const char *filename) header.bEFBEmulateFormatChanges = g_ActiveConfig.bEFBEmulateFormatChanges; header.bUseXFB = g_ActiveConfig.bUseXFB; header.bUseRealXFB = g_ActiveConfig.bUseRealXFB; - header.bMemcard = g_bMemcard; - header.bBlankMC = g_bBlankMC; + header.bMemcard = bMemcard; + header.bBlankMC = bBlankMC; strncpy((char *)header.discChange, g_discChange.c_str(),ARRAYSIZE(header.discChange)); strncpy((char *)header.author, author.c_str(),ARRAYSIZE(header.author)); diff --git a/Source/Core/Core/Src/Movie.h b/Source/Core/Core/Src/Movie.h index 9ad69e6e64..94e63a9e2b 100644 --- a/Source/Core/Core/Src/Movie.h +++ b/Source/Core/Core/Src/Movie.h @@ -57,11 +57,11 @@ struct ControllerState { u8 CStickX, CStickY; // Sub-Stick, 16 bits }; // Total: 60 + 4 = 64 bits per frame +static_assert(sizeof(ControllerState) == 8, "ControllerState should be 8 bytes"); #pragma pack(pop) // Global declarations extern bool g_bFrameStep, g_bPolled, g_bReadOnly, g_bDiscChange; -extern bool g_bMemcard, g_bBlankMC; extern PlayMode g_playMode; extern u32 g_framesToSkip, g_frameSkipCounter; @@ -75,8 +75,6 @@ extern u64 g_currentByte, g_totalBytes; extern u64 g_currentFrame, g_totalFrames; extern u64 g_currentLagCount, g_totalLagCount; extern u64 g_currentInputCount, g_totalInputCount; -extern std::string g_videoBackend; -extern int g_CPUCore; extern std::string g_discChange; extern u32 g_rerecords; @@ -120,7 +118,7 @@ struct DTMHeader { bool bUseRealXFB; bool bMemcard; bool bBlankMC; // Create a new memory card when playing back a movie if true - u8 reserved[16]; + u8 reserved[16]; // Padding for any new config options u8 discChange[40]; // Name of iso file to switch to, for two disc games. u8 reserved2[47]; // Make heading 256 bytes, just because we can }; @@ -150,6 +148,8 @@ bool IsSkipIdle(); bool IsDSPHLE(); bool IsFastDiscSpeed(); int GetCPUMode(); +bool IsBlankMemcard(); +bool IsUsingMemcard(); void SetGraphicsConfig(); bool IsUsingPad(int controller);