diff options
author | md5 | 2011-04-10 14:19:28 +0300 |
---|---|---|
committer | md5 | 2011-04-10 14:27:50 +0300 |
commit | c89f2276d1b52a99f08861c5acd86fedb349c718 (patch) | |
tree | 757e72fa343d348f0031a96a82833099d14aba64 /engines/tinsel | |
parent | d1c4b56223e0d586a4f5a9b21bbf7420bb194da7 (diff) | |
download | scummvm-rg350-c89f2276d1b52a99f08861c5acd86fedb349c718.tar.gz scummvm-rg350-c89f2276d1b52a99f08861c5acd86fedb349c718.tar.bz2 scummvm-rg350-c89f2276d1b52a99f08861c5acd86fedb349c718.zip |
TINSEL: Merged NewName() inside DoSave() in order to remove a static var
Diffstat (limited to 'engines/tinsel')
-rw-r--r-- | engines/tinsel/saveload.cpp | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/engines/tinsel/saveload.cpp b/engines/tinsel/saveload.cpp index c965666e84..3182593a88 100644 --- a/engines/tinsel/saveload.cpp +++ b/engines/tinsel/saveload.cpp @@ -77,9 +77,6 @@ SRSTATE SRstate = SR_IDLE; // in DOS_DW.C extern void syncSCdata(Common::Serializer &s); -// in DOS_MAIN.C -//char HardDriveLetter(); - // in PCODE.C extern void syncGlobInfo(Common::Serializer &s); @@ -283,32 +280,6 @@ static void syncSavedData(Common::Serializer &s, SAVED_DATA &sd) { } } - -/** - * Called when saving a game to a new file. - * Generates a new, unique, filename. - */ -static char *NewName() { - static char result[FNAMELEN]; // FIXME: Avoid non-const global vars - int i; - int ano = 1; // Allocated number - - while (1) { - Common::String fname = _vm->getSavegameFilename(ano); - strcpy(result, fname.c_str()); - - for (i = 0; i < numSfiles; i++) - if (!strcmp(savedFiles[i].name, result)) - break; - - if (i == numSfiles) - break; - ano++; - } - - return result; -} - /** * Compare two TimeDate structs to see which one was earlier. * Returns 0 if they are equal, a negative value if a is lower / first, and @@ -498,19 +469,37 @@ static bool DoRestore() { */ static void DoSave() { Common::OutSaveFile *f; - const char *fname; + char tmpName[FNAMELEN]; // Next getList() must do its stuff again NeedLoad = true; - if (SaveSceneName == NULL) - SaveSceneName = NewName(); + if (SaveSceneName == NULL) { + // Generate a new unique save name + int i; + int ano = 1; // Allocated number + + while (1) { + Common::String fname = _vm->getSavegameFilename(ano); + strcpy(tmpName, fname.c_str()); + + for (i = 0; i < numSfiles; i++) + if (!strcmp(savedFiles[i].name, tmpName)) + break; + + if (i == numSfiles) + break; + ano++; + } + + SaveSceneName = tmpName; + } + + if (SaveSceneDesc[0] == 0) SaveSceneDesc = "unnamed"; - fname = SaveSceneName; - - f = _vm->getSaveFileMan()->openForSaving(fname); + f = _vm->getSaveFileMan()->openForSaving(SaveSceneName); Common::Serializer s(0, f); if (f == NULL) @@ -537,12 +526,14 @@ static void DoSave() { f->finalize(); delete f; + SaveSceneName = NULL; // Invalidate save name return; save_failure: if (f) { delete f; - _vm->getSaveFileMan()->removeSavefile(fname); + _vm->getSaveFileMan()->removeSavefile(SaveSceneName); + SaveSceneName = NULL; // Invalidate save name } GUI::MessageDialog dialog("Failed to save game state to file."); dialog.runModal(); |