Index: src/saveload/saveload.cpp =================================================================== --- src/saveload/saveload.cpp (revision 27547) +++ src/saveload/saveload.cpp (working copy) @@ -271,6 +271,8 @@ uint16 _sl_version; ///< the major savegame version identifier byte _sl_minor_version; ///< the minor savegame version, DO NOT USE! char _savegame_format[8]; ///< how to compress savegames +char _sendmap_format[8]; ///< how to compress the map to send to a client joining servers +char _autosave_format[8]; ///< how to compress autosaves bool _do_autosave; ///< are we doing an autosave at the moment? /** What are we currently doing? */ @@ -409,6 +411,8 @@ byte ff_state; ///< The state of fast-forward when saving started. bool saveinprogress; ///< Whether there is currently a save in progress. + bool sendmapinprogress; ///< Whether there is currently an encoding of a map in progress while being sent to a client joining the server. + bool autosaveinprogress; ///< Whether there is currently an autosave in progress. }; static SaveLoadParams _sl; ///< Parameters used for/at saveload. @@ -2007,7 +2011,7 @@ if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlErrorCorrupt("Bad checksum"); /* Decompress */ - lzo1x_decompress_safe(out + sizeof(uint32) * 1, size, buf, &len, NULL); + lzo1x_decompress(out + sizeof(uint32) * 1, size, buf, &len, NULL); return len; } }; @@ -2338,9 +2342,11 @@ LoadFilter *(*init_load)(LoadFilter *chain); ///< Constructor for the load filter. SaveFilter *(*init_write)(SaveFilter *chain, byte compression); ///< Constructor for the save filter. - 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 + byte min_compression; ///< the minimum compression level accepted by this format + byte fast_compression; ///< the default fast compression level of this format to be used by openttd + byte default_compression; ///< the default compression level of this format to be used by openttd + byte slow_compression; ///< the default slow compression level of this format to be used by openttd + byte max_compression; ///< the maximum compression level accepted by this format }; /** The different saveload formats known/understood by OpenTTD. */ @@ -2347,19 +2353,19 @@ 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, CreateSaveFilter, 0, 0, 0}, + {"lzo", TO_BE32X('OTTD'), CreateLoadFilter, CreateSaveFilter, 0, 0, 0, 0, 0}, #else - {"lzo", TO_BE32X('OTTD'), NULL, NULL, 0, 0, 0}, + {"lzo", TO_BE32X('OTTD'), NULL, NULL, 0, 0, 0, 0, 0}, #endif /* Roughly 5 times larger at only 1% of the CPU usage over zlib level 6. */ - {"none", TO_BE32X('OTTN'), CreateLoadFilter, CreateSaveFilter, 0, 0, 0}, + {"none", TO_BE32X('OTTN'), CreateLoadFilter, CreateSaveFilter, 0, 0, 0, 0, 0}, #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, CreateSaveFilter, 0, 6, 9}, + {"zlib", TO_BE32X('OTTZ'), CreateLoadFilter, CreateSaveFilter, 0, 1, 6, 9, 9}, #else - {"zlib", TO_BE32X('OTTZ'), NULL, NULL, 0, 0, 0}, + {"zlib", TO_BE32X('OTTZ'), NULL, NULL, 0, 0, 0, 0, 0}, #endif #if defined(WITH_LZMA) /* Level 2 compression is speed wise as fast as zlib level 6 compression (old default), but results in ~10% smaller saves. @@ -2367,9 +2373,9 @@ * 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, CreateSaveFilter, 0, 2, 9}, + {"lzma", TO_BE32X('OTTX'), CreateLoadFilter, CreateSaveFilter, 0, 0, 2, 6, 9}, #else - {"lzma", TO_BE32X('OTTX'), NULL, NULL, 0, 0, 0}, + {"lzma", TO_BE32X('OTTX'), NULL, NULL, 0, 0, 0, 0, 0}, #endif }; @@ -2395,6 +2401,8 @@ for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) { if (slf->init_write != NULL && strcmp(s, slf->name) == 0) { *compression_level = slf->default_compression; + if ((_network_server && !_sl.sendmapinprogress) || (_pause_mode = PM_UNPAUSED && _sl.autosaveinprogress && _sl.ff_state != _fast_forward)) *compression_level = slf->fast_compression; + if (_sl.sendmapinprogress) *compression_level = slf->slow_compression; if (complevel != NULL) { /* There is a compression level in the string. * First restore the : we removed to do proper name matching, @@ -2424,6 +2432,8 @@ if (complevel != NULL) *complevel = ':'; } *compression_level = def->default_compression; + if ((_network_server && !_sl.sendmapinprogress) || (_pause_mode = PM_UNPAUSED && _sl.autosaveinprogress && _sl.ff_state != _fast_forward)) *compression_level = def->fast_compression; + if (_sl.sendmapinprogress) *compression_level = def->slow_compression; return def; } @@ -2463,6 +2473,7 @@ InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START); _sl.saveinprogress = true; + if (_do_autosave) _sl.autosaveinprogress = true; } /** Update the gui accordingly when saving is done and release locks on saveload. */ @@ -2473,6 +2484,8 @@ InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH); _sl.saveinprogress = false; + _sl.sendmapinprogress = false; + _sl.autosaveinprogress = false; } /** Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends) */ @@ -2508,7 +2521,7 @@ { try { byte compression; - const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format, &compression); + const SaveLoadFormat *fmt = GetSavegameFormat(_sl.sendmapinprogress ? _sendmap_format : _sl.autosaveinprogress ? _autosave_format : _savegame_format, &compression); /* We have written our stuff to memory, now write it to file! */ uint32 hdr[2] = { fmt->tag, TO_BE32(SAVEGAME_VERSION << 16) }; @@ -2603,7 +2616,9 @@ */ SaveOrLoadResult SaveWithFilter(SaveFilter *writer, bool threaded) { + if (_network_server && _sl.saveinprogress && threaded) WaitTillSaved(); try { + _sl.sendmapinprogress = true; _sl.action = SLA_SAVE; return DoSave(writer, threaded); } catch (...) { @@ -2829,7 +2844,7 @@ if (mode == SL_SAVE) { // SAVE game DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename); - if (_network_server || !_settings_client.gui.threaded_saves) threaded = false; + if (!_settings_client.gui.threaded_saves) threaded = false; return DoSave(new FileWriter(fh), threaded); } Index: src/saveload/saveload.h =================================================================== --- src/saveload/saveload.h (revision 27547) +++ src/saveload/saveload.h (working copy) @@ -547,6 +547,8 @@ bool SaveloadCrashWithMissingNewGRFs(); extern char _savegame_format[8]; +extern char _sendmap_format[8]; +extern char _autosave_format[8]; extern bool _do_autosave; #endif /* SAVELOAD_H */ Index: src/table/misc_settings.ini =================================================================== --- src/table/misc_settings.ini (revision 27547) +++ src/table/misc_settings.ini (working copy) @@ -138,6 +138,20 @@ def = NULL cat = SC_EXPERT +[SDTG_STR] +name = ""sendmap_format"" +type = SLE_STRB +var = _sendmap_format +def = NULL +cat = SC_EXPERT + +[SDTG_STR] +name = ""autosave_format"" +type = SLE_STRB +var = _autosave_format +def = NULL +cat = SC_EXPERT + [SDTG_BOOL] name = ""rightclick_emulate"" var = _rightclick_emulate