Skip to content

Commit

Permalink
recording: Many adjustments on VirtualPad from review feedback
Browse files Browse the repository at this point in the history
recording: Factor in DPIScaling when scaling VirtualPad window


recording: Add a reset button, hopefully better quality backgrounds for lower resolutions


recording: Improved VPad analog alignment

Co-authored-by: sonicfind
recording: Some final VirtualPad coordinate adjustments
  • Loading branch information
xTVaser authored and refractionpcsx2 committed Oct 1, 2020
1 parent 28a4d03 commit 400ed82
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 221 deletions.
3 changes: 0 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@
*.props text eol=crlf
*.vcxproj text eol=crlf
*.vcxproj.filters text eol=crlf

# Hide generated files for easier pull-request reviewing
pcsx2/Recording/VirtualPad/img/*.h linguist-generated
15 changes: 7 additions & 8 deletions .github/workflows/linux-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ jobs:
string(TIMESTAMP current_date "%Y-%m-%d-%H;%M;%S" UTC)
message("::set-output name=timestamp::${current_date}")
# - name: ccache cache files
# uses: actions/cache@v2
# with:
# path: .ccache
# key: ${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
# restore-keys: |
# ${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-ccache-
- name: ccache cache files
uses: actions/cache@v2
with:
path: .ccache
key: ${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
restore-keys: |
${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-ccache-
- name: Install Packages
env:
Expand All @@ -102,4 +102,3 @@ jobs:
chmod +x .github/workflows/scripts/build-linux.sh
./.github/workflows/scripts/build-linux.sh generate_cmake
./.github/workflows/scripts/build-linux.sh compile
ls ./pcsx2/Recording/VirtualPad/img
6 changes: 4 additions & 2 deletions pcsx2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ set(pcsx2RecordingHeaders
set(res_rec_vp_src "${CMAKE_SOURCE_DIR}/pcsx2/Recording/VirtualPad/img")
set(pcsx2RecordingVirtualPadResources
${res_rec_vp_src}/circlePressed.h
${res_rec_vp_src}/controller.h
${res_rec_vp_src}/controllerFull.h
${res_rec_vp_src}/controllerHalf.h
${res_rec_vp_src}/controllerThreeQuarters.h
${res_rec_vp_src}/crossPressed.h
${res_rec_vp_src}/downPressed.h
${res_rec_vp_src}/l1Pressed.h
Expand Down Expand Up @@ -760,7 +762,7 @@ endforeach()
### Generate Recording resource files
### Drop them into the folder alongside the png files
foreach(res_file IN ITEMS
circlePressed controller crossPressed downPressed l1Pressed l2Pressed l3Pressed leftPressed
circlePressed controllerFull controllerHalf controllerThreeQuarters crossPressed downPressed l1Pressed l2Pressed l3Pressed leftPressed
r1Pressed r2Pressed r3Pressed rightPressed selectPressed squarePressed startPressed trianglePressed upPressed)
add_custom_command(OUTPUT "${res_rec_vp_src}/${res_file}.h" COMMAND perl ${CMAKE_SOURCE_DIR}/linux_various/hex2h.pl "${res_rec_vp_src}/${res_file}.png" "${res_rec_vp_src}/${res_file}" )
endforeach()
Expand Down
69 changes: 33 additions & 36 deletions pcsx2/Recording/InputRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ InputRecording g_InputRecording;
InputRecording::InputRecording()
{
// NOTE - No multi-tap support, only two controllers
padData[CONTROLLER_PORT_ONE] = new PadData();
padData[CONTROLLER_PORT_TWO] = new PadData();
padData[CONTROLLER_PORT_ONE] = new PadData();
padData[CONTROLLER_PORT_TWO] = new PadData();
}

void InputRecording::setVirtualPadPtr(VirtualPad *ptr, int const port)
void InputRecording::setVirtualPadPtr(VirtualPad* ptr, int const port)
{
virtualPads[port] = ptr;
}
Expand All @@ -85,62 +85,53 @@ void InputRecording::RecordingReset()
g_InputRecordingControls.Resume();
}

void InputRecording::ControllerInterrupt(u8 &data, u8 &port, u16 &bufCount, u8 buf[])
void InputRecording::ControllerInterrupt(u8& data, u8& port, u16& bufCount, u8 buf[])
{
// TODO - Multi-Tap Support

if (bufCount == 1)
fInterruptFrame = data == READ_DATA_AND_VIBRATE_FIRST_BYTE;
else if (bufCount == 2)
{
if (buf[bufCount] != READ_DATA_AND_VIBRATE_SECOND_BYTE)
fInterruptFrame = false;
}
else if (bufCount == 2 && buf[bufCount] != READ_DATA_AND_VIBRATE_SECOND_BYTE)
fInterruptFrame = false;

// We do not want to record or save the first two bytes in the data returned from the PAD plugin
else if (fInterruptFrame && bufCount >= 3 && frameCounter >= 0 && frameCounter < INT_MAX)
{
u8 &bufVal = buf[bufCount];
const u16 bufIndex = bufCount - 3;
u8& bufVal = buf[bufCount];
const u16 bufIndex = bufCount - 3;

if (state == InputRecordingMode::Replaying)
{
u8 tmp = 0;
if (inputRecordingData.ReadKeyBuffer(tmp, frameCounter, port, bufIndex))
{
// Overwrite value originally provided by the PAD plugin
bufVal = tmp;
// Update controller data state for future VirtualPad / logging usage.
padData[port]->UpdateControllerData(bufIndex, bufVal);
if (virtualPads[port] && virtualPads[port]->IsShown())
{
virtualPads[port]->UpdateControllerData(bufIndex, padData[port]);
}
}
{
// Overwrite value originally provided by the PAD plugin
bufVal = tmp;
}
}

// Update controller data state for future VirtualPad / logging usage.
padData[port]->UpdateControllerData(bufIndex, bufVal);

if (virtualPads[port] && virtualPads[port]->IsShown())
if (virtualPads[port] &&
virtualPads[port]->IsShown() &&
virtualPads[port]->UpdateControllerData(bufIndex, padData[port]) &&
state != InputRecordingMode::Replaying)
{
// If the VirtualPad updated the PadData, we have to update the buffer
// before committing it to the recording / sending it to the game
// - Do not do this if we are in replay mode!
if (virtualPads[port]->UpdateControllerData(bufIndex, padData[port]) && state != InputRecordingMode::Replaying)
{
bufVal = padData[port]->PollControllerData(bufIndex);
}
bufVal = padData[port]->PollControllerData(bufIndex);
}

// If we have reached the end of the pad data, log it out
if (bufIndex == PadData::END_INDEX_CONTROLLER_BUFFER) {
if (bufIndex == PadData::END_INDEX_CONTROLLER_BUFFER)
{
padData[port]->LogPadData(port);
// As well as re-render the virtual pad UI, if applicable
// - Don't render if it's minimized
if (virtualPads[port] && virtualPads[port]->IsShown() && !virtualPads[port]->IsIconized())
{
virtualPads[port]->Redraw();
}
}

// Finally, commit the byte to the movie file if we are recording
Expand All @@ -161,7 +152,7 @@ s32 InputRecording::GetFrameCounter()
return frameCounter;
}

InputRecordingFile &InputRecording::GetInputRecordingData()
InputRecordingFile& InputRecording::GetInputRecordingData()
{
return inputRecordingData;
}
Expand Down Expand Up @@ -223,17 +214,21 @@ wxString InputRecording::RecordingModeTitleSegment()
void InputRecording::SetToRecordMode()
{
state = InputRecordingMode::Recording;
virtualPads[CONTROLLER_PORT_ONE]->SetReadOnlyMode(false);
virtualPads[CONTROLLER_PORT_TWO]->SetReadOnlyMode(false);
recordingConLog("[REC]: Record mode ON.\n");
}

void InputRecording::SetToReplayMode()
{
state = InputRecordingMode::Replaying;
virtualPads[CONTROLLER_PORT_ONE]->SetReadOnlyMode(true);
virtualPads[CONTROLLER_PORT_TWO]->SetReadOnlyMode(true);
recordingConLog("[REC]: Replay mode ON.\n");
}

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");
Expand Down Expand Up @@ -272,6 +267,8 @@ void InputRecording::SetStartingFrame(u32 newStartingFrame)
void InputRecording::Stop()
{
state = InputRecordingMode::NotActive;
virtualPads[CONTROLLER_PORT_ONE]->SetReadOnlyMode(false);
virtualPads[CONTROLLER_PORT_TWO]->SetReadOnlyMode(false);
incrementUndo = false;
if (inputRecordingData.Close())
recordingConLog(L"[REC]: InputRecording Recording Stopped.\n");
Expand Down Expand Up @@ -303,7 +300,7 @@ bool InputRecording::Create(wxString FileName, bool fromSaveState, wxString auth
inputRecordingData.GetHeader().SetGameName(resolveGameName());
// Write header contents
inputRecordingData.WriteHeader();
state = InputRecordingMode::Recording;
SetToRecordMode();
g_InputRecordingControls.DisableFrameAdvance();
recordingConLog(wxString::Format(L"[REC]: Started new recording - [%s]\n", FileName));
return true;
Expand All @@ -328,8 +325,8 @@ bool InputRecording::Play(wxString fileName)
}
if (!wxFileExists(inputRecordingData.GetFilename() + "_SaveState.p2s"))
{
recordingConLog(wxString::Format("[REC]: Could not locate savestate file at location - %s_SaveState.p2s\n",
inputRecordingData.GetFilename()));
recordingConLog(wxString::Format("[REC]: Could not locate savestate file at location - %s_SaveState.p2s\n",
inputRecordingData.GetFilename()));
inputRecordingData.Close();
return false;
}
Expand All @@ -348,7 +345,7 @@ bool InputRecording::Play(wxString fileName)
recordingConLog(L"[REC]: Recording was possibly constructed for a different game.\n");

incrementUndo = true;
state = InputRecordingMode::Replaying;
SetToReplayMode();
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));
Expand Down Expand Up @@ -380,4 +377,4 @@ wxString InputRecording::resolveGameName()
return !gameName.IsEmpty() ? gameName : Path::GetFilename(g_Conf->CurrentIso);
}

#endif
#endif
32 changes: 16 additions & 16 deletions pcsx2/Recording/InputRecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InputRecording
{
public:
InputRecording();

// 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
Expand All @@ -34,26 +34,26 @@ class InputRecording

// 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 &data, u8 &port, u16 &BufCount, u8 buf[]);
void ControllerInterrupt(u8& data, u8& port, u16& BufCount, u8 buf[]);

// The running frame counter for the input recording
s32 GetFrameCounter();

InputRecordingFile &GetInputRecordingData();
InputRecordingFile& GetInputRecordingData();

// The internal PCSX2 g_FrameCount value on the first frame of the recording
u32 GetStartingFrame();

void IncrementFrameCounter();

// DEPRECATED: Slated for removal
// 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
// 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();
Expand All @@ -78,7 +78,7 @@ class InputRecording

// Store the starting internal PCSX2 g_FrameCount value
void SetStartingFrame(u32 newStartingFrame);

/// Functions called from GUI

// Create a new input recording file
Expand All @@ -87,8 +87,8 @@ class InputRecording
bool Play(wxString filename);
// Stop the active input recording
void Stop();

void setVirtualPadPtr(VirtualPad *ptr, int const port);
// Initialze VirtualPad window
void setVirtualPadPtr(VirtualPad* ptr, int const port);

private:
enum class InputRecordingMode
Expand All @@ -99,35 +99,35 @@ class InputRecording
};

static const int CONTROLLER_PORT_ONE = 0;
static const int CONTROLLER_PORT_TWO = 1;
static const int CONTROLLER_PORT_TWO = 1;

// 0x42 is the magic number to indicate the default controller read query
// See - Lilypad.cpp::PADpoll - https://github.com/PCSX2/pcsx2/blob/v1.5.0-dev/plugins/LilyPad/LilyPad.cpp#L1193
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 - LilyPad.cpp::PADpoll - https://github.com/PCSX2/pcsx2/blob/v1.5.0-dev/plugins/LilyPad/LilyPad.cpp#L1194
static const u8 READ_DATA_AND_VIBRATE_SECOND_BYTE = 0x5A;
static const u8 READ_DATA_AND_VIBRATE_SECOND_BYTE = 0x5A;

// DEPRECATED: Slated for removal
// 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;

// Controller Data
PadData *padData[2];
PadData* padData[2];

// VirtualPads
VirtualPad *virtualPads[2];
VirtualPad* virtualPads[2];

// 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
wxString resolveGameName();
};

extern InputRecording g_InputRecording;

#endif
#endif
11 changes: 6 additions & 5 deletions pcsx2/Recording/NewRecordingFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@


#ifndef DISABLE_RECORDING
NewRecordingFrame::NewRecordingFrame(wxWindow *parent)
NewRecordingFrame::NewRecordingFrame(wxWindow* parent)
: wxDialog(parent, wxID_ANY, "New Input Recording", wxDefaultPosition, wxDefaultSize, wxSTAY_ON_TOP | wxCAPTION)
{
wxPanel *panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("panel"));
wxPanel* panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("panel"));

wxFlexGridSizer *fgs = new wxFlexGridSizer(4, 2, 20, 20);
wxBoxSizer *container = new wxBoxSizer(wxVERTICAL);
wxFlexGridSizer* fgs = new wxFlexGridSizer(4, 2, 20, 20);
wxBoxSizer* container = new wxBoxSizer(wxVERTICAL);

m_fileLabel = new wxStaticText(panel, wxID_ANY, _("File Path"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
m_authorLabel = new wxStaticText(panel, wxID_ANY, _("Author"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
Expand Down Expand Up @@ -65,7 +65,8 @@ wxString NewRecordingFrame::GetFile() const
wxString path = m_filePicker->GetPath();
// wxWidget's removes the extension if it contains wildcards
// on wxGTK https://trac.wxwidgets.org/ticket/15285
if (!path.EndsWith(".p2m2")) {
if (!path.EndsWith(".p2m2"))
{
return wxString::Format("%s.p2m2", path);
}
return path;
Expand Down
18 changes: 9 additions & 9 deletions pcsx2/Recording/NewRecordingFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ enum MenuIds_New_Recording_Frame
class NewRecordingFrame : public wxDialog
{
public:
NewRecordingFrame(wxWindow *parent);
NewRecordingFrame(wxWindow* parent);

wxString GetFile() const;
wxString GetAuthor() const;
int GetFrom() const;

private:
wxStaticText *m_fileLabel;
wxFilePickerCtrl *m_filePicker;
wxStaticText *m_authorLabel;
wxTextCtrl *m_authorInput;
wxStaticText *m_fromLabel;
wxChoice *m_fromChoice;
wxButton *m_startRecording;
wxButton *m_cancelRecording;
wxStaticText* m_fileLabel;
wxFilePickerCtrl* m_filePicker;
wxStaticText* m_authorLabel;
wxTextCtrl* m_authorInput;
wxStaticText* m_fromLabel;
wxChoice* m_fromChoice;
wxButton* m_startRecording;
wxButton* m_cancelRecording;
};
#endif
2 changes: 0 additions & 2 deletions pcsx2/Recording/PadData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ wxString PadData::RawPadBytesToString(int start, int end)
{
str += wxString::Format("%d", PollControllerData(i));
if (i != end - 1)
{
str += ", ";
}
}
return str;
}
Expand Down
Loading

0 comments on commit 400ed82

Please sign in to comment.