input-rec : additional m_/s_ variable tags and constexpr placements

This commit is contained in:
sonicfind 2022-09-22 09:10:00 -05:00 committed by refractionpcsx2
parent 409c285f36
commit 1356171af5
7 changed files with 233 additions and 215 deletions

View File

@ -50,24 +50,24 @@ void InputRecordingViewer::loadTable()
for (const auto& frame : data)
{
// TODO - disgusting, clean it up
m_ui.tableWidget->setItem(frameNum, 0, new QTableWidgetItem(tr("%1 %2").arg(frame.leftAnalogX).arg(frame.leftAnalogY)));
m_ui.tableWidget->setItem(frameNum, 1, new QTableWidgetItem(tr("%1 %2").arg(frame.rightAnalogX).arg(frame.rightAnalogY)));
m_ui.tableWidget->setItem(frameNum, 2, new QTableWidgetItem(tr("%1 [%2]").arg(frame.crossPressed).arg(frame.crossPressure)));
m_ui.tableWidget->setItem(frameNum, 3, new QTableWidgetItem(tr("%1 [%2]").arg(frame.squarePressed).arg(frame.squarePressure)));
m_ui.tableWidget->setItem(frameNum, 4, new QTableWidgetItem(tr("%1 [%2]").arg(frame.trianglePressed).arg(frame.trianglePressure)));
m_ui.tableWidget->setItem(frameNum, 5, new QTableWidgetItem(tr("%1 [%2]").arg(frame.circlePressed).arg(frame.circlePressure)));
m_ui.tableWidget->setItem(frameNum, 6, new QTableWidgetItem(tr("%1 [%2]").arg(frame.l1Pressed).arg(frame.l1Pressure)));
m_ui.tableWidget->setItem(frameNum, 7, new QTableWidgetItem(tr("%1 [%2]").arg(frame.l2Pressed).arg(frame.l2Pressure)));
m_ui.tableWidget->setItem(frameNum, 8, new QTableWidgetItem(tr("%1 [%2]").arg(frame.r1Pressed).arg(frame.r1Pressure)));
m_ui.tableWidget->setItem(frameNum, 9, new QTableWidgetItem(tr("%1 [%2]").arg(frame.r1Pressed).arg(frame.r2Pressure)));
m_ui.tableWidget->setItem(frameNum, 10, new QTableWidgetItem(tr("%1 [%2]").arg(frame.downPressed).arg(frame.downPressure)));
m_ui.tableWidget->setItem(frameNum, 11, new QTableWidgetItem(tr("%1 [%2]").arg(frame.rightPressed).arg(frame.rightPressure)));
m_ui.tableWidget->setItem(frameNum, 12, new QTableWidgetItem(tr("%1 [%2]").arg(frame.upPressed).arg(frame.upPressure)));
m_ui.tableWidget->setItem(frameNum, 13, new QTableWidgetItem(tr("%1 [%2]").arg(frame.leftPressed).arg(frame.leftPressure)));
m_ui.tableWidget->setItem(frameNum, 14, new QTableWidgetItem(tr("%1").arg(frame.l3)));
m_ui.tableWidget->setItem(frameNum, 15, new QTableWidgetItem(tr("%1").arg(frame.r3)));
m_ui.tableWidget->setItem(frameNum, 16, new QTableWidgetItem(tr("%1").arg(frame.select)));
m_ui.tableWidget->setItem(frameNum, 17, new QTableWidgetItem(tr("%1").arg(frame.start)));
m_ui.tableWidget->setItem(frameNum, 0, new QTableWidgetItem(tr("%1 %2").arg(frame.m_leftAnalogX).arg(frame.m_leftAnalogY)));
m_ui.tableWidget->setItem(frameNum, 1, new QTableWidgetItem(tr("%1 %2").arg(frame.m_rightAnalogX).arg(frame.m_rightAnalogY)));
m_ui.tableWidget->setItem(frameNum, 2, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_crossPressed).arg(frame.m_crossPressure)));
m_ui.tableWidget->setItem(frameNum, 3, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_squarePressed).arg(frame.m_squarePressure)));
m_ui.tableWidget->setItem(frameNum, 4, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_trianglePressed).arg(frame.m_trianglePressure)));
m_ui.tableWidget->setItem(frameNum, 5, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_circlePressed).arg(frame.m_circlePressure)));
m_ui.tableWidget->setItem(frameNum, 6, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_l1Pressed).arg(frame.m_l1Pressure)));
m_ui.tableWidget->setItem(frameNum, 7, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_l2Pressed).arg(frame.m_l2Pressure)));
m_ui.tableWidget->setItem(frameNum, 8, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_r1Pressed).arg(frame.m_r1Pressure)));
m_ui.tableWidget->setItem(frameNum, 9, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_r1Pressed).arg(frame.m_r2Pressure)));
m_ui.tableWidget->setItem(frameNum, 10, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_downPressed).arg(frame.m_downPressure)));
m_ui.tableWidget->setItem(frameNum, 11, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_rightPressed).arg(frame.m_rightPressure)));
m_ui.tableWidget->setItem(frameNum, 12, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_upPressed).arg(frame.m_upPressure)));
m_ui.tableWidget->setItem(frameNum, 13, new QTableWidgetItem(tr("%1 [%2]").arg(frame.m_leftPressed).arg(frame.m_leftPressure)));
m_ui.tableWidget->setItem(frameNum, 14, new QTableWidgetItem(tr("%1").arg(frame.m_l3)));
m_ui.tableWidget->setItem(frameNum, 15, new QTableWidgetItem(tr("%1").arg(frame.m_r3)));
m_ui.tableWidget->setItem(frameNum, 16, new QTableWidgetItem(tr("%1").arg(frame.m_select)));
m_ui.tableWidget->setItem(frameNum, 17, new QTableWidgetItem(tr("%1").arg(frame.m_start)));
frameNum++;
}
}

