From 452e1e332848cd0aa297a1d1eee0f23167313554 Mon Sep 17 00:00:00 2001 From: dP Date: Thu, 2 Jul 2020 15:24:59 +0300 Subject: [PATCH] Codechange #8258: Remove unused town cargo caches from the savegame --- src/saveload/saveload.h | 1 + src/saveload/town_sl.cpp | 29 ++++++++++------------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 26462cdaa4cae..abd58ea04e190 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -302,6 +302,7 @@ enum SaveLoadVersion : uint16 { SLV_MULTITILE_DOCKS, ///< 216 PR#7380 Multiple docks per station. SLV_TRADING_AGE, ///< 217 PR#7780 Configurable company trading age. SLV_ENDING_YEAR, ///< 218 PR#7747 v1.10 Configurable ending year. + SLV_REMOVE_TOWN_CARGO_CACHE, ///< 219 PR#8258 Remove town cargo acceptance and production caches. SL_MAX_VERSION, ///< Highest possible saveload version }; diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 78765dbdafb03..4e9e0afebb03c 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -20,7 +20,6 @@ #include "../safeguards.h" -/* TODO: Remove acceptance matrix from the savegame completely. */ typedef TileMatrix AcceptanceMatrix; /** @@ -193,10 +192,8 @@ static const SaveLoad _town_desc[] = { SLE_CONDLST(Town, psa_list, REF_STORAGE, SLV_161, SL_MAX_VERSION), SLE_CONDNULL(4, SLV_166, SLV_EXTEND_CARGOTYPES), ///< cargo_produced, no longer in use - SLE_CONDNULL(8, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), ///< cargo_produced, no longer in use - - /* reserve extra space in savegame here. (currently 30 bytes) */ - SLE_CONDNULL(30, SLV_2, SL_MAX_VERSION), + SLE_CONDNULL(8, SLV_EXTEND_CARGOTYPES, SLV_REMOVE_TOWN_CARGO_CACHE), ///< cargo_produced, no longer in use + SLE_CONDNULL(30, SLV_2, SLV_REMOVE_TOWN_CARGO_CACHE), ///< old reserved space SLE_END() }; @@ -252,12 +249,6 @@ static void RealSave_Town(Town *t) for (int i = TE_BEGIN; i < NUM_TE; i++) { SlObject(&t->received[i], _town_received_desc); } - - if (IsSavegameVersionBefore(SLV_166)) return; - - /* Write an empty matrix to avoid bumping savegame version. */ - AcceptanceMatrix dummy; - SlObject(&dummy, GetTileMatrixDesc()); } static void Save_TOWN() @@ -288,14 +279,14 @@ static void Load_TOWN() SlErrorCorrupt("Invalid town name generator"); } - if (IsSavegameVersionBefore(SLV_166)) continue; - - /* Discard acceptance matrix to avoid bumping savegame version. */ - AcceptanceMatrix dummy; - SlObject(&dummy, GetTileMatrixDesc()); - if (dummy.area.w != 0) { - uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID; - for (arr_len *= 4; arr_len != 0; arr_len--) SlReadByte(); + if (!IsSavegameVersionBefore(SLV_166) && IsSavegameVersionBefore(SLV_REMOVE_TOWN_CARGO_CACHE)) { + /* Discard now unused acceptance matrix. */ + AcceptanceMatrix dummy; + SlObject(&dummy, GetTileMatrixDesc()); + if (dummy.area.w != 0) { + uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID; + SlSkipBytes(4 * arr_len); + } } } }