mirror of https://github.com/PCSX2/pcsx2.git
input-rec: refactor and cleanup the file and logging classes
This commit is contained in:
parent
8f5458f3ae
commit
9e30fa81de
|
@ -242,6 +242,9 @@ bool InputRecordingFile::verifyRecordingFileHeader()
|
|||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
void InputRecordingFileHeader::Init()
|
||||
{
|
||||
memset(author, 0, std::size(author));
|
||||
|
@ -282,22 +285,22 @@ bool InputRecordingFile::Close()
|
|||
return true;
|
||||
}
|
||||
|
||||
const std::string& InputRecordingFile::GetFilename()
|
||||
const std::string& InputRecordingFile::getFilename() const
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
InputRecordingFileHeader& InputRecordingFile::GetHeader()
|
||||
InputRecordingFileHeader& InputRecordingFile::getHeader()
|
||||
{
|
||||
return header;
|
||||
}
|
||||
|
||||
long& InputRecordingFile::GetTotalFrames()
|
||||
const long& InputRecordingFile::getTotalFrames() const
|
||||
{
|
||||
return totalFrames;
|
||||
}
|
||||
|
||||
unsigned long& InputRecordingFile::GetUndoCount()
|
||||
const unsigned long& InputRecordingFile::getUndoCount() const
|
||||
{
|
||||
return undoCount;
|
||||
}
|
||||
|
@ -339,10 +342,10 @@ bool InputRecordingFile::open(const std::string_view& path, bool newRecording)
|
|||
return true;
|
||||
}
|
||||
Close();
|
||||
inputRec::consoleLog("Input recording file header is invalid");
|
||||
InputRec::consoleLog("Input recording file header is invalid");
|
||||
return false;
|
||||
}
|
||||
inputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno)));
|
||||
InputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -418,6 +421,49 @@ bool InputRecordingFile::WriteKeyBuffer(const uint& frame, const uint port, cons
|
|||
return true;
|
||||
}
|
||||
|
||||
void InputRecordingFile::logRecordingMetadata()
|
||||
{
|
||||
InputRec::consoleMultiLog({fmt::format("File: {}", getFilename()),
|
||||
fmt::format("PCSX2 Version Used: {}", std::string(getHeader().emu)),
|
||||
fmt::format("Recording File Version: {}", getHeader().version),
|
||||
fmt::format("Associated Game Name or ISO Filename: {}", std::string(getHeader().gameName)),
|
||||
fmt::format("Author: {}", getHeader().author),
|
||||
fmt::format("Total Frames: {}", getTotalFrames()),
|
||||
fmt::format("Undo Count: {}", getUndoCount())});
|
||||
}
|
||||
|
||||
std::vector<PadData> InputRecordingFile::bulkReadPadData(long frameStart, long frameEnd, const uint port)
|
||||
{
|
||||
std::vector<PadData> data = {};
|
||||
|
||||
if (recordingFile == nullptr)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
frameStart = frameStart < 0 ? 0 : frameStart;
|
||||
|
||||
std::array<u8, controllerInputBytes> padBytes;
|
||||
|
||||
// TODO - there are probably issues here if the file is too small / the frame counters are invalid!
|
||||
for (int frame = frameStart; frame < frameEnd; frame++)
|
||||
{
|
||||
const long seek = getRecordingBlockSeekPoint(frame) + controllerInputBytes * port;
|
||||
fseek(recordingFile, seek, SEEK_SET);
|
||||
if (fread(&padBytes, 1, padBytes.size(), recordingFile))
|
||||
{
|
||||
PadData frameData;
|
||||
for (int i = 0; i < padBytes.size(); i++)
|
||||
{
|
||||
frameData.UpdateControllerData(i, padBytes.at(i));
|
||||
}
|
||||
data.push_back(frameData);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
long InputRecordingFile::getRecordingBlockSeekPoint(const long& frame)
|
||||
{
|
||||
return headerSize + sizeof(bool) + frame * inputBytesPerFrame;
|
||||
|
@ -439,7 +485,7 @@ bool InputRecordingFile::verifyRecordingFileHeader()
|
|||
// Check for current verison
|
||||
if (header.version != 1)
|
||||
{
|
||||
inputRec::consoleLog(fmt::format("Input recording file is not a supported version - {}", header.version));
|
||||
InputRec::consoleLog(fmt::format("Input recording file is not a supported version - {}", header.version));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -150,15 +150,10 @@ public:
|
|||
// Closes the underlying input recording file, writing the header and
|
||||
// prepares for a possible new recording to be started
|
||||
bool Close();
|
||||
// Retrieve the input recording's filename (not the path)
|
||||
const std::string& GetFilename();
|
||||
// Retrieve the input recording's header which contains high-level metadata on the recording
|
||||
InputRecordingFileHeader& GetHeader();
|
||||
// The maximum number of frames, or in other words, the length of the recording
|
||||
long& GetTotalFrames();
|
||||
|
||||
// The number of times a save-state has been loaded while recording this movie
|
||||
// this is also often referred to as a "re-record"
|
||||
unsigned long& GetUndoCount();
|
||||
|
||||
// Whether or not this input recording starts by loading a save-state or by booting the game fresh
|
||||
bool FromSaveState();
|
||||
// Increment the number of undo actions and commit it to the recording file
|
||||
|
@ -178,6 +173,16 @@ public:
|
|||
// Writes the current frame's input data to the file so it can be replayed
|
||||
bool WriteKeyBuffer(const uint& frame, const uint port, const uint bufIndex, const u8& buf);
|
||||
|
||||
|
||||
// Retrieve the input recording's filename (not the path)
|
||||
const std::string& getFilename() const;
|
||||
InputRecordingFileHeader& getHeader();
|
||||
const long& getTotalFrames() const;
|
||||
const unsigned long& getUndoCount() const;
|
||||
|
||||
void logRecordingMetadata();
|
||||
std::vector<PadData> bulkReadPadData(long frameStart, long frameEnd, const uint port);
|
||||
|
||||
private:
|
||||
static const int controllerPortsSupported = 2;
|
||||
static const int controllerInputBytes = 18;
|
||||
|
|
|
@ -19,38 +19,40 @@
|
|||
|
||||
#include "DebugTools/Debug.h"
|
||||
#include "common/Console.h"
|
||||
#include "GS.h" // GSosdlog
|
||||
#include "GS.h"
|
||||
#include "Host.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace inputRec
|
||||
namespace InputRec
|
||||
{
|
||||
void log(const std::string& log)
|
||||
{
|
||||
if (log.empty())
|
||||
return;
|
||||
|
||||
recordingConLog(fmt::format("[REC]: {}\n", log));
|
||||
|
||||
// NOTE - Color is not currently used for OSD logs
|
||||
Host::AddOSDMessage(log, 15.0f);
|
||||
if (!log.empty())
|
||||
{
|
||||
recordingConLog(fmt::format("[REC]: {}\n", log));
|
||||
Host::AddOSDMessage(log, 15.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void consoleLog(const std::string& log)
|
||||
{
|
||||
if (log.empty())
|
||||
return;
|
||||
|
||||
recordingConLog(fmt::format("[REC]: {}\n", log));
|
||||
if (!log.empty())
|
||||
{
|
||||
recordingConLog(fmt::format("[REC]: {}\n", log));
|
||||
}
|
||||
}
|
||||
|
||||
void consoleMultiLog(const std::vector<std::string>& logs)
|
||||
{
|
||||
std::string log;
|
||||
for (std::string l : logs)
|
||||
log.append(fmt::format("[REC]: {}\n", l));
|
||||
|
||||
recordingConLog(log);
|
||||
if (!logs.empty())
|
||||
{
|
||||
std::string log;
|
||||
for (std::string l : logs)
|
||||
{
|
||||
log.append(fmt::format("[REC]: {}\n", l));
|
||||
}
|
||||
recordingConLog(log);
|
||||
}
|
||||
}
|
||||
} // namespace inputRec
|
||||
} // namespace InputRecording
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace inputRec
|
||||
namespace InputRec
|
||||
{
|
||||
void log(const std::string& log);
|
||||
void consoleLog(const std::string& log);
|
||||
|
|
Loading…
Reference in New Issue