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
 
@@ -215,13 +215,13 @@ void AirportOverrideManager::SetEntitySp
 
		/* There is no need to create a storage if the value is zero. */
 
		if (value == 0) return;
 

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

	
 
/**
 
 * Constructor of the airport resolver.
src/newgrf_industries.cpp
Show inline comments
 
@@ -396,13 +396,13 @@ static uint32 GetCountAndDistanceOfClose
 
		if (value == 0) return;
 

	
 
		/* Create storage on first modification. */
 
		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
 
@@ -9,12 +9,14 @@
 

	
 
/** @file newgrf_storage.cpp Functionality related to the temporary and persistent storage arrays for NewGRFs. */
 

	
 
#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");
 
INSTANTIATE_POOL_METHODS(PersistentStorage)
 

	
 
/** The changed storage arrays */
 
@@ -50,12 +52,15 @@ void AddChangedPersistentStorage(BasePer
 
 * @param keep_changes do we save or revert the changes since the last #ClearChanges?
 
 */
 
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);
 
	}
 

	
 
	/* And then clear that array */
 
	_changed_storage_arrays->clear();
 
}
src/newgrf_storage.h
Show inline comments
 
@@ -10,18 +10,23 @@
 
/** @file newgrf_storage.h Functionality related to the temporary and persistent storage arrays for NewGRFs. */
 

	
 
#ifndef NEWGRF_STORAGE_H
 
#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();
 

	
 
	/**
 
	 * Clear the changes made since the last #ClearChanges.
 
	 * This can be done in two ways:
 
	 *  - saving the changes permanently
 
@@ -195,20 +200,20 @@ struct PersistentStorage;
 
typedef Pool<PersistentStorage, PersistentStorageID, 1, 0xFF000> PersistentStoragePool;
 

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

	
 
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)
src/newgrf_town.cpp
Show inline comments
 
@@ -152,13 +152,13 @@ TownScopeResolver::TownScopeResolver(Res
 
			return;
 
		}
 
	}
 

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

	
 
/**
 
 * Resolver for a town.
src/saveload/afterload.cpp
Show inline comments
 
@@ -251,12 +251,35 @@ static void InitializeWindowsAndCaches()
 
	/* Count number of objects per type */
 
	Object *o;
 
	FOR_ALL_OBJECTS(o) {
 
		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();
 

	
 
	Station::RecomputeIndustriesNearForAll();
 
	RebuildSubsidisedSourceAndDestinationCache();
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -95,13 +95,13 @@ static void Load_INDY()
 
		SlObject(i, _industry_desc);
 

	
 
		/* Before savegame version 161, persistent storages were not stored in a pool. */
 
		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
 
@@ -524,13 +524,13 @@ static void Load_STNN()
 
			Station *st = Station::From(bst);
 

	
 
			/* Before savegame version 161, persistent storages were not stored in a pool. */
 
			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));
 
			}
 

	
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
 
				SlObject(&st->goods[i], GetGoodsDesc());
 
				FlowSaveLoad flow;
src/saveload/storage_sl.cpp
Show inline comments
 
@@ -24,13 +24,13 @@ static const SaveLoad _storage_desc[] = 
 
static void Load_PSAC()
 
{
 
	int index;
 

	
 
	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);
 
	}
 
}
 

	
 
/** Save persistent storage data. */
 
static void Save_PSAC()
0 comments (0 inline, 0 general)