diff options
author | dP <dp@dpointer.org> | 2020-05-18 17:32:05 +0300 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2020-06-28 18:23:59 +0200 |
commit | 7045186594d947b53312a0e72c901f3889757437 (patch) | |
tree | 301e8b29cb7e8c179352a642db29739d938b7085 /src/saveload | |
parent | 380fd8cab41bce0954bcd38eba5befe7057c8fa2 (diff) | |
download | openttd-7045186594d947b53312a0e72c901f3889757437.tar.xz |
Change #8159: Remove now unused town cargo caches without bumping the savegame version
Diffstat (limited to 'src/saveload')
-rw-r--r-- | src/saveload/afterload.cpp | 12 | ||||
-rw-r--r-- | src/saveload/town_sl.cpp | 32 |
2 files changed, 15 insertions, 29 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index cc2a671a2..163ded73c 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2830,18 +2830,6 @@ bool AfterLoadGame() * which is done by StartupEngines(). */ if (gcf_res != GLC_ALL_GOOD) StartupEngines(); - if (IsSavegameVersionBefore(SLV_166)) { - /* Update cargo acceptance map of towns. */ - for (TileIndex t = 0; t < map_size; t++) { - if (!IsTileType(t, MP_HOUSE)) continue; - Town::Get(GetTownIndex(t))->cargo_accepted.Add(t); - } - - for (Town *town : Town::Iterate()) { - UpdateTownCargoes(town); - } - } - /* The road owner of standard road stops was not properly accounted for. */ if (IsSavegameVersionBefore(SLV_172)) { for (TileIndex t = 0; t < map_size; t++) { diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index cbf7205d0..78765dbda 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -13,12 +13,16 @@ #include "../landscape.h" #include "../subsidy_func.h" #include "../strings_func.h" +#include "../tilematrix_type.hpp" #include "saveload.h" #include "newgrf_sl.h" #include "../safeguards.h" +/* TODO: Remove acceptance matrix from the savegame completely. */ +typedef TileMatrix<CargoTypes, 4> AcceptanceMatrix; + /** * Rebuild all the cached variables of towns. */ @@ -48,9 +52,7 @@ void RebuildTownCaches() /* Update the population and num_house dependent values */ for (Town *town : Town::Iterate()) { UpdateTownRadius(town); - UpdateTownCargoes(town); } - UpdateTownCargoBitmap(); } /** @@ -190,8 +192,8 @@ static const SaveLoad _town_desc[] = { SLE_CONDLST(Town, psa_list, REF_STORAGE, SLV_161, SL_MAX_VERSION), - SLE_CONDVAR(Town, cargo_produced, SLE_FILE_U32 | SLE_VAR_U64, SLV_166, SLV_EXTEND_CARGOTYPES), - SLE_CONDVAR(Town, cargo_produced, SLE_UINT64, SLV_EXTEND_CARGOTYPES, 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), @@ -253,11 +255,9 @@ static void RealSave_Town(Town *t) if (IsSavegameVersionBefore(SLV_166)) return; - SlObject(&t->cargo_accepted, GetTileMatrixDesc()); - if (t->cargo_accepted.area.w != 0) { - uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - } + /* Write an empty matrix to avoid bumping savegame version. */ + AcceptanceMatrix dummy; + SlObject(&dummy, GetTileMatrixDesc()); } static void Save_TOWN() @@ -290,14 +290,12 @@ static void Load_TOWN() if (IsSavegameVersionBefore(SLV_166)) continue; - SlObject(&t->cargo_accepted, GetTileMatrixDesc()); - if (t->cargo_accepted.area.w != 0) { - uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - t->cargo_accepted.data = MallocT<CargoTypes>(arr_len); - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - - /* Rebuild total cargo acceptance. */ - UpdateTownCargoTotal(t); + /* 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(); } } } |