From 74916a103e41ae32df7979fbc8f1eddcc4c5be70 Mon Sep 17 00:00:00 2001 From: frosch Date: Mon, 23 Dec 2013 18:09:29 +0000 Subject: [PATCH] (svn r26175) -Add: Log in desync output when persistent storage is discarded. --- src/newgrf_airport.cpp | 2 +- src/newgrf_industries.cpp | 2 +- src/newgrf_storage.cpp | 5 +++++ src/newgrf_storage.h | 13 +++++++++---- src/newgrf_town.cpp | 2 +- src/saveload/afterload.cpp | 23 +++++++++++++++++++++++ src/saveload/industry_sl.cpp | 2 +- src/saveload/station_sl.cpp | 2 +- src/saveload/storage_sl.cpp | 2 +- 9 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index c03eb2465e..4c5b21a6bd 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -218,7 +218,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as) /* Create storage on first modification. */ uint32 grfid = (this->ro.grffile != NULL) ? this->ro.grffile->grfid : 0; assert(PersistentStorage::CanAllocateItem()); - this->st->airport.psa = new PersistentStorage(grfid); + this->st->airport.psa = new PersistentStorage(grfid, GSF_AIRPORTS, this->st->airport.tile); } this->st->airport.psa->StoreValue(pos, value); } diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index c9ae6168b7..ffc677d02b 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -399,7 +399,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout const IndustrySpec *indsp = GetIndustrySpec(this->industry->type); uint32 grfid = (indsp->grf_prop.grffile != NULL) ? indsp->grf_prop.grffile->grfid : 0; assert(PersistentStorage::CanAllocateItem()); - this->industry->psa = new PersistentStorage(grfid); + this->industry->psa = new PersistentStorage(grfid, GSF_INDUSTRIES, this->industry->location.tile); } this->industry->psa->StoreValue(pos, value); diff --git a/src/newgrf_storage.cpp b/src/newgrf_storage.cpp index 0c6ea9fcd6..9fd0885c8c 100644 --- a/src/newgrf_storage.cpp +++ b/src/newgrf_storage.cpp @@ -12,6 +12,8 @@ #include "stdafx.h" #include "newgrf_storage.h" #include "core/pool_func.hpp" +#include "core/endian_func.hpp" +#include "debug.h" #include PersistentStoragePool _persistent_storage_pool("PersistentStorage"); @@ -53,6 +55,9 @@ void ClearPersistentStorageChanges(bool keep_changes) { /* Loop over all changes arrays */ for (std::set::iterator it = _changed_storage_arrays->begin(); it != _changed_storage_arrays->end(); it++) { + if (!keep_changes) { + DEBUG(desync, 1, "Discarding persistent storage changes: Feature %d, GrfID %08X, Tile %d", (*it)->feature, BSWAP32((*it)->grfid), (*it)->tile); + } (*it)->ClearChanges(keep_changes); } diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index c4c4addbf4..7dccb053c8 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -13,12 +13,17 @@ #define NEWGRF_STORAGE_H #include "core/pool_type.hpp" +#include "tile_type.h" /** * Base class for all persistent NewGRF storage arrays. Nothing fancy, only here * so we have a generalised access to the virtual methods. */ struct BasePersistentStorageArray { + uint32 grfid; ///< GRFID associated to this persistent storage. A value of zero means "default". + byte feature; ///< NOSAVE: Used to identify in the owner of the array in debug output. + TileIndex tile; ///< NOSAVE: Used to identify in the owner of the array in debug output. + virtual ~BasePersistentStorageArray(); /** @@ -198,14 +203,14 @@ extern PersistentStoragePool _persistent_storage_pool; /** * Class for pooled persistent storage of data. - * On #ClearChanges that data is always zero-ed. */ struct PersistentStorage : PersistentStorageArray, PersistentStoragePool::PoolItem<&_persistent_storage_pool> { - uint32 grfid; ///< GRFID associated to this persistent storage. A value of zero means "default". - /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ - PersistentStorage(const uint32 new_grfid) : grfid(new_grfid) + PersistentStorage(const uint32 new_grfid, byte feature, TileIndex tile) { + this->grfid = new_grfid; + this->feature = feature; + this->tile = tile; } }; diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp index b6693d9aed..c807e77a84 100644 --- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -155,7 +155,7 @@ TownScopeResolver::TownScopeResolver(ResolverObject &ro, Town *t, bool readonly) /* Create a new storage. */ assert(PersistentStorage::CanAllocateItem()); - PersistentStorage *psa = new PersistentStorage(grfid); + PersistentStorage *psa = new PersistentStorage(grfid, GSF_FAKE_TOWNS, this->t->xy); psa->StoreValue(pos, value); t->psa_list.push_back(psa); } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 82c13e3f66..ab34a0c076 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -254,6 +254,29 @@ static void InitializeWindowsAndCaches() Object::IncTypeCount(o->type); } + /* Identify owners of persistent storage arrays */ + Industry *i; + FOR_ALL_INDUSTRIES(i) { + if (i->psa != NULL) { + i->psa->feature = GSF_INDUSTRIES; + i->psa->tile = i->location.tile; + } + } + Station *s; + FOR_ALL_STATIONS(s) { + if (s->airport.psa != NULL) { + s->airport.psa->feature = GSF_AIRPORTS; + s->airport.psa->tile = s->airport.tile; + } + } + Town *t; + FOR_ALL_TOWNS(t) { + for (std::list::iterator it = t->psa_list.begin(); it != t->psa_list.end(); ++it) { + (*it)->feature = GSF_FAKE_TOWNS; + (*it)->tile = t->xy; + } + } + RecomputePrices(); GroupStatistics::UpdateAfterLoad(); diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp index 8943a5d529..469548f231 100644 --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -98,7 +98,7 @@ static void Load_INDY() if (IsSavegameVersionBefore(161) && !IsSavegameVersionBefore(76)) { /* Store the old persistent storage. The GRFID will be added later. */ assert(PersistentStorage::CanAllocateItem()); - i->psa = new PersistentStorage(0); + i->psa = new PersistentStorage(0, 0, 0); memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(i->psa->storage)); } Industry::IncIndustryTypeCount(i->type); diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 7da2d3badc..71e3b31ec7 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -527,7 +527,7 @@ static void Load_STNN() if (IsSavegameVersionBefore(161) && !IsSavegameVersionBefore(145) && st->facilities & FACIL_AIRPORT) { /* Store the old persistent storage. The GRFID will be added later. */ assert(PersistentStorage::CanAllocateItem()); - st->airport.psa = new PersistentStorage(0); + st->airport.psa = new PersistentStorage(0, 0, 0); memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(st->airport.psa->storage)); } diff --git a/src/saveload/storage_sl.cpp b/src/saveload/storage_sl.cpp index 1fa8d2404a..9fb1c86721 100644 --- a/src/saveload/storage_sl.cpp +++ b/src/saveload/storage_sl.cpp @@ -27,7 +27,7 @@ static void Load_PSAC() while ((index = SlIterateArray()) != -1) { assert(PersistentStorage::CanAllocateItem()); - PersistentStorage *ps = new (index) PersistentStorage(0); + PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0); SlObject(ps, _storage_desc); } }