Fix loading of savegames which use LZO compression

pull/115/head
Jonathan G Rennison 5 years ago
parent b26e173b86
commit 785eed2958

@ -2736,25 +2736,26 @@ struct SaveLoadFormat {
byte min_compression; ///< the minimum compression level of this format
byte default_compression; ///< the default compression level of this format
byte max_compression; ///< the maximum compression level of this format
bool no_threaded_load; ///< unsuitable for threaded loading
};
/** The different saveload formats known/understood by OpenTTD. */
static const SaveLoadFormat _saveload_formats[] = {
#if defined(WITH_LZO)
/* Roughly 75% larger than zlib level 6 at only ~7% of the CPU usage. */
{"lzo", TO_BE32X('OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0},
{"lzo", TO_BE32X('OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0, true},
#else
{"lzo", TO_BE32X('OTTD'), nullptr, nullptr, 0, 0, 0},
{"lzo", TO_BE32X('OTTD'), nullptr, nullptr, 0, 0, 0, false},
#endif
/* Roughly 5 times larger at only 1% of the CPU usage over zlib level 6. */
{"none", TO_BE32X('OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
{"none", TO_BE32X('OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0, false},
#if defined(WITH_ZLIB)
/* After level 6 the speed reduction is significant (1.5x to 2.5x slower per level), but the reduction in filesize is
* fairly insignificant (~1% for each step). Lower levels become ~5-10% bigger by each level than level 6 while level
* 1 is "only" 3 times as fast. Level 0 results in uncompressed savegames at about 8 times the cost of "none". */
{"zlib", TO_BE32X('OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9},
{"zlib", TO_BE32X('OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9, false},
#else
{"zlib", TO_BE32X('OTTZ'), nullptr, nullptr, 0, 0, 0},
{"zlib", TO_BE32X('OTTZ'), nullptr, nullptr, 0, 0, 0, false},
#endif
#if defined(WITH_LIBLZMA)
/* Level 2 compression is speed wise as fast as zlib level 6 compression (old default), but results in ~10% smaller saves.
@ -2762,9 +2763,9 @@ static const SaveLoadFormat _saveload_formats[] = {
* The next significant reduction in file size is at level 4, but that is already 4 times slower. Level 3 is primarily 50%
* slower while not improving the filesize, while level 0 and 1 are faster, but don't reduce savegame size much.
* It's OTTX and not e.g. OTTL because liblzma is part of xz-utils and .tar.xz is preferred over .tar.lzma. */
{"lzma", TO_BE32X('OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9},
{"lzma", TO_BE32X('OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9, false},
#else
{"lzma", TO_BE32X('OTTX'), nullptr, nullptr, 0, 0, 0},
{"lzma", TO_BE32X('OTTX'), nullptr, nullptr, 0, 0, 0, false},
#endif
};
@ -3176,7 +3177,9 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
}
_sl.lf = fmt->init_load(_sl.lf);
_sl.lf = new ThreadedLoadFilter(_sl.lf);
if (!fmt->no_threaded_load) {
_sl.lf = new ThreadedLoadFilter(_sl.lf);
}
_sl.reader = new ReadBuffer(_sl.lf);
_next_offs = 0;

Loading…
Cancel
Save