diff options
author | rubidium <rubidium@openttd.org> | 2010-01-10 14:57:05 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-01-10 14:57:05 +0000 |
commit | 188c8ebd5c56b3bf33045731052c86fb14cd7221 (patch) | |
tree | 28701ce4d2e413cbbce2465df1a582480bc3d70c | |
parent | f5053cee7e45f582d4dede4025cfaa0a1bd39b96 (diff) | |
download | openttd-188c8ebd5c56b3bf33045731052c86fb14cd7221.tar.xz |
(svn r18771) -Codechange: minor cleanups in saveload code
-rw-r--r-- | src/saveload/saveload.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 8d0a09a81..bdd8728aa 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1613,23 +1613,23 @@ static const SaveLoadFormat _saveload_formats[] = { }; /** - * Return the savegameformat of the game. Whether it was create with ZLIB compression + * Return the savegameformat of the game. Whether it was created with ZLIB compression * uncompressed, or another type * @param s Name of the savegame format. If NULL it picks the first available one * @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame */ static const SaveLoadFormat *GetSavegameFormat(const char *s) { - const SaveLoadFormat *def = endof(_saveload_formats) - 1; + const SaveLoadFormat *def = lastof(_saveload_formats); /* find default savegame format, the highest one with which files can be written */ while (!def->init_write) def--; - if (s != NULL && s[0] != '\0') { - const SaveLoadFormat *slf; - for (slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) { - if (slf->init_write != NULL && strcmp(s, slf->name) == 0) + if (!StrEmpty(s)) { + for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) { + if (slf->init_write != NULL && strcmp(s, slf->name) == 0) { return slf; + } } ShowInfoF("Savegame format '%s' is not available. Reverting to '%s'.", s, def->name); @@ -1705,16 +1705,12 @@ static void SaveFileError() */ static SaveOrLoadResult SaveFileToDisk(bool threaded) { - const SaveLoadFormat *fmt; - uint32 hdr[2]; - _sl.excpt_uninit = NULL; try { - fmt = GetSavegameFormat(_savegame_format); + const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format); /* We have written our stuff to memory, now write it to file! */ - hdr[0] = fmt->tag; - hdr[1] = TO_BE32(SAVEGAME_VERSION << 16); + uint32 hdr[2] = { fmt->tag, TO_BE32(SAVEGAME_VERSION << 16) }; if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE); if (!fmt->init_write()) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor"); |