mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r26175) -Add: Log in desync output when persistent storage is discarded.
This commit is contained in:
parent
eca86d1baf
commit
49852e3dac
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue