Changeset - r21091:6d0d361e1c1e
[Not reviewed]
master
0 9 0
frosch - 10 years ago 2013-12-23 18:09:29
frosch@openttd.org
(svn r26175) -Add: Log in desync output when persistent storage is discarded.
9 files changed with 43 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/newgrf_airport.cpp
Show inline comments
 
@@ -218,7 +218,7 @@ void AirportOverrideManager::SetEntitySp
 
		/* 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);
 
}
src/newgrf_industries.cpp
Show inline comments
 
@@ -399,7 +399,7 @@ static uint32 GetCountAndDistanceOfClose
 
		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);
src/newgrf_storage.cpp
Show inline comments
 
@@ -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 
 
{
 
	/* 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);
 
	}
 

	
src/newgrf_storage.h
Show inline comments
 
@@ -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
 

	
 
/**
 
 * 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;
 
	}
 
};
 

	
src/newgrf_town.cpp
Show inline comments
 
@@ -155,7 +155,7 @@ TownScopeResolver::TownScopeResolver(Res
 

	
 
	/* 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);
 
}
src/saveload/afterload.cpp
Show inline comments
 
@@ -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();
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -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);
src/saveload/station_sl.cpp
Show inline comments
 
@@ -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));
 
			}
 

	
src/saveload/storage_sl.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
0 comments (0 inline, 0 general)