Skip to content
Permalink
Browse files

Added "oldest save" and "slots 1-5" as options for "auto load savestate"

  • Loading branch information...
hissingshark committed Jun 21, 2018
1 parent 28e3152 commit 7fd7afeba98c1bc814796196daff639ec0ccad44
Showing with 70 additions and 10 deletions.
  1. +1 −1 Core/Config.cpp
  2. +1 −1 Core/Config.h
  3. +6 −0 Core/ConfigValues.h
  4. +38 −0 Core/SaveState.cpp
  5. +3 −2 Core/SaveState.h
  6. +19 −4 UI/EmuScreen.cpp
  7. +2 −2 UI/GameSettingsScreen.cpp
@@ -398,7 +398,7 @@ static ConfigSetting generalSettings[] = {
ConfigSetting("ForceLagSync", &g_Config.bForceLagSync, false, true, true),

ReportedConfigSetting("NumWorkerThreads", &g_Config.iNumWorkerThreads, &DefaultNumWorkers, true, true),
ConfigSetting("EnableAutoLoad", &g_Config.bEnableAutoLoad, false, true, true),
ConfigSetting("AutoLoadSaveState", &g_Config.iAutoLoadSaveState, 0, true, true),
ReportedConfigSetting("EnableCheats", &g_Config.bEnableCheats, false, true, true),
ConfigSetting("CwCheatRefreshRate", &g_Config.iCwCheatRefreshRate, 77, true, true),

@@ -175,7 +175,7 @@ struct Config {
int iCurrentStateSlot;
int iRewindFlipFrequency;
bool bEnableStateUndo;
bool bEnableAutoLoad;
int iAutoLoadSaveState; // 0 = off, 1 = oldest, 2 = newest, >2 = slot number + 3
bool bEnableCheats;
bool bReloadCheats;
int iCwCheatRefreshRate;
@@ -71,3 +71,9 @@ enum class SmallDisplayZoom {
AUTO = 2,
MANUAL = 3,
};

enum AutoLoadSaveState {
OFF = 0,
OLDEST = 1,
NEWEST = 2,
};
@@ -550,6 +550,27 @@ namespace SaveState
return false;
}

bool operator > (const tm &t1, const tm &t2) {
if (t1.tm_year > t2.tm_year) return true;
if (t1.tm_year < t2.tm_year) return false;
if (t1.tm_mon > t2.tm_mon) return true;
if (t1.tm_mon < t2.tm_mon) return false;
if (t1.tm_mday > t2.tm_mday) return true;
if (t1.tm_mday < t2.tm_mday) return false;
if (t1.tm_hour > t2.tm_hour) return true;
if (t1.tm_hour < t2.tm_hour) return false;
if (t1.tm_min > t2.tm_min) return true;
if (t1.tm_min < t2.tm_min) return false;
if (t1.tm_sec > t2.tm_sec) return true;
if (t1.tm_sec < t2.tm_sec) return false;
return false;
}

bool operator ! (const tm &t1) {
if (t1.tm_year || t1.tm_mon || t1.tm_mday || t1.tm_hour || t1.tm_min || t1.tm_sec) return false;
return true;
}

int GetNewestSlot(const std::string &gameFilename) {
int newestSlot = -1;
tm newestDate = {0};
@@ -567,6 +588,23 @@ namespace SaveState
return newestSlot;
}

int GetOldestSlot(const std::string &gameFilename) {
int oldestSlot = -1;
tm oldestDate = {0};
for (int i = 0; i < NUM_SLOTS; i++) {
std::string fn = GenerateSaveSlotFilename(gameFilename, i, STATE_EXTENSION);
if (File::Exists(fn)) {
tm time;
bool success = File::GetModifTime(fn, time);
if (success && (!oldestDate || oldestDate > time)) {
oldestDate = time;
oldestSlot = i;
}
}
}
return oldestSlot;
}

std::string GetSlotDateAsString(const std::string &gameFilename, int slot) {
std::string fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
if (File::Exists(fn)) {
@@ -51,9 +51,10 @@ namespace SaveState

int GetCurrentSlot();

// Returns -1 if there's no newest slot.
// Returns -1 if there's no oldest/newest slot.
int GetNewestSlot(const std::string &gameFilename);

int GetOldestSlot(const std::string &gameFilename);

std::string GetSlotDateAsString(const std::string &gameFilename, int slot);
std::string GenerateSaveSlotFilename(const std::string &gameFilename, int slot, const char *extension);

@@ -1337,11 +1337,26 @@ void EmuScreen::renderUI() {
}

void EmuScreen::autoLoad() {
int autoSlot = -1;

//check if save state has save, if so, load
int lastSlot = SaveState::GetNewestSlot(gamePath_);
if (g_Config.bEnableAutoLoad && lastSlot != -1) {
SaveState::LoadSlot(gamePath_, lastSlot, &AfterSaveStateAction);
g_Config.iCurrentStateSlot = lastSlot;
switch (g_Config.iAutoLoadSaveState) {
case AutoLoadSaveState::OFF: // "AutoLoad Off"
return;
case AutoLoadSaveState::OLDEST: // "Oldest Save"
autoSlot = SaveState::GetOldestSlot(gamePath_);
break;
case AutoLoadSaveState::NEWEST: // "Newest Save"
autoSlot = SaveState::GetNewestSlot(gamePath_);
break;
default: // try the specific save state slot specified
autoSlot = (SaveState::HasSaveInSlot(gamePath_, g_Config.iAutoLoadSaveState - 3)) ? (g_Config.iAutoLoadSaveState - 3) : -1;
break;
}

if (g_Config.iAutoLoadSaveState && autoSlot != -1) {
SaveState::LoadSlot(gamePath_, autoSlot, &AfterSaveStateAction);
g_Config.iCurrentStateSlot = autoSlot;
}
}

@@ -734,8 +734,8 @@ void GameSettingsScreen::CreateViews() {

systemSettings->Add(new Choice(sy->T("Restore Default Settings")))->OnClick.Handle(this, &GameSettingsScreen::OnRestoreDefaultSettings);
systemSettings->Add(new CheckBox(&g_Config.bEnableStateUndo, sy->T("Savestate slot backups")));
systemSettings->Add(new CheckBox(&g_Config.bEnableAutoLoad, sy->T("Auto Load Newest Savestate")));

static const char *autoLoadSaveStateChoices[] = { "Off", "Oldest Save", "Newest Save", "Slot 1", "Slot 2", "Slot 3", "Slot 4", "Slot 5" };
systemSettings->Add(new PopupMultiChoice(&g_Config.iAutoLoadSaveState, sy->T("Auto Load Savestate"), autoLoadSaveStateChoices, 0, ARRAY_SIZE(autoLoadSaveStateChoices), sy->GetName(), screenManager()));
#if defined(USING_WIN_UI)
systemSettings->Add(new CheckBox(&g_Config.bBypassOSKWithKeyboard, sy->T("Enable Windows native keyboard", "Enable Windows native keyboard")));
#endif

0 comments on commit 7fd7afe

Please sign in to comment.
You can’t perform that action at this time.