From 4b0b4e06435b76e1cb40a8a65ccdc2307d48081d Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Mon, 13 Aug 2018 23:44:49 +0200 Subject: [PATCH] Feature: [NewGRF] Increase size of persistent storage to 256. --- src/newgrf.cpp | 2 ++ src/newgrf_storage.h | 4 ++-- src/saveload/industry_sl.cpp | 2 +- src/saveload/saveload.cpp | 3 ++- src/saveload/station_sl.cpp | 2 +- src/saveload/storage_sl.cpp | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 216bdc1901..16a6c231f0 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -7898,6 +7898,8 @@ static void InitializeGRFSpecial() | ((_settings_game.vehicle.dynamic_engines ? 1 : 0) << 0x18) // dynamic engines | (1 << 0x1E) // variablerunningcosts | (1 << 0x1F); // any switch is on + + _ttdpatch_flags[4] = (1 << 0x00); // larger persistent storage } /** Reset and clear all NewGRF stations */ diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index ae9782d88c..a0c1558f8e 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -220,7 +220,7 @@ extern PersistentStoragePool _persistent_storage_pool; /** * Class for pooled persistent storage of data. */ -struct PersistentStorage : PersistentStorageArray, PersistentStoragePool::PoolItem<&_persistent_storage_pool> { +struct PersistentStorage : PersistentStorageArray, PersistentStoragePool::PoolItem<&_persistent_storage_pool> { /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ PersistentStorage(const uint32 new_grfid, byte feature, TileIndex tile) { @@ -230,7 +230,7 @@ struct PersistentStorage : PersistentStorageArray, PersistentStorageP } }; -assert_compile(cpp_lengthof(OldPersistentStorage, storage) == cpp_lengthof(PersistentStorage, storage)); +assert_compile(cpp_lengthof(OldPersistentStorage, storage) <= cpp_lengthof(PersistentStorage, storage)); #define FOR_ALL_STORAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(PersistentStorage, storage_index, var, start) #define FOR_ALL_STORAGES(var) FOR_ALL_STORAGES_FROM(var, 0) diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp index b28730e3c3..615e8e1522 100644 --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -101,7 +101,7 @@ static void Load_INDY() /* Store the old persistent storage. The GRFID will be added later. */ assert(PersistentStorage::CanAllocateItem()); i->psa = new PersistentStorage(0, 0, 0); - memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(i->psa->storage)); + memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(_old_ind_persistent_storage.storage)); } Industry::IncIndustryTypeCount(i->type); } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index e065237693..f9c3efd758 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -268,8 +268,9 @@ * 198 * 199 * 200 #6805 Extend railtypes to 64, adding uint16 to map array. + * 201 #6885 Extend NewGRF persistant storages. */ -extern const uint16 SAVEGAME_VERSION = 200; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 201; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop. diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index f01123da0a..670d6fcf06 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -538,7 +538,7 @@ static void Load_STNN() /* Store the old persistent storage. The GRFID will be added later. */ assert(PersistentStorage::CanAllocateItem()); st->airport.psa = new PersistentStorage(0, 0, 0); - memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(st->airport.psa->storage)); + memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(_old_st_persistent_storage.storage)); } for (CargoID i = 0; i < num_cargo; i++) { diff --git a/src/saveload/storage_sl.cpp b/src/saveload/storage_sl.cpp index 110df63a7c..04980c7c37 100644 --- a/src/saveload/storage_sl.cpp +++ b/src/saveload/storage_sl.cpp @@ -18,7 +18,8 @@ /** Description of the data to save and load in #PersistentStorage. */ static const SaveLoad _storage_desc[] = { SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, 6, SL_MAX_VERSION), - SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, 161, SL_MAX_VERSION), + SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, 161, 200), + SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 256, 201, SL_MAX_VERSION), SLE_END() };