View File

@ -584,9 +584,9 @@ bool InputRecording::play(const std::string_view& filename)
initializeState();
InputRec::log("Replaying input recording");
m_file.logRecordingMetadata();
if (resolveGameName() != m_file.getHeader().gameName)
if (resolveGameName() != m_file.getHeader().m_gameName)
{
InputRec::consoleLog(fmt::format("Input recording was possibly constructed for a different game. Expected: {}, Actual: {}", m_file.getHeader().gameName, resolveGameName()));
InputRec::consoleLog(fmt::format("Input recording was possibly constructed for a different game. Expected: {}, Actual: {}", m_file.getHeader().m_gameName, resolveGameName()));
}
return true;

View File

@ -185,9 +185,9 @@ public:
private:
// - https://github.com/PCSX2/pcsx2/blob/7db9627ff6986c2d3faeecc58525a0e32da2f29f/pcsx2/PAD/Windows/PAD.cpp#L1141
static const u8 READ_DATA_AND_VIBRATE_QUERY_FIRST_BYTE = 0x42;
static constexpr u8 s_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 constexpr u8 s_READ_DATA_AND_VIBRATE_QUERY_SECOND_BYTE = 0x5A;
InputRecordingControls m_controls;
InputRecordingFile m_file;

View File

@ -247,102 +247,102 @@ bool InputRecordingFile::verifyRecordingFileHeader()
void InputRecordingFileHeader::Init()
{
memset(author, 0, std::size(author));
memset(gameName, 0, std::size(gameName));
memset(m_author, 0, std::size(m_author));
memset(m_gameName, 0, std::size(m_gameName));
}
void InputRecordingFileHeader::SetEmulatorVersion()
{
std::string emuVersion = fmt::format("PCSX2-{}.{}.{}", PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo);
int max = std::size(emu) - 1;
strncpy(emu, emuVersion.c_str(), max);
emu[max] = 0;
int max = std::size(m_emulatorVersion) - 1;
strncpy(m_emulatorVersion, emuVersion.c_str(), max);
m_emulatorVersion[max] = 0;
}
void InputRecordingFileHeader::SetAuthor(const std::string_view& _author)
{
int max = std::size(author) - 1;
strncpy(author, _author.data(), max);
author[max] = 0;
int max = std::size(m_author) - 1;
strncpy(m_author, _author.data(), max);
m_author[max] = 0;
}
void InputRecordingFileHeader::SetGameName(const std::string_view& _gameName)
{
int max = std::size(gameName) - 1;
strncpy(gameName, _gameName.data(), max);
gameName[max] = 0;
int max = std::size(m_gameName) - 1;
strncpy(m_gameName, _gameName.data(), max);
m_gameName[max] = 0;
}
bool InputRecordingFile::Close()
{
if (recordingFile == nullptr)
if (m_recordingFile == nullptr)
{
return false;
}
fclose(recordingFile);
recordingFile = nullptr;
filename = "";
fclose(m_recordingFile);
m_recordingFile = nullptr;
m_filename = "";
return true;
}
const std::string& InputRecordingFile::getFilename() const
{
return filename;
return m_filename;
}
InputRecordingFileHeader& InputRecordingFile::getHeader()
{
return header;
return m_header;
}
const long& InputRecordingFile::getTotalFrames() const
{
return totalFrames;
return m_totalFrames;
}
const unsigned long& InputRecordingFile::getUndoCount() const
{
return undoCount;
return m_undoCount;
}
bool InputRecordingFile::FromSaveState()
{
return savestate.fromSavestate;
return m_savestate.fromSavestate;
}
void InputRecordingFile::IncrementUndoCount()
{
undoCount++;
if (recordingFile == nullptr)
m_undoCount++;
if (m_recordingFile == nullptr)
{
return;
}
fseek(recordingFile, seekpointUndoCount, SEEK_SET);
fwrite(&undoCount, 4, 1, recordingFile);
fseek(m_recordingFile, s_seekpointUndoCount, SEEK_SET);
fwrite(&m_undoCount, 4, 1, m_recordingFile);
}
bool InputRecordingFile::open(const std::string_view& path, bool newRecording)
{
if (newRecording)
{
if ((recordingFile = FileSystem::OpenCFile(path.data(), "wb+")) != nullptr)
if ((m_recordingFile = FileSystem::OpenCFile(path.data(), "wb+")) != nullptr)
{
filename = path;
totalFrames = 0;
undoCount = 0;
header.Init();
m_filename = path;
m_totalFrames = 0;
m_undoCount = 0;
m_header.Init();
return true;
}
}
else if ((recordingFile = FileSystem::OpenCFile(path.data(), "rb+")) != nullptr)
else if ((m_recordingFile = FileSystem::OpenCFile(path.data(), "rb+")) != nullptr)
{
if (verifyRecordingFileHeader())
{
filename = path;
m_filename = path;
return true;
}
Close();
InputRec::consoleLog("Input recording file header is invalid");
InputRec::consoleLog("Input recording file m_header is invalid");
return false;
}
InputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno)));
@ -353,7 +353,7 @@ bool InputRecordingFile::OpenNew(const std::string_view& path, bool fromSavestat
{
if (!open(path, true))
return false;
savestate.fromSavestate = fromSavestate;
m_savestate.fromSavestate = fromSavestate;
return true;
}
@ -364,13 +364,13 @@ bool InputRecordingFile::OpenExisting(const std::string_view& path)
bool InputRecordingFile::ReadKeyBuffer(u8& result, const uint& frame, const uint port, const uint bufIndex)
{
if (recordingFile == nullptr)
if (m_recordingFile == nullptr)
{
return false;
}
long seek = getRecordingBlockSeekPoint(frame) + controllerInputBytes * port + bufIndex;
if (fseek(recordingFile, seek, SEEK_SET) != 0 || fread(&result, 1, 1, recordingFile) != 1)
long seek = getRecordingBlockSeekPoint(frame) + s_controllerInputBytes * port + bufIndex;
if (fseek(m_recordingFile, seek, SEEK_SET) != 0 || fread(&result, 1, 1, m_recordingFile) != 1)
{
return false;
}
@ -380,23 +380,23 @@ bool InputRecordingFile::ReadKeyBuffer(u8& result, const uint& frame, const uint
void InputRecordingFile::SetTotalFrames(long frame)
{
if (recordingFile == nullptr || totalFrames >= frame)
if (m_recordingFile == nullptr || m_totalFrames >= frame)
{
return;
}
totalFrames = frame;
fseek(recordingFile, seekpointTotalFrames, SEEK_SET);
fwrite(&totalFrames, 4, 1, recordingFile);
m_totalFrames = frame;
fseek(m_recordingFile, s_seekpointTotalFrames, SEEK_SET);
fwrite(&m_totalFrames, 4, 1, m_recordingFile);
}
bool InputRecordingFile::WriteHeader()
{
if (recordingFile == nullptr)
if (m_recordingFile == nullptr)
{
return false;
}
rewind(recordingFile);
if (fwrite(&header, sizeof(InputRecordingFileHeader), 1, recordingFile) != 1 || fwrite(&totalFrames, 4, 1, recordingFile) != 1 || fwrite(&undoCount, 4, 1, recordingFile) != 1 || fwrite(&savestate, 1, 1, recordingFile) != 1)
rewind(m_recordingFile);
if (fwrite(&m_header, sizeof(InputRecordingFileHeader), 1, m_recordingFile) != 1 || fwrite(&m_totalFrames, 4, 1, m_recordingFile) != 1 || fwrite(&m_undoCount, 4, 1, m_recordingFile) != 1 || fwrite(&m_savestate, 1, 1, m_recordingFile) != 1)
{
return false;
}
@ -405,29 +405,29 @@ bool InputRecordingFile::WriteHeader()
bool InputRecordingFile::WriteKeyBuffer(const uint& frame, const uint port, const uint bufIndex, const u8& buf)
{
if (recordingFile == nullptr)
if (m_recordingFile == nullptr)
{
return false;
}
long seek = getRecordingBlockSeekPoint(frame) + 18 * port + bufIndex;
if (fseek(recordingFile, seek, SEEK_SET) != 0 || fwrite(&buf, 1, 1, recordingFile) != 1)
if (fseek(m_recordingFile, seek, SEEK_SET) != 0 || fwrite(&buf, 1, 1, m_recordingFile) != 1)
{
return false;
}
fflush(recordingFile);
fflush(m_recordingFile);
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("PCSX2 Version Used: {}", std::string(getHeader().m_emulatorVersion)),
fmt::format("Recording File Version: {}", getHeader().m_fileVersion),
fmt::format("Associated Game Name or ISO Filename: {}", std::string(getHeader().m_gameName)),
fmt::format("Author: {}", getHeader().m_author),
fmt::format("Total Frames: {}", getTotalFrames()),
fmt::format("Undo Count: {}", getUndoCount())});
}
@ -436,21 +436,21 @@ std::vector<PadData> InputRecordingFile::bulkReadPadData(long frameStart, long f
{
std::vector<PadData> data = {};
if (recordingFile == nullptr)
if (m_recordingFile == nullptr)
{
return data;
}
frameStart = frameStart < 0 ? 0 : frameStart;
std::array<u8, controllerInputBytes> padBytes;
std::array<u8, s_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))
const long seek = getRecordingBlockSeekPoint(frame) + s_controllerInputBytes * port;
fseek(m_recordingFile, seek, SEEK_SET);
if (fread(&padBytes, 1, padBytes.size(), m_recordingFile))
{
PadData frameData;
for (int i = 0; i < padBytes.size(); i++)
@ -466,26 +466,26 @@ std::vector<PadData> InputRecordingFile::bulkReadPadData(long frameStart, long f
long InputRecordingFile::getRecordingBlockSeekPoint(const long& frame)
{
return headerSize + sizeof(bool) + frame * inputBytesPerFrame;
return s_headerSize + sizeof(bool) + frame * s_inputBytesPerFrame;
}
bool InputRecordingFile::verifyRecordingFileHeader()
{
if (recordingFile == nullptr)
if (m_recordingFile == nullptr)
{
return false;
}
// Verify header contents
rewind(recordingFile);
if (fread(&header, sizeof(InputRecordingFileHeader), 1, recordingFile) != 1 || fread(&totalFrames, 4, 1, recordingFile) != 1 || fread(&undoCount, 4, 1, recordingFile) != 1 || fread(&savestate.fromSavestate, sizeof(bool), 1, recordingFile) != 1)
// Verify m_header contents
rewind(m_recordingFile);
if (fread(&m_header, sizeof(InputRecordingFileHeader), 1, m_recordingFile) != 1 || fread(&m_totalFrames, 4, 1, m_recordingFile) != 1 || fread(&m_undoCount, 4, 1, m_recordingFile) != 1 || fread(&m_savestate.fromSavestate, sizeof(bool), 1, m_recordingFile) != 1)
{
return false;
}
// Check for current verison
if (header.version != 1)
if (m_header.m_fileVersion != 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 m_fileVersion - {}", m_header.m_fileVersion));
return false;
}
return true;

View File

@ -121,10 +121,10 @@ private:
struct InputRecordingFileHeader
{
u8 version = 1;
char emu[50] = "";
char author[255] = "";
char gameName[255] = "";
u8 m_fileVersion = 1;
char m_emulatorVersion[50] = "";
char m_author[255] = "";
char m_gameName[255] = "";
public:
void SetEmulatorVersion();
@ -184,26 +184,26 @@ public:
std::vector<PadData> bulkReadPadData(long frameStart, long frameEnd, const uint port);
private:
static const int controllerPortsSupported = 2;
static const int controllerInputBytes = 18;
static const int inputBytesPerFrame = controllerInputBytes * controllerPortsSupported;
static constexpr int s_controllerPortsSupported = 2;
static constexpr int s_controllerInputBytes = 18;
static constexpr int s_inputBytesPerFrame = s_controllerInputBytes * s_controllerPortsSupported;
// TODO - version 2, this could be greatly simplified if everything was in the header
// + 4 + 4 is the totalFrame and undoCount values
static const int headerSize = sizeof(InputRecordingFileHeader) + 4 + 4;
static constexpr int s_headerSize = sizeof(InputRecordingFileHeader) + 4 + 4;
// DEPRECATED / Slated for Removal
static const int recordingSavestateHeaderSize = sizeof(bool);
static const int seekpointTotalFrames = sizeof(InputRecordingFileHeader);
static const int seekpointUndoCount = sizeof(InputRecordingFileHeader) + 4;
static const int seekpointSaveStateHeader = seekpointUndoCount + 4;
static constexpr int s_recordingSavestateHeaderSize = sizeof(bool);
static constexpr int s_seekpointTotalFrames = sizeof(InputRecordingFileHeader);
static constexpr int s_seekpointUndoCount = sizeof(InputRecordingFileHeader) + 4;
static constexpr int s_seekpointSaveStateHeader = s_seekpointUndoCount + 4;
InputRecordingFileHeader header;
std::string filename = "";
FILE* recordingFile = nullptr;
InputRecordingSavestate savestate;
InputRecordingFileHeader m_header;
std::string m_filename = "";
FILE* m_recordingFile = nullptr;
InputRecordingSavestate m_savestate;
// An signed 32-bit frame limit is equivalent to 1.13 years of continuous 60fps footage
long totalFrames = 0;
unsigned long undoCount = 0;
long m_totalFrames = 0;
unsigned long m_undoCount = 0;
// Calculates the position of the current frame in the input recording
long getRecordingBlockSeekPoint(const long& frame);

View File

@ -19,78 +19,96 @@
#include <fmt/core.h>
const PadData::ButtonResolver PadData::s_LEFT {0b10000000};
const PadData::ButtonResolver PadData::s_DOWN {0b01000000};
const PadData::ButtonResolver PadData::s_RIGHT {0b00100000};
const PadData::ButtonResolver PadData::s_UP {0b00010000};
const PadData::ButtonResolver PadData::s_START {0b00001000};
const PadData::ButtonResolver PadData::s_R3 {0b00000100};
const PadData::ButtonResolver PadData::s_L3 {0b00000010};
const PadData::ButtonResolver PadData::s_SELECT {0b00000001};
const PadData::ButtonResolver PadData::s_SQUARE {0b10000000};
const PadData::ButtonResolver PadData::s_CROSS {0b01000000};
const PadData::ButtonResolver PadData::s_CIRCLE {0b00100000};
const PadData::ButtonResolver PadData::s_TRIANGLE{0b00010000};
const PadData::ButtonResolver PadData::s_R1 {0b00001000};
const PadData::ButtonResolver PadData::s_L1 {0b00000100};
const PadData::ButtonResolver PadData::s_R2 {0b00000010};
const PadData::ButtonResolver PadData::s_L2 {0b00000001};
void PadData::UpdateControllerData(u16 bufIndex, u8 const& bufVal)
{
const BufferIndex index = static_cast<BufferIndex>(bufIndex);
switch (index)
{
case BufferIndex::PressedFlagsGroupOne:
leftPressed = IsButtonPressed(LEFT, bufVal);
downPressed = IsButtonPressed(DOWN, bufVal);
rightPressed = IsButtonPressed(RIGHT, bufVal);
upPressed = IsButtonPressed(UP, bufVal);
start = IsButtonPressed(START, bufVal);
r3 = IsButtonPressed(R3, bufVal);
l3 = IsButtonPressed(L3, bufVal);
select = IsButtonPressed(SELECT, bufVal);
m_leftPressed = IsButtonPressed(s_LEFT, bufVal);
m_downPressed = IsButtonPressed(s_DOWN, bufVal);
m_rightPressed = IsButtonPressed(s_RIGHT, bufVal);
m_upPressed = IsButtonPressed(s_UP, bufVal);
m_start = IsButtonPressed(s_START, bufVal);
m_r3 = IsButtonPressed(s_R3, bufVal);
m_l3 = IsButtonPressed(s_L3, bufVal);
m_select = IsButtonPressed(s_SELECT, bufVal);
break;
case BufferIndex::PressedFlagsGroupTwo:
squarePressed = IsButtonPressed(SQUARE, bufVal);
crossPressed = IsButtonPressed(CROSS, bufVal);
circlePressed = IsButtonPressed(CIRCLE, bufVal);
trianglePressed = IsButtonPressed(TRIANGLE, bufVal);
r1Pressed = IsButtonPressed(R1, bufVal);
l1Pressed = IsButtonPressed(L1, bufVal);
r2Pressed = IsButtonPressed(R2, bufVal);
l2Pressed = IsButtonPressed(L2, bufVal);
m_squarePressed = IsButtonPressed(s_SQUARE, bufVal);
m_crossPressed = IsButtonPressed(s_CROSS, bufVal);
m_circlePressed = IsButtonPressed(s_CIRCLE, bufVal);
m_trianglePressed = IsButtonPressed(s_TRIANGLE, bufVal);
m_r1Pressed = IsButtonPressed(s_R1, bufVal);
m_l1Pressed = IsButtonPressed(s_L1, bufVal);
m_r2Pressed = IsButtonPressed(s_R2, bufVal);
m_l2Pressed = IsButtonPressed(s_L2, bufVal);
break;
case BufferIndex::RightAnalogXVector:
rightAnalogX = bufVal;
m_rightAnalogX = bufVal;
break;
case BufferIndex::RightAnalogYVector:
rightAnalogY = bufVal;
m_rightAnalogY = bufVal;
break;
case BufferIndex::LeftAnalogXVector:
leftAnalogX = bufVal;
m_leftAnalogX = bufVal;
break;
case BufferIndex::LeftAnalogYVector:
leftAnalogY = bufVal;
m_leftAnalogY = bufVal;
break;
case BufferIndex::RightPressure:
rightPressure = bufVal;
m_rightPressure = bufVal;
break;
case BufferIndex::LeftPressure:
leftPressure = bufVal;
m_leftPressure = bufVal;
break;
case BufferIndex::UpPressure:
upPressure = bufVal;
m_upPressure = bufVal;
break;
case BufferIndex::DownPressure:
downPressure = bufVal;
m_downPressure = bufVal;
break;
case BufferIndex::TrianglePressure:
trianglePressure = bufVal;
m_trianglePressure = bufVal;
break;
case BufferIndex::CirclePressure:
circlePressure = bufVal;
m_circlePressure = bufVal;
break;
case BufferIndex::CrossPressure:
crossPressure = bufVal;
m_crossPressure = bufVal;
break;
case BufferIndex::SquarePressure:
squarePressure = bufVal;
m_squarePressure = bufVal;
break;
case BufferIndex::L1Pressure:
l1Pressure = bufVal;
m_l1Pressure = bufVal;
break;
case BufferIndex::R1Pressure:
r1Pressure = bufVal;
m_r1Pressure = bufVal;
break;
case BufferIndex::L2Pressure:
l2Pressure = bufVal;
m_l2Pressure = bufVal;
break;
case BufferIndex::R2Pressure:
r2Pressure = bufVal;
m_r2Pressure = bufVal;
break;
}
}
@ -103,60 +121,60 @@ u8 PadData::PollControllerData(u16 bufIndex)
{
case BufferIndex::PressedFlagsGroupOne:
// Construct byte by combining flags if the buttons are pressed
byte |= BitmaskOrZero(leftPressed, LEFT);
byte |= BitmaskOrZero(downPressed, DOWN);
byte |= BitmaskOrZero(rightPressed, RIGHT);
byte |= BitmaskOrZero(upPressed, UP);
byte |= BitmaskOrZero(start, START);
byte |= BitmaskOrZero(r3, R3);
byte |= BitmaskOrZero(l3, L3);
byte |= BitmaskOrZero(select, SELECT);
byte |= BitmaskOrZero(m_leftPressed, s_LEFT);
byte |= BitmaskOrZero(m_downPressed, s_DOWN);
byte |= BitmaskOrZero(m_rightPressed, s_RIGHT);
byte |= BitmaskOrZero(m_upPressed, s_UP);
byte |= BitmaskOrZero(m_start, s_START);
byte |= BitmaskOrZero(m_r3, s_R3);
byte |= BitmaskOrZero(m_l3, s_L3);
byte |= BitmaskOrZero(m_select, s_SELECT);
// We flip the bits because as mentioned below, 0 = pressed
return ~byte;
case BufferIndex::PressedFlagsGroupTwo:
// Construct byte by combining flags if the buttons are pressed
byte |= BitmaskOrZero(squarePressed, SQUARE);
byte |= BitmaskOrZero(crossPressed, CROSS);
byte |= BitmaskOrZero(circlePressed, CIRCLE);
byte |= BitmaskOrZero(trianglePressed, TRIANGLE);
byte |= BitmaskOrZero(r1Pressed, R1);
byte |= BitmaskOrZero(l1Pressed, L1);
byte |= BitmaskOrZero(r2Pressed, R2);
byte |= BitmaskOrZero(l2Pressed, L2);
byte |= BitmaskOrZero(m_squarePressed, s_SQUARE);
byte |= BitmaskOrZero(m_crossPressed, s_CROSS);
byte |= BitmaskOrZero(m_circlePressed, s_CIRCLE);
byte |= BitmaskOrZero(m_trianglePressed, s_TRIANGLE);
byte |= BitmaskOrZero(m_r1Pressed, s_R1);
byte |= BitmaskOrZero(m_l1Pressed, s_L1);
byte |= BitmaskOrZero(m_r2Pressed, s_R2);
byte |= BitmaskOrZero(m_l2Pressed, s_L2);
// We flip the bits because as mentioned below, 0 = pressed
return ~byte;
case BufferIndex::RightAnalogXVector:
return rightAnalogX;
return m_rightAnalogX;
case BufferIndex::RightAnalogYVector:
return rightAnalogY;
return m_rightAnalogY;
case BufferIndex::LeftAnalogXVector:
return leftAnalogX;
return m_leftAnalogX;
case BufferIndex::LeftAnalogYVector:
return leftAnalogY;
return m_leftAnalogY;
case BufferIndex::RightPressure:
return rightPressure;
return m_rightPressure;
case BufferIndex::LeftPressure:
return leftPressure;
return m_leftPressure;
case BufferIndex::UpPressure:
return upPressure;
return m_upPressure;
case BufferIndex::DownPressure:
return downPressure;
return m_downPressure;
case BufferIndex::TrianglePressure:
return trianglePressure;
return m_trianglePressure;
case BufferIndex::CirclePressure:
return circlePressure;
return m_circlePressure;
case BufferIndex::CrossPressure:
return crossPressure;
return m_crossPressure;
case BufferIndex::SquarePressure:
return squarePressure;
return m_squarePressure;
case BufferIndex::L1Pressure:
return l1Pressure;
return m_l1Pressure;
case BufferIndex::R1Pressure:
return r1Pressure;
return m_r1Pressure;
case BufferIndex::L2Pressure:
return l2Pressure;
return m_l2Pressure;
case BufferIndex::R2Pressure:
return r2Pressure;
return m_r2Pressure;
default:
return 0;
}

View File

@ -19,7 +19,7 @@ class PadData
{
public:
/// Constants
static const u8 ANALOG_VECTOR_NEUTRAL = 127;
static constexpr u8 ANALOG_VECTOR_NEUTRAL = 127;
enum class BufferIndex
{
@ -44,46 +44,46 @@ public:
};
/// Pressure Buttons - 0-255
u8 circlePressure = 0;
u8 crossPressure = 0;
u8 squarePressure = 0;
u8 trianglePressure = 0;
u8 downPressure = 0;
u8 leftPressure = 0;
u8 rightPressure = 0;
u8 upPressure = 0;
u8 l1Pressure = 0;
u8 l2Pressure = 0;
u8 r1Pressure = 0;
u8 r2Pressure = 0;
u8 m_circlePressure = 0;
u8 m_crossPressure = 0;
u8 m_squarePressure = 0;
u8 m_trianglePressure = 0;
u8 m_downPressure = 0;
u8 m_leftPressure = 0;
u8 m_rightPressure = 0;
u8 m_upPressure = 0;
u8 m_l1Pressure = 0;
u8 m_l2Pressure = 0;
u8 m_r1Pressure = 0;
u8 m_r2Pressure = 0;
/// Pressure Button Flags
/// NOTE - It shouldn't be possible to depress a button while also having no pressure
/// But for the sake of completeness, it should be tracked.
bool circlePressed = false;
bool crossPressed = false;
bool squarePressed = false;
bool trianglePressed = false;
bool downPressed = false;
bool leftPressed = false;
bool rightPressed = false;
bool upPressed = false;
bool l1Pressed = false;
bool l2Pressed = false;
bool r1Pressed = false;
bool r2Pressed = false;
bool m_circlePressed = false;
bool m_crossPressed = false;
bool m_squarePressed = false;
bool m_trianglePressed = false;
bool m_downPressed = false;
bool m_leftPressed = false;
bool m_rightPressed = false;
bool m_upPressed = false;
bool m_l1Pressed = false;
bool m_l2Pressed = false;
bool m_r1Pressed = false;
bool m_r2Pressed = false;
/// Normal (un)pressed buttons
bool select = false;
bool start = false;
bool l3 = false;
bool r3 = false;
bool m_select = false;
bool m_start = false;
bool m_l3 = false;
bool m_r3 = false;
/// Analog Sticks - 0-255 (127 center)
u8 leftAnalogX = ANALOG_VECTOR_NEUTRAL;
u8 leftAnalogY = ANALOG_VECTOR_NEUTRAL;
u8 rightAnalogX = ANALOG_VECTOR_NEUTRAL;
u8 rightAnalogY = ANALOG_VECTOR_NEUTRAL;
u8 m_leftAnalogX = ANALOG_VECTOR_NEUTRAL;
u8 m_leftAnalogY = ANALOG_VECTOR_NEUTRAL;
u8 m_rightAnalogX = ANALOG_VECTOR_NEUTRAL;
u8 m_rightAnalogY = ANALOG_VECTOR_NEUTRAL;
// Given the input buffer and the current index, updates the correct field(s)
void UpdateControllerData(u16 bufIndex, u8 const& bufVal);
@ -98,23 +98,23 @@ private:
u8 buttonBitmask;
};
const ButtonResolver LEFT = ButtonResolver{0b10000000};
const ButtonResolver DOWN = ButtonResolver{0b01000000};
const ButtonResolver RIGHT = ButtonResolver{0b00100000};
const ButtonResolver UP = ButtonResolver{0b00010000};
const ButtonResolver START = ButtonResolver{0b00001000};
const ButtonResolver R3 = ButtonResolver{0b00000100};
const ButtonResolver L3 = ButtonResolver{0b00000010};
const ButtonResolver SELECT = ButtonResolver{0b00000001};
static const ButtonResolver s_LEFT;
static const ButtonResolver s_DOWN;
static const ButtonResolver s_RIGHT;
static const ButtonResolver s_UP;
static const ButtonResolver s_START;
static const ButtonResolver s_R3;
static const ButtonResolver s_L3;
static const ButtonResolver s_SELECT;
const ButtonResolver SQUARE = ButtonResolver{0b10000000};
const ButtonResolver CROSS = ButtonResolver{0b01000000};
const ButtonResolver CIRCLE = ButtonResolver{0b00100000};
const ButtonResolver TRIANGLE = ButtonResolver{0b00010000};
const ButtonResolver R1 = ButtonResolver{0b00001000};
const ButtonResolver L1 = ButtonResolver{0b00000100};
const ButtonResolver R2 = ButtonResolver{0b00000010};
const ButtonResolver L2 = ButtonResolver{0b00000001};
static const ButtonResolver s_SQUARE;
static const ButtonResolver s_CROSS;
static const ButtonResolver s_CIRCLE;
static const ButtonResolver s_TRIANGLE;
static const ButtonResolver s_R1;
static const ButtonResolver s_L1;
static const ButtonResolver s_R2;
static const ButtonResolver s_L2;
// Checks and returns if button a is pressed or not
bool IsButtonPressed(ButtonResolver buttonResolver, u8 const& bufVal);