add option to automatically save states when exiting emulation

This commit is contained in:
thrust26 2019-06-03 21:55:40 +02:00
parent 58b8c3458b
commit 0eb7cd70da
6 changed files with 66 additions and 4 deletions

View File

@ -2185,6 +2185,11 @@
saving a ROM state file.</td>
</tr>
<tr>
<td><pre>-saveonexit &lt;none|current|all&gt;</pre></td>
<td>Automatically save no, current or all states when exiting emulation.</td>
</tr>
<tr>
<td><pre>-fastscbios &lt;1|0&gt;</pre></td>
<td>Disable Supercharger BIOS progress loading bars.</td>
@ -3298,6 +3303,12 @@
'Buffer size'.
</td>
<td>-plr.tm.horizon<br>-dev.tm.horizon</td>
</tr><tr>
<td>When exiting emulation:</td>
<td>
Automatically save no, current or all states when exiting emulation.
</td>
<td>-saveonexit</td>
</tr>
</table>
</td>

View File

@ -705,6 +705,7 @@ void EventHandler::handleEvent(Event::Type event, bool pressed, bool repeated)
case EventHandlerState::EMULATION:
if (pressed && !repeated)
{
exitEmulation();
// Go back to the launcher, or immediately quit
if (myOSystem.settings().getBool("exitlauncher") ||
myOSystem.launcherUsed())
@ -723,6 +724,8 @@ void EventHandler::handleEvent(Event::Type event, bool pressed, bool repeated)
{
saveKeyMapping();
saveJoyMapping();
if (myState != EventHandlerState::LAUNCHER)
exitEmulation();
myOSystem.quit();
}
return;
@ -1570,6 +1573,18 @@ void EventHandler::setState(EventHandlerState state)
myEvent.clear();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::exitEmulation()
{
// TODO: confirm message
string saveOnExit = myOSystem.settings().getString("saveonexit");
if (saveOnExit == "all")
handleEvent(Event::SaveAllStates);
else if (saveOnExit == "current")
handleEvent(Event::SaveState);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = {
{ Event::Quit, "Quit", "" },

View File

@ -308,6 +308,8 @@ class EventHandler
void saveKeyMapping();
void saveJoyMapping();
void exitEmulation();
protected:
// Global OSystem object
OSystem& myOSystem;

View File

@ -104,10 +104,11 @@ Settings::Settings()
setPermanent("snapsavedir", "");
setPermanent("snaploaddir", "");
setPermanent("snapname", "int");
setPermanent("autoslot", "false");
setPermanent("sssingle", "false");
setPermanent("ss1x", "false");
setPermanent("ssinterval", "2");
setPermanent("autoslot", "false");
setPermanent("saveonexit", "ALL");
// Config files and paths
setPermanent("romdir", "");
@ -451,13 +452,15 @@ void Settings::usage() const
<< " -snaploaddir <path> The directory to load snapshot files from\n"
<< " -snapname <int|rom> Name snapshots according to internal database or\n"
<< " ROM\n"
<< " -autoslot <1|0> Automatically switch to next save slot when\n"
<< " state saving\n"
<< " -sssingle <1|0> Generate single snapshot instead of many\n"
<< " -ss1x <1|0> Generate TIA snapshot in 1x mode (ignore\n"
<< " scaling/effects)\n"
<< " -ssinterval <number Number of seconds between snapshots in\n"
<< " -ssinterval <number> Number of seconds between snapshots in\n"
<< " continuous snapshot mode\n"
<< " -autoslot <1|0> Automatically switch to next save slot when\n"
<< " state saving\n"
<< " -saveonexit <none|current Automatically save state(s) when exiting emulation\n"
<< " all>\n"
<< endl
<< " -rominfo <rom> Display detailed information for the given ROM\n"
<< " -listrominfo Display contents of stella.pro, one line per ROM\n"

View File

@ -472,6 +472,24 @@ void DeveloperDialog::addTimeMachineTab(const GUI::Font& font)
lineHeight, items, "Horizon ~ ", 0, kHorizonChanged);
wid.push_back(myStateHorizonWidget);
ypos += lineHeight + VGAP * 2;
new StaticTextWidget(myTab, font, HBORDER, ypos + 1,
"When exiting emulation:");
ypos += lineHeight + VGAP;
mySaveOnExitGroup = new RadioButtonGroup();
r = new RadioButtonWidget(myTab, font, HBORDER + INDENT, ypos + 1,
"Save nothing", mySaveOnExitGroup);
wid.push_back(r);
ypos += lineHeight + VGAP;
r = new RadioButtonWidget(myTab, font, HBORDER + INDENT, ypos + 1,
"Save current state in current slot", mySaveOnExitGroup);
wid.push_back(r);
ypos += lineHeight + VGAP;
r = new RadioButtonWidget(myTab, font, HBORDER + INDENT, ypos + 1,
"Save all states", mySaveOnExitGroup);
wid.push_back(r);
ypos += lineHeight + VGAP;
// Add message concerning usage
const GUI::Font& infofont = instance().frameBuffer().infoFont();
ypos = myTab->getHeight() - 5 - fontHeight - infofont.getFontHeight() - 10;
@ -625,6 +643,8 @@ void DeveloperDialog::loadSettings(SettingsSet set)
myUncompressed[set] = instance().settings().getInt(prefix + "tm.uncompressed");
myStateInterval[set] = instance().settings().getString(prefix + "tm.interval");
myStateHorizon[set] = instance().settings().getString(prefix + "tm.horizon");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -813,6 +833,10 @@ void DeveloperDialog::loadConfig()
// Debug colours
handleDebugColours(instance().settings().getString("tia.dbgcolors"));
// Save on exit
string saveOnExit = instance().settings().getString("saveonexit");
mySaveOnExitGroup->setSelected(saveOnExit == "all" ? 2 : saveOnExit == "current" ? 1 : 0);
#ifdef DEBUGGER_SUPPORT
uInt32 w, h;
@ -889,6 +913,11 @@ void DeveloperDialog::saveConfig()
instance().state().setRewindMode(myTimeMachineWidget->getState() ?
StateManager::Mode::TimeMachine : StateManager::Mode::Off);
// Save on exit
int saveOnExit = mySaveOnExitGroup->getSelected();
instance().settings().setValue("saveonexit",
saveOnExit == 0 ? "none" : saveOnExit == 1 ? "current" : "all");
#ifdef DEBUGGER_SUPPORT
// Debugger font style
instance().settings().setValue("dbg.fontstyle",
@ -975,6 +1004,7 @@ void DeveloperDialog::setDefaults()
myStateHorizon[set] = devSettings ? "30s" : "10m";
setWidgetStates(set);
mySaveOnExitGroup->setSelected(0);
break;
case 4: // Debugger options

View File

@ -134,6 +134,7 @@ class DeveloperDialog : public Dialog
SliderWidget* myUncompressedWidget;
PopUpWidget* myStateIntervalWidget;
PopUpWidget* myStateHorizonWidget;
RadioButtonGroup* mySaveOnExitGroup;
#ifdef DEBUGGER_SUPPORT
// Debugger UI widgets