diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 9dabfcd83d..ac87c611af 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -555,7 +555,7 @@ set(pcsx2RecordingHeaders ${rec_src}/InputRecordingFile.h ${rec_src}/NewRecordingFrame.h ${rec_src}/PadData.h - ${rec_src}/Utilities/InputRecordingLogger.h + ${rec_src}/Utilities/InputRecordingLogger.h ${rec_vp_src}/VirtualPad.h ${rec_vp_src}/VirtualPadData.h ${rec_vp_src}/VirtualPadResources.h diff --git a/pcsx2/Recording/InputRecording.cpp b/pcsx2/Recording/InputRecording.cpp index aeb8359398..ccb9c8b6cf 100644 --- a/pcsx2/Recording/InputRecording.cpp +++ b/pcsx2/Recording/InputRecording.cpp @@ -27,6 +27,7 @@ #include "InputRecording.h" #include "InputRecordingControls.h" +#include "Utilities/InputRecordingLogger.h" #endif @@ -221,7 +222,7 @@ void InputRecording::SetToRecordMode() state = InputRecordingMode::Recording; virtualPads[CONTROLLER_PORT_ONE]->SetReadOnlyMode(false); virtualPads[CONTROLLER_PORT_TWO]->SetReadOnlyMode(false); - recordingConLog("[REC]: Record mode ON.\n"); + inputRec::log("Record mode ON"); } void InputRecording::SetToReplayMode() @@ -229,15 +230,15 @@ void InputRecording::SetToReplayMode() state = InputRecordingMode::Replaying; virtualPads[CONTROLLER_PORT_ONE]->SetReadOnlyMode(true); virtualPads[CONTROLLER_PORT_TWO]->SetReadOnlyMode(true); - recordingConLog("[REC]: Replay mode ON.\n"); + inputRec::log("Replay mode ON"); } void InputRecording::SetFrameCounter(u32 newGFrameCount) { if (newGFrameCount > startingFrame + (u32)g_InputRecording.GetInputRecordingData().GetTotalFrames()) { - recordingConLog(L"[REC]: Warning, you've loaded PCSX2 emulation to a point after the end of the original recording. This should be avoided.\n"); - recordingConLog(L"[REC]: Savestate's framecount has been ignored.\n"); + inputRec::consoleLog("Warning, you've loaded PCSX2 emulation to a point after the end of the original recording. This should be avoided."); + inputRec::consoleLog("Savestate's framecount has been ignored."); frameCounter = g_InputRecording.GetInputRecordingData().GetTotalFrames(); if (state == InputRecordingMode::Replaying) SetToRecordMode(); @@ -247,7 +248,7 @@ void InputRecording::SetFrameCounter(u32 newGFrameCount) { if (newGFrameCount < startingFrame) { - recordingConLog(L"[REC]: Warning, you've loaded PCSX2 emulation to a point before the start of the original recording. This should be avoided.\n"); + inputRec::consoleLog("Warning, you've loaded PCSX2 emulation to a point before the start of the original recording. This should be avoided."); if (state == InputRecordingMode::Recording) SetToReplayMode(); } @@ -261,9 +262,8 @@ void InputRecording::SetFrameCounter(u32 newGFrameCount) void InputRecording::SetStartingFrame(u32 newStartingFrame) { startingFrame = newStartingFrame; - // TODO - make a function of my own to simplify working with the logging macros if (inputRecordingData.FromSaveState()) - recordingConLog(wxString::Format(L"[REC]: Internal Starting Frame: %d\n", startingFrame)); + inputRec::consoleLog(fmt::format("Internal Starting Frame: {}", startingFrame)); frameCounter = 0; initialLoad = false; g_InputRecordingControls.Lock(startingFrame); @@ -276,7 +276,7 @@ void InputRecording::Stop() virtualPads[CONTROLLER_PORT_TWO]->SetReadOnlyMode(false); incrementUndo = false; if (inputRecordingData.Close()) - recordingConLog(L"[REC]: InputRecording Recording Stopped.\n"); + inputRec::log("Input recording stopped"); } bool InputRecording::Create(wxString FileName, bool fromSaveState, wxString authorName) @@ -307,7 +307,8 @@ bool InputRecording::Create(wxString FileName, bool fromSaveState, wxString auth inputRecordingData.WriteHeader(); SetToRecordMode(); g_InputRecordingControls.DisableFrameAdvance(); - recordingConLog(wxString::Format(L"[REC]: Started new recording - [%s]\n", FileName)); + inputRec::log("Started new input recording"); + inputRec::consoleLog(fmt::format("Filename {}", std::string(FileName))); return true; } @@ -324,13 +325,13 @@ bool InputRecording::Play(wxString fileName) { if (!CoreThread.IsOpen()) { - recordingConLog(L"[REC]: Game is not open, aborting playing input recording which starts on a save-state.\n"); + inputRec::consoleLog("Game is not open, aborting playing input recording which starts on a save-state."); inputRecordingData.Close(); return false; } if (!wxFileExists(inputRecordingData.GetFilename() + "_SaveState.p2s")) { - recordingConLog(wxString::Format("[REC]: Could not locate savestate file at location - %s_SaveState.p2s\n", + inputRec::consoleLog(fmt::format("Could not locate savestate file at location - {}_SaveState.p2s", inputRecordingData.GetFilename())); inputRecordingData.Close(); return false; @@ -347,18 +348,19 @@ bool InputRecording::Play(wxString fileName) // Check if the current game matches with the one used to make the original recording if (!g_Conf->CurrentIso.IsEmpty()) if (resolveGameName() != inputRecordingData.GetHeader().gameName) - recordingConLog(L"[REC]: Recording was possibly constructed for a different game.\n"); + inputRec::consoleLog("Input recording was possibly constructed for a different game."); incrementUndo = true; SetToReplayMode(); + inputRec::log("Playing input recording"); g_InputRecordingControls.DisableFrameAdvance(); - recordingConLog(wxString::Format(L"[REC]: Replaying input recording - [%s]\n", inputRecordingData.GetFilename())); - recordingConLog(wxString::Format(L"[REC]: PCSX2 Version Used: %s\n", inputRecordingData.GetHeader().emu)); - recordingConLog(wxString::Format(L"[REC]: Recording File Version: %d\n", inputRecordingData.GetHeader().version)); - recordingConLog(wxString::Format(L"[REC]: Associated Game Name or ISO Filename: %s\n", inputRecordingData.GetHeader().gameName)); - recordingConLog(wxString::Format(L"[REC]: Author: %s\n", inputRecordingData.GetHeader().author)); - recordingConLog(wxString::Format(L"[REC]: Total Frames: %d\n", inputRecordingData.GetTotalFrames())); - recordingConLog(wxString::Format(L"[REC]: Undo Count: %d\n", inputRecordingData.GetUndoCount())); + inputRec::consoleMultiLog({fmt::format("Replaying input recording - [{}]", std::string(inputRecordingData.GetFilename())), + fmt::format("PCSX2 Version Used: {}", std::string(inputRecordingData.GetHeader().emu)), + fmt::format("Recording File Version: {}", inputRecordingData.GetHeader().version), + fmt::format("Associated Game Name or ISO Filename: {}", std::string(inputRecordingData.GetHeader().gameName)), + fmt::format("Author: {}", inputRecordingData.GetHeader().author), + fmt::format("Total Frames: {}", inputRecordingData.GetTotalFrames()), + fmt::format("Undo Count: {}", inputRecordingData.GetUndoCount())}); return true; } diff --git a/pcsx2/Recording/InputRecordingControls.cpp b/pcsx2/Recording/InputRecordingControls.cpp index 7054426576..d764ba8b1e 100644 --- a/pcsx2/Recording/InputRecordingControls.cpp +++ b/pcsx2/Recording/InputRecordingControls.cpp @@ -25,7 +25,7 @@ #include "InputRecording.h" #include "InputRecordingControls.h" - +#include "Utilities/InputRecordingLogger.h" InputRecordingControls g_InputRecordingControls; @@ -43,7 +43,7 @@ void InputRecordingControls::HandleFrameAdvanceAndPausing() if (g_FrameCount == frameCountTracker) { frameLock = false; - g_InputRecordingControls.Resume(); + Resume(); } else if (!emulationCurrentlyPaused && CoreThread.IsOpen() && CoreThread.IsRunning()) { @@ -62,7 +62,7 @@ void InputRecordingControls::HandleFrameAdvanceAndPausing() frameCountTracker = g_FrameCount; if (g_InputRecording.GetFrameCounter() < INT_MAX) g_InputRecording.IncrementFrameCounter(); - } + } else { if (pauseEmulation) @@ -79,17 +79,18 @@ void InputRecordingControls::HandleFrameAdvanceAndPausing() switchToReplay = false; } - if ((g_InputRecording.IsReplaying() && g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) - || g_InputRecording.GetFrameCounter() == INT_MAX) + if ((g_InputRecording.IsReplaying() && + g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) || + g_InputRecording.GetFrameCounter() == INT_MAX) pauseEmulation = true; // If we haven't yet advanced atleast a single frame from when we paused, setup things to be paused - if (frameAdvancing && frameAdvanceMarker < g_InputRecording.GetFrameCounter()) + if (frameAdvancing && frameAdvanceMarker < g_InputRecording.GetFrameCounter()) { frameAdvancing = false; pauseEmulation = true; } - + // Pause emulation if we need to (either due to frame advancing, or pause has been explicitly toggled on) if (pauseEmulation && CoreThread.IsOpen() && CoreThread.IsRunning()) { @@ -110,8 +111,8 @@ void InputRecordingControls::ResumeCoreThreadIfStarted() void InputRecordingControls::FrameAdvance() { - if (g_InputRecording.IsReplaying() - && g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) + if (g_InputRecording.IsReplaying() && + g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) { g_InputRecording.SetToRecordMode(); return; @@ -151,8 +152,8 @@ void InputRecordingControls::PauseImmediately() void InputRecordingControls::Resume() { - if (g_InputRecording.IsReplaying() - && g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) + if (g_InputRecording.IsReplaying() && + g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) { g_InputRecording.SetToRecordMode(); return; @@ -173,20 +174,23 @@ void InputRecordingControls::DisableFrameAdvance() void InputRecordingControls::TogglePause() { - if (pauseEmulation && g_InputRecording.IsReplaying() - && g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) + if (pauseEmulation && + g_InputRecording.IsReplaying() && + g_InputRecording.GetFrameCounter() >= g_InputRecording.GetInputRecordingData().GetTotalFrames()) { g_InputRecording.SetToRecordMode(); return; } pauseEmulation = !pauseEmulation; resumeEmulation = !pauseEmulation; + inputRec::log(pauseEmulation ? "Paused Emulation" : "Resumed Emulation"); } void InputRecordingControls::RecordModeToggle() { - if (IsPaused() || g_InputRecording.IsReplaying() - || g_InputRecording.GetFrameCounter() < g_InputRecording.GetInputRecordingData().GetTotalFrames()) + if (IsPaused() || + g_InputRecording.IsReplaying() || + g_InputRecording.GetFrameCounter() < g_InputRecording.GetInputRecordingData().GetTotalFrames()) { if (g_InputRecording.IsReplaying()) g_InputRecording.SetToRecordMode(); diff --git a/pcsx2/Recording/InputRecordingFile.cpp b/pcsx2/Recording/InputRecordingFile.cpp index 11fed6e179..2342e33eff 100644 --- a/pcsx2/Recording/InputRecordingFile.cpp +++ b/pcsx2/Recording/InputRecordingFile.cpp @@ -21,7 +21,8 @@ #include "MainFrame.h" #include "MemoryTypes.h" -#include "Recording/InputRecordingFile.h" +#include "InputRecordingFile.h" +#include "Utilities/InputRecordingLogger.h" void InputRecordingFileHeader::Init() { @@ -120,10 +121,10 @@ bool InputRecordingFile::open(const wxString path, bool newRecording) return true; } Close(); - recordingConLog(wxString::Format("[REC]: Input recording file header is invalid\n")); + inputRec::consoleLog("Input recording file header is invalid"); return false; } - recordingConLog(wxString::Format("[REC]: Input recording file opening failed. Error - %s\n", strerror(errno))); + inputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno))); return false; } @@ -140,7 +141,7 @@ bool InputRecordingFile::OpenNew(const wxString path, bool fromSavestate) } } else - recordingConLog(L"[REC]: Game is not open, aborting playing input recording which starts on a save-state.\n"); + inputRec::consoleLog("Game is not open, aborting playing input recording which starts on a save-state."); return false; } else if (open(path, true)) @@ -242,9 +243,9 @@ bool InputRecordingFile::verifyRecordingFileHeader() // Check for current verison if (header.version != 1) { - recordingConLog(wxString::Format("[REC]: Input recording file is not a supported version - %d\n", header.version)); + inputRec::consoleLog(fmt::format("Input recording file is not a supported version - {}", header.version)); return false; } return true; } -#endif \ No newline at end of file +#endif diff --git a/pcsx2/Recording/Utilities/InputRecordingLogger.h b/pcsx2/Recording/Utilities/InputRecordingLogger.h index e2183098a6..65a0a58de3 100644 --- a/pcsx2/Recording/Utilities/InputRecordingLogger.h +++ b/pcsx2/Recording/Utilities/InputRecordingLogger.h @@ -28,42 +28,32 @@ namespace inputRec { - static void log(const std::string& log) + static void log(const std::string log) { if (log.empty()) return; - recordingConLog(fmt::format("[REC]: %s\n", log)); + recordingConLog(fmt::format("[REC]: {}\n", log)); // NOTE - Color is not currently used for OSD logs if (GSosdLog) GSosdLog(log.c_str(), wxGetApp().GetProgramLog()->GetRGBA(ConsoleColors::Color_StrongMagenta)); } - static void consoleLog(const std::string& log) + static void consoleLog(const std::string log) { if (log.empty()) return; - recordingConLog(fmt::format("[REC]: %s\n", log)); + recordingConLog(fmt::format("[REC]: {}\n", log)); } static void consoleMultiLog(std::vector logs) { std::string log; for (std::string l : logs) - log.append(fmt::format("[REC]: %s\n", l)); + log.append(fmt::format("[REC]: {}\n", l)); recordingConLog(log); } - - - static void consoleMultiLog(std::vector logs) - { - std::vector stdLogs; - for (wxString l : logs) - stdLogs.push_back(std::string(l)); - - consoleMultiLog(stdLogs); - } } // namespace inputRec diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 77117cf299..42c701903c 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -27,6 +27,7 @@ #ifndef DISABLE_RECORDING # include "Recording/InputRecording.h" +# include "Recording/Utilities/InputRecordingLogger.h" #endif #include @@ -142,7 +143,7 @@ void GSPanel::InitRecordingAccelerators() m_Accels->findKeycodeWithCommandId("InputRecordingModeToggle").toTitleizedString(), g_InputRecording.IsActive()); - recordingConLog(L"Initialized Input Recording Key Bindings\n"); + inputRec::consoleLog("Initialized Input Recording Key Bindings"); } void GSPanel::RemoveRecordingAccelerators()