diff options
author | David Turner | 2011-12-18 18:29:05 -0800 |
---|---|---|
committer | David Turner | 2011-12-18 18:29:05 -0800 |
commit | 538d83408091e9077f451f45c1ac1127f302b47d (patch) | |
tree | a8b3ffaf9199665b41e8f990549fc267c6421b46 /engines/tinsel/saveload.cpp | |
parent | f0eee81d327957cddb85c5a1ffe7a308a377f636 (diff) | |
parent | f722542ceea557e906699c60b10b3ace1f41c238 (diff) | |
download | scummvm-rg350-538d83408091e9077f451f45c1ac1127f302b47d.tar.gz scummvm-rg350-538d83408091e9077f451f45c1ac1127f302b47d.tar.bz2 scummvm-rg350-538d83408091e9077f451f45c1ac1127f302b47d.zip |
Merge pull request #131 from digitall/goto_considered_harmful
Goto Considered Harmful...
The following commits should improve the ScummVM code structure by reducing the number of gotos used in various engine code.
They should implement identical functionality, but without using goto and without the result being less readable/maintainable than the version with goto.
Diffstat (limited to 'engines/tinsel/saveload.cpp')
-rw-r--r-- | engines/tinsel/saveload.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/engines/tinsel/saveload.cpp b/engines/tinsel/saveload.cpp index a0801d8247..8664cd5f15 100644 --- a/engines/tinsel/saveload.cpp +++ b/engines/tinsel/saveload.cpp @@ -486,6 +486,16 @@ static bool DoRestore() { return !failed; } +static void SaveFailure(Common::OutSaveFile *f) { + if (f) { + delete f; + _vm->getSaveFileMan()->removeSavefile(SaveSceneName); + SaveSceneName = NULL; // Invalidate save name + } + GUI::MessageDialog dialog(_("Failed to save game state to file.")); + dialog.runModal(); +} + /** * DoSave */ @@ -524,8 +534,10 @@ static void DoSave() { f = _vm->getSaveFileMan()->openForSaving(SaveSceneName); Common::Serializer s(0, f); - if (f == NULL) - goto save_failure; + if (f == NULL) { + SaveFailure(f); + return; + } // Write out a savegame header SaveGameHeader hdr; @@ -536,29 +548,22 @@ static void DoSave() { hdr.desc[SG_DESC_LEN - 1] = 0; g_system->getTimeAndDate(hdr.dateTime); if (!syncSaveGameHeader(s, hdr) || f->err()) { - goto save_failure; + SaveFailure(f); + return; } DoSync(s); // Write out the special Id for Discworld savegames f->writeUint32LE(0xFEEDFACE); - if (f->err()) - goto save_failure; + if (f->err()) { + SaveFailure(f); + return; + } f->finalize(); delete f; SaveSceneName = NULL; // Invalidate save name - return; - -save_failure: - if (f) { - delete f; - _vm->getSaveFileMan()->removeSavefile(SaveSceneName); - SaveSceneName = NULL; // Invalidate save name - } - GUI::MessageDialog dialog(_("Failed to save game state to file.")); - dialog.runModal(); } /** |