diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 970824a026..9d495f8d02 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -900,11 +900,11 @@ void UpdateTitle() if (Movie::IsPlayingInput()) SFPS = StringFromFormat("Input: %u/%u - VI: %u - FPS: %.0f - VPS: %.0f - %.0f%%", - (u32)Movie::g_currentInputCount, (u32)Movie::g_totalInputCount, - (u32)Movie::g_currentFrame, FPS, VPS, Speed); + (u32)Movie::GetCurrentInputCount(), (u32)Movie::GetTotalInputCount(), + (u32)Movie::GetCurrentFrame(), FPS, VPS, Speed); else if (Movie::IsRecordingInput()) SFPS = StringFromFormat("Input: %u - VI: %u - FPS: %.0f - VPS: %.0f - %.0f%%", - (u32)Movie::g_currentInputCount, (u32)Movie::g_currentFrame, FPS, VPS, + (u32)Movie::GetCurrentInputCount(), (u32)Movie::GetCurrentFrame(), FPS, VPS, Speed); else { diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp index 6f28ba1fef..24e74618b3 100644 --- a/Source/Core/Core/HW/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVDInterface.cpp @@ -492,7 +492,6 @@ void ChangeDiscAsCPU(const std::string& newFileName) CoreTiming::ScheduleEvent(500000000, s_insert_disc, (u64)_FileName); if (Movie::IsRecordingInput()) { - Movie::g_bDiscChange = true; std::string fileName = newFileName; auto sizeofpath = fileName.find_last_of("/\\") + 1; if (fileName.substr(sizeofpath).length() > 40) @@ -501,7 +500,7 @@ void ChangeDiscAsCPU(const std::string& newFileName) "The filename of the disc image must not be longer than 40 characters.", newFileName.c_str()); } - Movie::g_discChange = fileName.substr(sizeofpath); + Movie::SignalDiscChange(fileName.substr(sizeofpath)); } } diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp index a76d304357..5392f9bbbb 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -1147,15 +1147,15 @@ u32 CWII_IPC_HLE_Device_es::ES_DIVerify(const std::vector& tmd) File::CreateFullPath(tmd_path); File::CreateFullPath(Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT)); - Movie::g_titleID = tmd_title_id; + Movie::SetTitleId(tmd_title_id); std::string save_path = Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT); if (Movie::IsRecordingInput()) { // TODO: Check for the actual save data if (File::Exists(save_path + "banner.bin")) - Movie::g_bClearSave = false; + Movie::SetClearSave(false); else - Movie::g_bClearSave = true; + Movie::SetClearSave(true); } // TODO: Force the game to save to another location, instead of moving the user's save. diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 7e00f9a3cd..5a33bd69bc 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -61,10 +61,10 @@ static DTMHeader tmpHeader; static u8* tmpInput = nullptr; static size_t tmpInputAllocated = 0; static u64 s_currentByte = 0, s_totalBytes = 0; -u64 g_currentFrame = 0, g_totalFrames = 0; // VI -u64 g_currentLagCount = 0; +static u64 s_currentFrame = 0, s_totalFrames = 0; // VI +static u64 s_currentLagCount = 0; static u64 s_totalLagCount = 0; // just stats -u64 g_currentInputCount = 0, g_totalInputCount = 0; // just stats +static u64 s_currentInputCount = 0, s_totalInputCount = 0; // just stats static u64 s_totalTickCount = 0, s_tickCountAtLastInput = 0; // just stats static u64 s_recordingStartTime; // seconds since 1970 that recording started static bool s_bSaveConfig = false, s_bSkipIdle = false, s_bDualCore = false; @@ -73,12 +73,12 @@ static bool s_bDSPHLE = false, s_bFastDiscSpeed = false; static bool s_bSyncGPU = false, s_bNetPlay = false; static std::string s_videoBackend = "unknown"; static int s_iCPUCore = 1; -bool g_bClearSave = false; -bool g_bDiscChange = false; -bool g_bReset = false; +static bool s_bClearSave = false; +static bool s_bDiscChange = false; +static bool s_bReset = false; static std::string s_author = ""; -std::string g_discChange = ""; -u64 g_titleID = 0; +static std::string s_discChange = ""; +static u64 s_titleID = 0; static u8 s_MD5[16]; static u8 s_bongos, s_memcards; static u8 s_revision[20]; @@ -196,14 +196,14 @@ void FrameUpdate() { // TODO[comex]: This runs on the GPU thread, yet it messes with the CPU // state directly. That's super sketchy. - g_currentFrame++; + s_currentFrame++; if (!s_bPolled) - g_currentLagCount++; + s_currentLagCount++; if (IsRecordingInput()) { - g_totalFrames = g_currentFrame; - s_totalLagCount = g_currentLagCount; + s_totalFrames = s_currentFrame; + s_totalLagCount = s_currentLagCount; } if (s_bFrameStep) { @@ -260,19 +260,19 @@ void Init() s_bRecordingFromSaveState = false; s_rerecords = 0; s_currentByte = 0; - g_currentFrame = 0; - g_currentLagCount = 0; - g_currentInputCount = 0; + s_currentFrame = 0; + s_currentLagCount = 0; + s_currentInputCount = 0; } } // NOTE: CPU Thread void InputUpdate() { - g_currentInputCount++; + s_currentInputCount++; if (IsRecordingInput()) { - g_totalInputCount = g_currentInputCount; + s_totalInputCount = s_currentInputCount; s_totalTickCount += CoreTiming::GetTicks() - s_tickCountAtLastInput; s_tickCountAtLastInput = CoreTiming::GetTicks(); } @@ -352,12 +352,12 @@ bool IsRecordingInputFromSaveState() bool IsJustStartingRecordingInputFromSaveState() { - return IsRecordingInputFromSaveState() && g_currentFrame == 0; + return IsRecordingInputFromSaveState() && s_currentFrame == 0; } bool IsJustStartingPlayingInputFromSaveState() { - return IsRecordingInputFromSaveState() && g_currentFrame == 1 && IsPlayingInput(); + return IsRecordingInputFromSaveState() && s_currentFrame == 1 && IsPlayingInput(); } bool IsPlayingInput() @@ -380,6 +380,57 @@ u64 GetRecordingStartTime() return s_recordingStartTime; } +u64 GetCurrentFrame() +{ + return s_currentFrame; +} + +u64 GetTotalFrames() +{ + return s_totalFrames; +} + +u64 GetCurrentInputCount() +{ + return s_currentInputCount; +} + +u64 GetTotalInputCount() +{ + return s_totalInputCount; +} + +u64 GetCurrentLagCount() +{ + return s_currentLagCount; +} + +u64 GetTotalLagCount() +{ + return s_totalLagCount; +} + +void SetClearSave(bool enabled) +{ + s_bClearSave = enabled; +} + +void SignalDiscChange(const std::string& new_disc_filename) +{ + s_discChange = new_disc_filename; + s_bDiscChange = true; +} + +void SetReset(bool reset) +{ + s_bReset = reset; +} + +void SetTitleId(u64 title_id) +{ + s_titleID = title_id; +} + bool IsUsingPad(int controller) { return ((s_numPads & (1 << controller)) != 0); @@ -441,7 +492,7 @@ u8 GetLanguage() bool IsStartingFromClearSave() { - return g_bClearSave; + return s_bClearSave; } bool IsUsingMemcard(int memcard) @@ -520,9 +571,9 @@ bool BeginRecordingInput(int controllers) bool was_unpaused = Core::PauseAndLock(true); s_numPads = controllers; - g_currentFrame = g_totalFrames = 0; - g_currentLagCount = s_totalLagCount = 0; - g_currentInputCount = g_totalInputCount = 0; + s_currentFrame = s_totalFrames = 0; + s_currentLagCount = s_totalLagCount = 0; + s_currentInputCount = s_totalInputCount = 0; s_totalTickCount = s_tickCountAtLastInput = 0; s_bongos = 0; s_memcards = 0; @@ -560,11 +611,11 @@ bool BeginRecordingInput(int controllers) // TODO: find a way to GetTitleDataPath() from Movie::Init() if (SConfig::GetInstance().bWii) { - if (File::Exists(Common::GetTitleDataPath(g_titleID, Common::FROM_SESSION_ROOT) + + if (File::Exists(Common::GetTitleDataPath(s_titleID, Common::FROM_SESSION_ROOT) + "banner.bin")) - Movie::g_bClearSave = false; + Movie::s_bClearSave = false; else - Movie::g_bClearSave = true; + Movie::s_bClearSave = true; } std::thread md5thread(GetMD5); md5thread.detach(); @@ -832,10 +883,10 @@ void CheckPadStatus(GCPadStatus* PadStatus, int controllerID) s_padState.CStickX = PadStatus->substickX; s_padState.CStickY = PadStatus->substickY; - s_padState.disc = g_bDiscChange; - g_bDiscChange = false; - s_padState.reset = g_bReset; - g_bReset = false; + s_padState.disc = s_bDiscChange; + s_bDiscChange = false; + s_padState.reset = s_bReset; + s_bReset = false; SetInputDisplayString(s_padState, controllerID); } @@ -895,7 +946,7 @@ void ReadHeader() s_bDSPHLE = tmpHeader.bDSPHLE; s_bFastDiscSpeed = tmpHeader.bFastDiscSpeed; s_iCPUCore = tmpHeader.CPUCore; - g_bClearSave = tmpHeader.bClearSave; + s_bClearSave = tmpHeader.bClearSave; s_memcards = tmpHeader.memcards; s_bongos = tmpHeader.bongos; s_bSyncGPU = tmpHeader.bSyncGPU; @@ -909,7 +960,7 @@ void ReadHeader() } s_videoBackend = (char*)tmpHeader.videoBackend; - g_discChange = (char*)tmpHeader.discChange; + s_discChange = (char*)tmpHeader.discChange; s_author = (char*)tmpHeader.author; memcpy(s_MD5, tmpHeader.md5, 16); s_DSPiromHash = tmpHeader.DSPiromHash; @@ -940,13 +991,13 @@ bool PlayInput(const std::string& filename) } ReadHeader(); - g_totalFrames = tmpHeader.frameCount; + s_totalFrames = tmpHeader.frameCount; s_totalLagCount = tmpHeader.lagCount; - g_totalInputCount = tmpHeader.inputCount; + s_totalInputCount = tmpHeader.inputCount; s_totalTickCount = tmpHeader.tickCount; - g_currentFrame = 0; - g_currentLagCount = 0; - g_currentInputCount = 0; + s_currentFrame = 0; + s_currentLagCount = 0; + s_currentInputCount = 0; s_playMode = MODE_PLAYING; @@ -978,13 +1029,13 @@ void DoState(PointerWrap& p) { // many of these could be useful to save even when no movie is active, // and the data is tiny, so let's just save it regardless of movie state. - p.Do(g_currentFrame); + p.Do(s_currentFrame); p.Do(s_currentByte); - p.Do(g_currentLagCount); - p.Do(g_currentInputCount); + p.Do(s_currentLagCount); + p.Do(s_currentInputCount); p.Do(s_bPolled); p.Do(s_tickCountAtLastInput); - // other variables (such as s_totalBytes and g_totalFrames) are set in LoadInput + // other variables (such as s_totalBytes and s_totalFrames) are set in LoadInput } // NOTE: Host Thread @@ -1028,15 +1079,15 @@ void LoadInput(const std::string& filename) PanicAlertT("Warning: You loaded a save whose movie ends before the current frame in the save " "(byte %u < %u) (frame %u < %u). You should load another save before continuing.", (u32)totalSavedBytes + 256, (u32)s_currentByte + 256, (u32)tmpHeader.frameCount, - (u32)g_currentFrame); + (u32)s_currentFrame); afterEnd = true; } if (!s_bReadOnly || tmpInput == nullptr) { - g_totalFrames = tmpHeader.frameCount; + s_totalFrames = tmpHeader.frameCount; s_totalLagCount = tmpHeader.lagCount; - g_totalInputCount = tmpHeader.inputCount; + s_totalInputCount = tmpHeader.inputCount; s_totalTickCount = s_tickCountAtLastInput = tmpHeader.tickCount; EnsureTmpInputSize((size_t)totalSavedBytes); @@ -1054,8 +1105,8 @@ void LoadInput(const std::string& filename) PanicAlertT("Warning: You loaded a save that's after the end of the current movie. (byte %u " "> %u) (input %u > %u). You should load another save before continuing, or load " "this state with read-only mode off.", - (u32)s_currentByte + 256, (u32)s_totalBytes + 256, (u32)g_currentInputCount, - (u32)g_totalInputCount); + (u32)s_currentByte + 256, (u32)s_totalBytes + 256, (u32)s_currentInputCount, + (u32)s_totalInputCount); } else if (s_currentByte > 0 && s_totalBytes > 0) { @@ -1104,7 +1155,7 @@ void LoadInput(const std::string& filename) "On frame %td, the savestate's movie presses:\n" "Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, " "L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d", - frame, (int)g_totalFrames, (int)tmpHeader.frameCount, frame, (int)curPadState.Start, + frame, (int)s_totalFrames, (int)tmpHeader.frameCount, frame, (int)curPadState.Start, (int)curPadState.A, (int)curPadState.B, (int)curPadState.X, (int)curPadState.Y, (int)curPadState.Z, (int)curPadState.DPadUp, (int)curPadState.DPadDown, (int)curPadState.DPadLeft, (int)curPadState.DPadRight, (int)curPadState.L, @@ -1237,7 +1288,7 @@ void PlayController(GCPadStatus* PadStatus, int controllerID) std::string path; for (const std::string& iso_folder : SConfig::GetInstance().m_ISOFolder) { - path = iso_folder + '/' + g_discChange; + path = iso_folder + '/' + s_discChange; if (File::Exists(path)) { found = true; @@ -1251,7 +1302,7 @@ void PlayController(GCPadStatus* PadStatus, int controllerID) else { CPU::Break(); - PanicAlertT("Change the disc to %s", g_discChange.c_str()); + PanicAlertT("Change the disc to %s", s_discChange.c_str()); } } @@ -1305,7 +1356,7 @@ bool PlayWiimote(int wiimote, u8* data, const WiimoteEmu::ReportFeatures& rptf, memcpy(data, &(tmpInput[s_currentByte]), size); s_currentByte += size; - g_currentInputCount++; + s_currentInputCount++; CheckInputEnd(); return true; @@ -1332,7 +1383,7 @@ void EndPlayInput(bool cont) s_bRecordingFromSaveState = false; // we don't clear these things because otherwise we can't resume playback if we load a movie // state later - // g_totalFrames = s_totalBytes = 0; + // s_totalFrames = s_totalBytes = 0; // delete tmpInput; // tmpInput = nullptr; @@ -1361,9 +1412,9 @@ void SaveRecording(const std::string& filename) header.numControllers = s_numPads & (SConfig::GetInstance().bWii ? 0xFF : 0x0F); header.bFromSaveState = s_bRecordingFromSaveState; - header.frameCount = g_totalFrames; + header.frameCount = s_totalFrames; header.lagCount = s_totalLagCount; - header.inputCount = g_totalInputCount; + header.inputCount = s_totalInputCount; header.numRerecords = s_rerecords; header.recordingStartTime = s_recordingStartTime; @@ -1384,10 +1435,10 @@ void SaveRecording(const std::string& filename) header.bUseXFB = g_ActiveConfig.bUseXFB; header.bUseRealXFB = g_ActiveConfig.bUseRealXFB; header.memcards = s_memcards; - header.bClearSave = g_bClearSave; + header.bClearSave = s_bClearSave; header.bSyncGPU = s_bSyncGPU; header.bNetPlay = s_bNetPlay; - strncpy((char*)header.discChange, g_discChange.c_str(), ArraySize(header.discChange)); + strncpy((char*)header.discChange, s_discChange.c_str(), ArraySize(header.discChange)); strncpy((char*)header.author, s_author.c_str(), ArraySize(header.author)); memcpy(header.md5, s_MD5, 16); header.bongos = s_bongos; @@ -1466,7 +1517,7 @@ void GetSettings() s_bNetPlay = NetPlay::IsNetPlayRunning(); s_language = SConfig::GetInstance().m_SYSCONF->GetData("IPL.LNG"); if (!SConfig::GetInstance().bWii) - g_bClearSave = !File::Exists(SConfig::GetInstance().m_strMemoryCardA); + s_bClearSave = !File::Exists(SConfig::GetInstance().m_strMemoryCardA); s_memcards |= (SConfig::GetInstance().m_EXIDevice[0] == EXIDEVICE_MEMORYCARD) << 0; s_memcards |= (SConfig::GetInstance().m_EXIDevice[1] == EXIDEVICE_MEMORYCARD) << 1; @@ -1543,7 +1594,7 @@ void GetMD5() // NOTE: EmuThread void Shutdown() { - g_currentInputCount = g_totalInputCount = g_totalFrames = s_totalBytes = s_tickCountAtLastInput = + s_currentInputCount = s_totalInputCount = s_totalFrames = s_totalBytes = s_tickCountAtLastInput = 0; delete[] tmpInput; tmpInput = nullptr; diff --git a/Source/Core/Core/Movie.h b/Source/Core/Core/Movie.h index c7b9d8c5a6..8bb31461e3 100644 --- a/Source/Core/Core/Movie.h +++ b/Source/Core/Core/Movie.h @@ -48,15 +48,6 @@ struct ControllerState static_assert(sizeof(ControllerState) == 8, "ControllerState should be 8 bytes"); #pragma pack(pop) -// Global declarations -extern bool g_bDiscChange, g_bClearSave, g_bReset; -extern u64 g_titleID; - -extern u64 g_currentFrame, g_totalFrames; -extern u64 g_currentLagCount; -extern u64 g_currentInputCount, g_totalInputCount; -extern std::string g_discChange; - #pragma pack(push, 1) struct DTMHeader { @@ -130,6 +121,18 @@ bool IsMovieActive(); bool IsReadOnly(); u64 GetRecordingStartTime(); +u64 GetCurrentFrame(); +u64 GetTotalFrames(); +u64 GetCurrentInputCount(); +u64 GetTotalInputCount(); +u64 GetCurrentLagCount(); +u64 GetTotalLagCount(); + +void SetClearSave(bool enabled); +void SignalDiscChange(const std::string& new_disc_filename); +void SetReset(bool reset); +void SetTitleId(u64 title_id); + bool IsConfigSaved(); bool IsDualCore(); bool IsProgressive(); diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 012e9c1209..8f4383eb69 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -220,7 +220,7 @@ void MainWindow::ForceStop() void MainWindow::Reset() { if (Movie::IsRecordingInput()) - Movie::g_bReset = true; + Movie::SetReset(true); ProcessorInterface::ResetButton_Tap(); } diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index b3689e9ab5..290ebeb83e 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -1294,7 +1294,7 @@ void CFrame::OnStop(wxCommandEvent& WXUNUSED(event)) void CFrame::OnReset(wxCommandEvent& WXUNUSED(event)) { if (Movie::IsRecordingInput()) - Movie::g_bReset = true; + Movie::SetReset(true); ProcessorInterface::ResetButton_Tap(); } diff --git a/Source/Core/DolphinWX/TASInputDlg.cpp b/Source/Core/DolphinWX/TASInputDlg.cpp index f732f65871..2dba37f563 100644 --- a/Source/Core/DolphinWX/TASInputDlg.cpp +++ b/Source/Core/DolphinWX/TASInputDlg.cpp @@ -1106,11 +1106,11 @@ void TASInputDlg::SetTurbo(wxMouseEvent& event) // NOTE: Host / CPU Thread void TASInputDlg::ButtonTurbo() { - static u64 frame = Movie::g_currentFrame; + static u64 frame = Movie::GetCurrentFrame(); - if (frame != Movie::g_currentFrame) + if (frame != Movie::GetCurrentFrame()) { - frame = Movie::g_currentFrame; + frame = Movie::GetCurrentFrame(); for (Button* const button : m_buttons) { if (button != nullptr && button->turbo_on) diff --git a/Source/Core/VideoCommon/AVIDump.cpp b/Source/Core/VideoCommon/AVIDump.cpp index c0a2613ea5..708c943822 100644 --- a/Source/Core/VideoCommon/AVIDump.cpp +++ b/Source/Core/VideoCommon/AVIDump.cpp @@ -204,7 +204,7 @@ void AVIDump::AddFrame(const u8* data, int width, int height) // Check to see if the first frame being dumped is the first frame of output from the emulator. // This prevents an issue with starting dumping later in emulation from placing the frames // incorrectly. - if (!s_start_dumping && Movie::g_currentFrame < 1) + if (!s_start_dumping && Movie::GetCurrentFrame() < 1) { delta = CoreTiming::GetTicks(); last_pts = AV_NOPTS_VALUE; diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index baddf67867..a8911a7cdd 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -310,11 +310,11 @@ void Renderer::DrawDebugText() final_cyan += " - "; if (SConfig::GetInstance().m_ShowFrameCount) { - final_cyan += StringFromFormat("Frame: %llu", (unsigned long long)Movie::g_currentFrame); + final_cyan += StringFromFormat("Frame: %llu", (unsigned long long)Movie::GetCurrentFrame()); if (Movie::IsPlayingInput()) final_cyan += - StringFromFormat("\nInput: %llu / %llu", (unsigned long long)Movie::g_currentInputCount, - (unsigned long long)Movie::g_totalInputCount); + StringFromFormat("\nInput: %llu / %llu", (unsigned long long)Movie::GetCurrentInputCount(), + (unsigned long long)Movie::GetTotalInputCount()); } final_cyan += "\n"; @@ -323,7 +323,7 @@ void Renderer::DrawDebugText() if (SConfig::GetInstance().m_ShowLag) { - final_cyan += StringFromFormat("Lag: %" PRIu64 "\n", Movie::g_currentLagCount); + final_cyan += StringFromFormat("Lag: %" PRIu64 "\n", Movie::GetCurrentLagCount()); final_yellow += "\n"; }