Loading

Paste #p3ha7rdl1

  1. Index: src/saveload/saveload.cpp
  2. ===================================================================
  3. --- src/saveload/saveload.cpp   (revision 27547)
  4. +++ src/saveload/saveload.cpp   (working copy)
  5. @@ -271,6 +271,8 @@
  6.  uint16 _sl_version;       ///< the major savegame version identifier
  7.  byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
  8.  char _savegame_format[8]; ///< how to compress savegames
  9. +char _sendmap_format[8];  ///< how to compress the map to send to a client joining servers
  10. +char _autosave_format[8]; ///< how to compress autosaves
  11.  bool _do_autosave;        ///< are we doing an autosave at the moment?
  12.  
  13.  /** What are we currently doing? */
  14. @@ -409,6 +411,8 @@
  15.  
  16.     byte ff_state;                       ///< The state of fast-forward when saving started.
  17.     bool saveinprogress;                 ///< Whether there is currently a save in progress.
  18. +   bool sendmapinprogress;              ///< Whether there is currently an encoding of a map in progress while being sent to a client joining the server.
  19. +   bool autosaveinprogress;             ///< Whether there is currently an autosave in progress.
  20.  };
  21.  
  22.  static SaveLoadParams _sl; ///< Parameters used for/at saveload.
  23. @@ -2007,7 +2011,7 @@
  24.         if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlErrorCorrupt("Bad checksum");
  25.  
  26.         /* Decompress */
  27. -       lzo1x_decompress_safe(out + sizeof(uint32) * 1, size, buf, &len, NULL);
  28. +       lzo1x_decompress(out + sizeof(uint32) * 1, size, buf, &len, NULL);
  29.         return len;
  30.     }
  31.  };
  32. @@ -2338,9 +2342,11 @@
  33.     LoadFilter *(*init_load)(LoadFilter *chain);                    ///< Constructor for the load filter.
  34.     SaveFilter *(*init_write)(SaveFilter *chain, byte compression); ///< Constructor for the save filter.
  35.  
  36. -   byte min_compression;                 ///< the minimum compression level of this format
  37. -   byte default_compression;             ///< the default compression level of this format
  38. -   byte max_compression;                 ///< the maximum compression level of this format
  39. +   byte min_compression;                 ///< the minimum compression level accepted by this format
  40. +   byte fast_compression;                ///< the default fast compression level of this format to be used by openttd
  41. +   byte default_compression;             ///< the default compression level of this format to be used by openttd
  42. +   byte slow_compression;                ///< the default slow compression level of this format to be used by openttd
  43. +   byte max_compression;                 ///< the maximum compression level accepted by this format
  44.  };
  45.  
  46.  /** The different saveload formats known/understood by OpenTTD. */
  47. @@ -2347,19 +2353,19 @@
  48.  static const SaveLoadFormat _saveload_formats[] = {
  49.  #if defined(WITH_LZO)
  50.     /* Roughly 75% larger than zlib level 6 at only ~7% of the CPU usage. */
  51. -   {"lzo",    TO_BE32X('OTTD'), CreateLoadFilter<LZOLoadFilter>,    CreateSaveFilter<LZOSaveFilter>,    0, 0, 0},
  52. +   {"lzo",    TO_BE32X('OTTD'), CreateLoadFilter<LZOLoadFilter>,    CreateSaveFilter<LZOSaveFilter>,    0, 0, 0, 0, 0},
  53.  #else
  54. -   {"lzo",    TO_BE32X('OTTD'), NULL,                               NULL,                               0, 0, 0},
  55. +   {"lzo",    TO_BE32X('OTTD'), NULL,                               NULL,                               0, 0, 0, 0, 0},
  56.  #endif
  57.     /* Roughly 5 times larger at only 1% of the CPU usage over zlib level 6. */
  58. -   {"none",   TO_BE32X('OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
  59. +   {"none",   TO_BE32X('OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0, 0, 0},
  60.  #if defined(WITH_ZLIB)
  61.     /* After level 6 the speed reduction is significant (1.5x to 2.5x slower per level), but the reduction in filesize is
  62.      * fairly insignificant (~1% for each step). Lower levels become ~5-10% bigger by each level than level 6 while level
  63.      * 1 is "only" 3 times as fast. Level 0 results in uncompressed savegames at about 8 times the cost of "none". */
  64. -   {"zlib",   TO_BE32X('OTTZ'), CreateLoadFilter<ZlibLoadFilter>,   CreateSaveFilter<ZlibSaveFilter>,   0, 6, 9},
  65. +   {"zlib",   TO_BE32X('OTTZ'), CreateLoadFilter<ZlibLoadFilter>,   CreateSaveFilter<ZlibSaveFilter>,   0, 1, 6, 9, 9},
  66.  #else
  67. -   {"zlib",   TO_BE32X('OTTZ'), NULL,                               NULL,                               0, 0, 0},
  68. +   {"zlib",   TO_BE32X('OTTZ'), NULL,                               NULL,                               0, 0, 0, 0, 0},
  69.  #endif
  70.  #if defined(WITH_LZMA)
  71.     /* Level 2 compression is speed wise as fast as zlib level 6 compression (old default), but results in ~10% smaller saves.
  72. @@ -2367,9 +2373,9 @@
  73.      * The next significant reduction in file size is at level 4, but that is already 4 times slower. Level 3 is primarily 50%
  74.      * slower while not improving the filesize, while level 0 and 1 are faster, but don't reduce savegame size much.
  75.      * It's OTTX and not e.g. OTTL because liblzma is part of xz-utils and .tar.xz is preferred over .tar.lzma. */
  76. -   {"lzma",   TO_BE32X('OTTX'), CreateLoadFilter<LZMALoadFilter>,   CreateSaveFilter<LZMASaveFilter>,   0, 2, 9},
  77. +   {"lzma",   TO_BE32X('OTTX'), CreateLoadFilter<LZMALoadFilter>,   CreateSaveFilter<LZMASaveFilter>,   0, 0, 2, 6, 9},
  78.  #else
  79. -   {"lzma",   TO_BE32X('OTTX'), NULL,                               NULL,                               0, 0, 0},
  80. +   {"lzma",   TO_BE32X('OTTX'), NULL,                               NULL,                               0, 0, 0, 0, 0},
  81.  #endif
  82.  };
  83.  
  84. @@ -2395,6 +2401,8 @@
  85.         for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) {
  86.             if (slf->init_write != NULL && strcmp(s, slf->name) == 0) {
  87.                 *compression_level = slf->default_compression;
  88. +               if ((_network_server && !_sl.sendmapinprogress) || (_pause_mode = PM_UNPAUSED && _sl.autosaveinprogress && _sl.ff_state != _fast_forward)) *compression_level = slf->fast_compression;
  89. +               if (_sl.sendmapinprogress) *compression_level = slf->slow_compression;
  90.                 if (complevel != NULL) {
  91.                     /* There is a compression level in the string.
  92.                      * First restore the : we removed to do proper name matching,
  93. @@ -2424,6 +2432,8 @@
  94.         if (complevel != NULL) *complevel = ':';
  95.     }
  96.     *compression_level = def->default_compression;
  97. +   if ((_network_server && !_sl.sendmapinprogress) || (_pause_mode = PM_UNPAUSED && _sl.autosaveinprogress && _sl.ff_state != _fast_forward)) *compression_level = def->fast_compression;
  98. +   if (_sl.sendmapinprogress) *compression_level = def->slow_compression;
  99.     return def;
  100.  }
  101.  
  102. @@ -2463,6 +2473,7 @@
  103.  
  104.     InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START);
  105.     _sl.saveinprogress = true;
  106. +   if (_do_autosave) _sl.autosaveinprogress = true;
  107.  }
  108.  
  109.  /** Update the gui accordingly when saving is done and release locks on saveload. */
  110. @@ -2473,6 +2484,8 @@
  111.  
  112.     InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH);
  113.     _sl.saveinprogress = false;
  114. +   _sl.sendmapinprogress = false;
  115. +   _sl.autosaveinprogress = false;
  116.  }
  117.  
  118.  /** Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends) */
  119. @@ -2508,7 +2521,7 @@
  120.  {
  121.     try {
  122.         byte compression;
  123. -       const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format, &compression);
  124. +       const SaveLoadFormat *fmt = GetSavegameFormat(_sl.sendmapinprogress ? _sendmap_format : _sl.autosaveinprogress ? _autosave_format : _savegame_format, &compression);
  125.  
  126.         /* We have written our stuff to memory, now write it to file! */
  127.         uint32 hdr[2] = { fmt->tag, TO_BE32(SAVEGAME_VERSION << 16) };
  128. @@ -2603,7 +2616,9 @@
  129.   */
  130.  SaveOrLoadResult SaveWithFilter(SaveFilter *writer, bool threaded)
  131.  {
  132. +   if (_network_server && _sl.saveinprogress && threaded) WaitTillSaved();
  133.     try {
  134. +       _sl.sendmapinprogress = true;
  135.         _sl.action = SLA_SAVE;
  136.         return DoSave(writer, threaded);
  137.     } catch (...) {
  138. @@ -2829,7 +2844,7 @@
  139.  
  140.         if (mode == SL_SAVE) { // SAVE game
  141.             DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename);
  142. -           if (_network_server || !_settings_client.gui.threaded_saves) threaded = false;
  143. +           if (!_settings_client.gui.threaded_saves) threaded = false;
  144.  
  145.             return DoSave(new FileWriter(fh), threaded);
  146.         }
  147. Index: src/saveload/saveload.h
  148. ===================================================================
  149. --- src/saveload/saveload.h (revision 27547)
  150. +++ src/saveload/saveload.h (working copy)
  151. @@ -547,6 +547,8 @@
  152.  bool SaveloadCrashWithMissingNewGRFs();
  153.  
  154.  extern char _savegame_format[8];
  155. +extern char _sendmap_format[8];
  156. +extern char _autosave_format[8];
  157.  extern bool _do_autosave;
  158.  
  159.  #endif /* SAVELOAD_H */
  160. Index: src/table/misc_settings.ini
  161. ===================================================================
  162. --- src/table/misc_settings.ini (revision 27547)
  163. +++ src/table/misc_settings.ini (working copy)
  164. @@ -138,6 +138,20 @@
  165.  def      = NULL
  166.  cat      = SC_EXPERT
  167.  
  168. +[SDTG_STR]
  169. +name     = ""sendmap_format""
  170. +type     = SLE_STRB
  171. +var      = _sendmap_format
  172. +def      = NULL
  173. +cat      = SC_EXPERT
  174. +
  175. +[SDTG_STR]
  176. +name     = ""autosave_format""
  177. +type     = SLE_STRB
  178. +var      = _autosave_format
  179. +def      = NULL
  180. +cat      = SC_EXPERT
  181. +
  182.  [SDTG_BOOL]
  183.  name     = ""rightclick_emulate""
  184.  var      = _rightclick_emulate

Comments