aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorColin Snover2017-07-29 22:41:31 -0500
committerColin Snover2017-07-30 19:10:50 -0500
commit325fd1a3efdbeaaf01a61a9905d40cc91ad9f6c3 (patch)
treeef8fe6a1cb1fd29ccdfd7286fef070b2be70ba5b /engines
parente4b3478d9905e42b96430fb311b92293f295fc78 (diff)
downloadscummvm-rg350-325fd1a3efdbeaaf01a61a9905d40cc91ad9f6c3.tar.gz
scummvm-rg350-325fd1a3efdbeaaf01a61a9905d40cc91ad9f6c3.tar.bz2
scummvm-rg350-325fd1a3efdbeaaf01a61a9905d40cc91ad9f6c3.zip
SCI32: Deduplicate guest additions save/load code
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/guest_additions.cpp101
-rw-r--r--engines/sci/engine/guest_additions.h11
2 files changed, 56 insertions, 56 deletions
diff --git a/engines/sci/engine/guest_additions.cpp b/engines/sci/engine/guest_additions.cpp
index a508b5176b..6b9b98d83d 100644
--- a/engines/sci/engine/guest_additions.cpp
+++ b/engines/sci/engine/guest_additions.cpp
@@ -421,70 +421,65 @@ reg_t GuestAdditions::kScummVMSaveLoad(EngineState *s, int argc, reg_t *argv) co
}
reg_t GuestAdditions::promptSaveRestoreDefault(EngineState *s, int argc, reg_t *argv) const {
- const bool isSave = (argc > 0);
- int saveNo;
+ return make_reg(0, runSaveRestore(argc > 0, argc > 0 ? argv[0] : NULL_REG, s->_delayedRestoreGameId));
+}
+
+reg_t GuestAdditions::promptSaveRestoreTorin(EngineState *s, int argc, reg_t *argv) const {
+ const bool isSave = (argc > 0 && (bool)argv[0].toSint16());
+ reg_t descriptionId = NULL_REG;
if (isSave) {
- GUI::SaveLoadChooser dialog(_("Save game:"), _("Save"), true);
- saveNo = dialog.runModalWithCurrentTarget();
- if (saveNo != -1) {
- reg_t descriptionId;
- if (_segMan->isObject(argv[0])) {
- descriptionId = readSelector(_segMan, argv[0], SELECTOR(data));
- } else {
- descriptionId = argv[0];
- }
- SciArray &description = *_segMan->lookupArray(descriptionId);
- Common::String descriptionString = dialog.getResultString();
- if (descriptionString.empty())
- descriptionString = dialog.createDefaultSaveDescription(saveNo - 1);
- description.fromString(descriptionString);
- }
- } else {
- if (s->_delayedRestoreGameId != -1) {
- saveNo = s->_delayedRestoreGameId;
- } else {
- GUI::SaveLoadChooser dialog(_("Restore game:"), _("Restore"), false);
- saveNo = dialog.runModalWithCurrentTarget();
- }
+ _segMan->allocateArray(kArrayTypeString, 0, &descriptionId);
}
- if (saveNo > 0) {
- // The autosave slot in ScummVM takes up slot 0, but in SCI the first
- // non-autosave save game number needs to be 0, so reduce the save
- // number here to match what would come from the normal SCI save/restore
- // dialog. There is additional special code for handling the autosave
- // game inside of kRestoreGame32.
- --saveNo;
+ const int saveNo = runSaveRestore(isSave, descriptionId, s->_delayedRestoreGameId);
+
+ if (saveNo != -1) {
+ assert(s->variablesMax[VAR_LOCAL] > 2);
+ writeSelector(_segMan, s->variables[VAR_LOCAL][1], SELECTOR(data), descriptionId);
+ s->variables[VAR_LOCAL][2] = make_reg(0, saveNo);
+ s->variables[VAR_LOCAL][3] = make_reg(0, isSave ? 1 : 0);
+ } else if (isSave) {
+ _segMan->freeArray(descriptionId);
}
- return make_reg(0, saveNo);
+ return make_reg(0, saveNo != -1);
}
-reg_t GuestAdditions::promptSaveRestoreTorin(EngineState *s, int argc, reg_t *argv) const {
- const bool isSave = (argc > 0 && (bool)argv[0].toSint16());
+int GuestAdditions::runSaveRestore(const bool isSave, reg_t outDescription, const int forcedSaveNo) const {
int saveNo;
+ Common::String descriptionString;
- if (isSave) {
- GUI::SaveLoadChooser dialog(_("Save game:"), _("Save"), true);
+ if (!isSave && forcedSaveNo != -1) {
+ saveNo = forcedSaveNo;
+ } else {
+ const char *title;
+ const char *action;
+ if (isSave) {
+ title = _("Save game:");
+ action = _("Save");
+ } else {
+ title = _("Restore game:");
+ action = _("Restore");
+ }
+
+ GUI::SaveLoadChooser dialog(title, action, isSave);
saveNo = dialog.runModalWithCurrentTarget();
if (saveNo != -1) {
- reg_t descriptionId = s->variables[VAR_LOCAL][1];
- reg_t dataId;
- SciArray &description = *_segMan->allocateArray(kArrayTypeString, 0, &dataId);
- Common::String descriptionString = dialog.getResultString();
- if (descriptionString.empty())
+ descriptionString = dialog.getResultString();
+ if (descriptionString.empty()) {
descriptionString = dialog.createDefaultSaveDescription(saveNo - 1);
- description.fromString(descriptionString);
- writeSelector(_segMan, descriptionId, SELECTOR(data), dataId);
+ }
}
- } else {
- if (s->_delayedRestoreGameId != -1) {
- saveNo = s->_delayedRestoreGameId;
- } else {
- GUI::SaveLoadChooser dialog(_("Restore game:"), _("Restore"), false);
- saveNo = dialog.runModalWithCurrentTarget();
+ }
+
+ assert(!isSave || !outDescription.isNull());
+ if (!outDescription.isNull()) {
+ if (_segMan->isObject(outDescription)) {
+ outDescription = readSelector(_segMan, outDescription, SELECTOR(data));
}
+ SciArray &description = *_segMan->lookupArray(outDescription);
+ description.fromString(descriptionString);
}
if (saveNo > 0) {
@@ -496,13 +491,7 @@ reg_t GuestAdditions::promptSaveRestoreTorin(EngineState *s, int argc, reg_t *ar
--saveNo;
}
- if (saveNo != -1) {
- assert(s->variablesMax[VAR_LOCAL] > 2);
- s->variables[VAR_LOCAL][2] = make_reg(0, saveNo);
- s->variables[VAR_LOCAL][3] = make_reg(0, isSave ? 1 : 0);
- }
-
- return make_reg(0, saveNo != -1);
+ return saveNo;
}
#endif
diff --git a/engines/sci/engine/guest_additions.h b/engines/sci/engine/guest_additions.h
index 68bb7d17d7..657fa52318 100644
--- a/engines/sci/engine/guest_additions.h
+++ b/engines/sci/engine/guest_additions.h
@@ -198,6 +198,17 @@ private:
* custom NewGame class semantics.
*/
reg_t promptSaveRestoreTorin(EngineState *s, int argc, reg_t *argv) const;
+
+ /**
+ * Prompts the user to save or load a game.
+ *
+ * @param isSave If true, the prompt is for saving.
+ * @param outDescription Will be filled with the save game description.
+ * Optional for loads, required for saves.
+ * @param forcedSaveNo During delayed restore, force the returned save game
+ * number to this value.
+ */
+ int runSaveRestore(const bool isSave, const reg_t outDescription, const int forcedSaveNo = -1) const;
#endif
#pragma mark -