summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-12-23 18:09:29 +0000
committerfrosch <frosch@openttd.org>2013-12-23 18:09:29 +0000
commit49852e3dac0e59377b440a23c514608e714846f2 (patch)
treeba094a330655085516bd75bd560973ae29cd64b3
parenteca86d1baf5f374d25dcc9bf0ff2bad328bdffab (diff)
downloadopenttd-49852e3dac0e59377b440a23c514608e714846f2.tar.xz
(svn r26175) -Add: Log in desync output when persistent storage is discarded.
-rw-r--r--src/newgrf_airport.cpp2
-rw-r--r--src/newgrf_industries.cpp2
-rw-r--r--src/newgrf_storage.cpp5
-rw-r--r--src/newgrf_storage.h13
-rw-r--r--src/newgrf_town.cpp2
-rw-r--r--src/saveload/afterload.cpp23
-rw-r--r--src/saveload/industry_sl.cpp2
-rw-r--r--src/saveload/station_sl.cpp2
-rw-r--r--src/saveload/storage_sl.cpp2
9 files changed, 43 insertions, 10 deletions
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index c03eb2465..4c5b21a6b 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 c9ae6168b..ffc677d02 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 0c6ea9fcd..9fd0885c8 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 <set>
PersistentStoragePool _persistent_storage_pool("PersistentStorage");
@@ -53,6 +55,9 @@ void ClearPersistentStorageChanges(bool keep_changes)
{
/* Loop over all changes arrays */
for (std::set<BasePersistentStorageArray*>::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 c4c4addbf..7dccb053c 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<int32, 16>, 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 b6693d9ae..c807e77a8 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 82c13e3f6..ab34a0c07 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<PersistentStorage *>::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 8943a5d52..469548f23 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 7da2d3bad..71e3b31ec 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 1fa8d2404..9fb1c8672 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);
}
}