Skip to content

Commit

Permalink
Merge pull request #11592 from unknownbrackets/savestate
Browse files Browse the repository at this point in the history
SaveState: Retry failed state screenshots
  • Loading branch information
hrydgard committed Nov 25, 2018
2 parents 2582e3e + 38461ed commit 8e56c62
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Core/SaveState.cpp
Expand Up @@ -240,6 +240,7 @@ namespace SaveState
static bool needsProcess = false;
static std::vector<Operation> pending;
static std::mutex mutex;
static int screenshotFailures = 0;
static bool hasLoadedState = false;
static const int STALE_STATE_USES = 2;
// 4 hours of total gameplay since the virtual PSP started the game.
Expand All @@ -249,6 +250,7 @@ namespace SaveState

// TODO: Should this be configurable?
static const int REWIND_NUM_STATES = 20;
static const int SCREENSHOT_FAILURE_RETRIES = 15;
static StateRingbuffer rewindStates(REWIND_NUM_STATES);
// TODO: Any reason for this to be configurable?
const static float rewindMaxWallFrequency = 1.0f;
Expand Down Expand Up @@ -852,6 +854,12 @@ namespace SaveState
callbackResult = tempResult ? Status::SUCCESS : Status::FAILURE;
if (!tempResult) {
ERROR_LOG(SAVESTATE, "Failed to take a screenshot for the savestate! %s", op.filename.c_str());
if (screenshotFailures++ < SCREENSHOT_FAILURE_RETRIES) {
// Requeue for next frame.
SaveScreenshot(op.filename, op.callback, op.cbUserData);
}
} else {
screenshotFailures = 0;
}
break;
}
Expand Down
26 changes: 26 additions & 0 deletions UI/SavedataScreen.cpp
Expand Up @@ -323,6 +323,8 @@ void SavedataBrowser::SetSortOption(SavedataSortOption opt) {
gl->SetCompare(&ByFilename, &SortDone);
} else if (sortOption_ == SavedataSortOption::SIZE) {
gl->SetCompare(&BySize, &SortDone);
} else if (sortOption_ == SavedataSortOption::DATE) {
gl->SetCompare(&ByDate, &SortDone);
}
}
}
Expand All @@ -345,6 +347,29 @@ bool SavedataBrowser::BySize(const UI::View *v1, const UI::View *v2) {
return g1info->gameSize > g2info->gameSize;
}

bool SavedataBrowser::ByDate(const UI::View *v1, const UI::View *v2) {
const SavedataButton *b1 = static_cast<const SavedataButton *>(v1);
const SavedataButton *b2 = static_cast<const SavedataButton *>(v2);

auto getDateSeconds = [&](const SavedataButton *b) {
std::shared_ptr<GameInfo> ginfo = g_gameInfoCache->GetInfo(nullptr, b->GamePath(), 0);
tm datetm;
bool success;
if (ginfo && ginfo->fileType == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY) {
success = File::GetModifTime(b->GamePath() + "/PARAM.SFO", datetm);
} else {
success = File::GetModifTime(b->GamePath(), datetm);
}

if (success) {
return mktime(&datetm);
}
return (time_t)0;
};

return getDateSeconds(b1) > getDateSeconds(b2);
}

bool SavedataBrowser::SortDone() {
PrioritizedWorkQueue *wq = g_gameInfoCache->WorkQueue();
return wq->Done();
Expand Down Expand Up @@ -454,6 +479,7 @@ void SavedataScreen::CreateViews() {
ChoiceStrip *sortStrip = new ChoiceStrip(ORIENT_HORIZONTAL, new AnchorLayoutParams(NONE, 0, 0, NONE));
sortStrip->AddChoice(sa->T("Filename"));
sortStrip->AddChoice(sa->T("Size"));
sortStrip->AddChoice(sa->T("Date"));
sortStrip->SetSelection((int)sortOption_);
sortStrip->OnChoice.Handle<SavedataScreen>(this, &SavedataScreen::OnSortClick);

Expand Down
2 changes: 2 additions & 0 deletions UI/SavedataScreen.h
Expand Up @@ -29,6 +29,7 @@
enum class SavedataSortOption {
FILENAME,
SIZE,
DATE,
};

class SavedataBrowser : public UI::LinearLayout {
Expand All @@ -42,6 +43,7 @@ class SavedataBrowser : public UI::LinearLayout {
private:
static bool ByFilename(const UI::View *, const UI::View *);
static bool BySize(const UI::View *, const UI::View *);
static bool ByDate(const UI::View *, const UI::View *);
static bool SortDone();

void Refresh();
Expand Down

0 comments on commit 8e56c62

Please sign in to comment.