input-rec: refactor main input recording class

This commit is contained in:
Tyler Wilding
2022-11-27 20:02:29 +00:00
committed by refractionpcsx2
parent 9e30fa81de
commit c5298cf12d
2 changed files with 308 additions and 371 deletions
File diff suppressed because it is too large Load Diff
+37 -87
View File
@@ -151,6 +151,7 @@ extern InputRecording g_InputRecording;
#else
#include "Recording/InputRecordingFile.h"
#include "Recording/InputRecordingControls.h"
class InputRecording
{
@@ -160,109 +161,58 @@ public:
POWER_ON,
FROM_SAVESTATE
};
bool create(const std::string_view& filename, const bool fromSaveState, const std::string_view& authorName);
bool play(const std::string_view& path);
void stop();
// Save or load PCSX2's global frame counter (g_FrameCount) along with each full/fast boot
//
// This is to prevent any inaccuracy issues caused by having a different
// internal emulation frame count than what it was at the beginning of the
// original recording
void RecordingReset();
void controllerInterrupt(u8& data, u8& port, u16& BufCount, u8 buf[]);
void incFrameCounter();
u64 getFrameCounter() const;
bool isInitialSavestateLoadComplete() const;
bool isActive() const;
// Main handler for ingesting input data and either saving it to the recording file (recording)
// or mutating it to the contents of the recording file (replaying)
void ControllerInterrupt(u8 port, size_t fifoSize, u8 dataIn, u8 dataOut);
void handleExceededFrameCounter();
void handleLoadingSavestate();
// The running frame counter for the input recording
s32 GetFrameCounter();
bool isTypeSavestate() const;
InputRecordingFile& GetInputRecordingData();
void setStartingFrame(u64 startingFrame);
void setInitialSavestateLoaded();
void adjustFrameCounterOnReRecord(u64 newFrameCounter);
// The internal PCSX2 g_FrameCount value on the first frame of the recording
u32 GetStartingFrame();
void watchForRerecords();
void IncrementFrameCounter();
// DEPRECATED: Slated for removal
// If the current frame contains controller / input data
bool IsInterruptFrame();
// If there is currently an input recording being played back or actively being recorded
bool IsActive();
// Whether or not the recording's initial state has yet to be loaded or saved and
// the rest of the recording can be initialized
// This is not applicable to recordings from a "power-on" state
bool IsInitialLoad();
// If there is currently an input recording being played back
bool IsReplaying();
// If there are inputs currently being recorded to a file
bool IsRecording();
// Sets input recording to Record Mode
void SetToRecordMode();
// Sets input recording to Replay Mode
void SetToReplayMode();
// Set the running frame counter for the input recording to an arbitrary value
void SetFrameCounter(u32 newGFrameCount);
// Sets up all values and prints console logs pertaining to the start of a recording
void SetupInitialState(u32 newStartingFrame);
/// Functions called from GUI
// Create a new input recording file
bool Create(const std::string_view& filename, const bool fromSaveState, const std::string_view& authorName);
// Play an existing input recording from a file
// TODO - Vaser - Calls a file dialog if it fails to locate the default base savestate
bool Play(const std::string_view& path);
// Stop the active input recording
void Stop();
// Logs the padData and redraws the virtualPad windows of active pads
void LogAndRedraw();
// Resets a recording if the base savestate could not be loaded at the start
void FailedSavestate();
InputRecordingControls& getControls();
const InputRecordingFile& getData() const;
private:
enum class InputRecordingMode
{
NotActive,
Recording,
Replaying,
};
// - https://github.com/PCSX2/pcsx2/blob/7db9627ff6986c2d3faeecc58525a0e32da2f29f/pcsx2/PAD/Windows/PAD.cpp#L1141
static const u8 READ_DATA_AND_VIBRATE_QUERY_FIRST_BYTE = 0x42;
// - https://github.com/PCSX2/pcsx2/blob/7db9627ff6986c2d3faeecc58525a0e32da2f29f/pcsx2/PAD/Windows/PAD.cpp#L1142
static const u8 READ_DATA_AND_VIBRATE_QUERY_SECOND_BYTE = 0x5A;
static const int CONTROLLER_PORT_ONE = 0;
static const int CONTROLLER_PORT_TWO = 1;
InputRecordingControls m_controls;
InputRecordingFile m_file;
// 0x42 is the magic number to indicate the default controller read query
// See - PAD.cpp::PADpoll - https://github.com/PCSX2/pcsx2/blob/master/pcsx2/PAD/Windows/PAD.cpp#L1255
static const u8 READ_DATA_AND_VIBRATE_FIRST_BYTE = 0x42;
// 0x5A is always the second byte in the buffer when the normal READ_DATA_AND_VIBRATE (0x42) query is executed.
// See - PAD.cpp::PADpoll - https://github.com/PCSX2/pcsx2/blob/master/pcsx2/PAD/Windows/PAD.cpp#L1256
static const u8 READ_DATA_AND_VIBRATE_SECOND_BYTE = 0x5A;
Type m_type;
// DEPRECATED: Slated for removal
bool fInterruptFrame = false;
InputRecordingFile inputRecordingData;
bool initialLoad = false;
u32 startingFrame = 0;
s32 frameCounter = 0;
bool incrementUndo = false;
InputRecordingMode state = InputRecording::InputRecordingMode::NotActive;
std::string savestate;
bool m_initialSavestateLoadComplete = false;
bool m_isActive = false;
bool m_padDataAvailable = false;
bool m_watchingForRerecords = false;
// Array of usable pads (currently, only 2)
struct InputRecordingPad
{
// Controller Data
PadData* padData;
InputRecordingPad();
~InputRecordingPad();
} pads[2];
u64 m_frameCounter = 0;
// Either 0 for a power-on movie, or the g_FrameCount that is stored on the starting frame
u64 m_startingFrame = 0;
void initializeState();
private:
// Resolve the name and region of the game currently loaded using the GameDB
// If the game cannot be found in the DB, the fallback is the ISO filename
std::string resolveGameName();