Skip to content

Commit

Permalink
input-rec: Set frame count to zero on "reset"
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicfind authored and refractionpcsx2 committed Nov 27, 2022
1 parent 5cd243f commit 592395d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 13 additions & 4 deletions pcsx2/Recording/InputRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ bool InputRecording::create(const std::string& fileName, const bool fromSaveStat
{
FileSystem::CopyFilePath(savestatePath.c_str(), fmt::format("{}.bak", savestatePath).c_str(), true);
}
m_initial_savestate_load_complete = false;
m_initial_load_complete = false;
m_type = Type::FROM_SAVESTATE;
m_is_active = true;
// TODO - error handling
Expand All @@ -527,6 +527,7 @@ bool InputRecording::create(const std::string& fileName, const bool fromSaveStat
{
m_starting_frame = 0;
m_type = Type::POWER_ON;
m_initial_load_complete = false;
m_is_active = true;
// TODO - should this be an explicit [full] boot instead of a reset?
VMManager::Reset();
Expand Down Expand Up @@ -561,7 +562,7 @@ bool InputRecording::play(const std::string& filename)
return false;
}
m_type = Type::FROM_SAVESTATE;
m_initial_savestate_load_complete = false;
m_initial_load_complete = false;
m_is_active = true;
const auto loaded = VMManager::LoadState(savestatePath.c_str());
if (!loaded)
Expand All @@ -576,6 +577,7 @@ bool InputRecording::play(const std::string& filename)
{
m_starting_frame = 0;
m_type = Type::POWER_ON;
m_initial_load_complete = false;
m_is_active = true;
// TODO - should this be an explicit [full] boot instead of a reset?
VMManager::Reset();
Expand Down Expand Up @@ -695,6 +697,13 @@ void InputRecording::handleExceededFrameCounter()
}
}

void InputRecording::handleReset()
{
if (m_initial_load_complete)
adjustFrameCounterOnReRecord(0);
m_initial_load_complete = true;
}

void InputRecording::handleLoadingSavestate()
{
// We need to keep track of the starting internal frame of the recording
Expand All @@ -704,10 +713,10 @@ void InputRecording::handleLoadingSavestate()
// Why?
// - When you re-record you load another save-state which has it's own frame counter
// stored within, we use this to adjust the frame we are replaying/recording to
if (isTypeSavestate() && !m_initial_savestate_load_complete)
if (isTypeSavestate() && !m_initial_load_complete)
{
setStartingFrame(g_FrameCount);
m_initial_savestate_load_complete = true;
m_initial_load_complete = true;
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion pcsx2/Recording/InputRecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class InputRecording
void ControllerInterrupt(u8 port, size_t fifoSize, u8 dataIn, u8 dataOut);

void handleExceededFrameCounter();
void handleReset();
void handleLoadingSavestate();
bool isTypeSavestate() const;
void adjustFrameCounterOnReRecord(u32 newFrameCounter);
Expand All @@ -196,7 +197,7 @@ class InputRecording

Type m_type;

bool m_initial_savestate_load_complete = false;
bool m_initial_load_complete = false;
bool m_is_active = false;
bool m_pad_data_available = false;
bool m_watching_for_rerecords = false;
Expand Down
5 changes: 5 additions & 0 deletions pcsx2/VMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,11 @@ void VMManager::Reset()
// gameid change, so apply settings
if (game_was_started)
UpdateRunningGame(true, false);

if (g_InputRecording.isActive())
{
g_InputRecording.handleReset();
}
}

std::string VMManager::GetSaveStateFileName(const char* game_serial, u32 game_crc, s32 slot)
Expand Down

0 comments on commit 592395d

Please sign in to comment.