Changeset - r7401:68e7df538ea0
[Not reviewed]
master
0 8 0
rubidium - 17 years ago 2007-08-03 20:18:38
rubidium@openttd.org
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
8 files changed with 30 insertions and 48 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1940,14 +1940,14 @@ void IndustryMonthlyLoop()
 
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
 
}
 

	
 

	
 
void InitializeIndustries()
 
{
 
	CleanPool(&_Industry_pool);
 
	AddBlockToPool(&_Industry_pool);
 
	_Industry_pool.CleanPool();
 
	_Industry_pool.AddBlockToPool();
 

	
 
	ResetIndustryCounts();
 
	_industry_sort_dirty = true;
 
	_industry_sound_tile = 0;
 
}
 

	
src/newgrf_sound.cpp
Show inline comments
 
@@ -17,22 +17,22 @@ STATIC_OLD_POOL(SoundInternal, FileEntry
 

	
 

	
 
/* Allocate a new FileEntry */
 
FileEntry *AllocateFileEntry()
 
{
 
	if (_sound_count == GetSoundInternalPoolSize()) {
 
		if (!AddBlockToPool(&_SoundInternal_pool)) return NULL;
 
		if (!_SoundInternal_pool.AddBlockToPool()) return NULL;
 
	}
 

	
 
	return GetSoundInternal(_sound_count++);
 
}
 

	
 

	
 
void InitializeSoundPool()
 
{
 
	CleanPool(&_SoundInternal_pool);
 
	_SoundInternal_pool.CleanPool();
 
	_sound_count = 0;
 

	
 
	/* Copy original sound data to the pool */
 
	SndCopyToPool();
 
}
 

	
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -59,22 +59,22 @@ static void SpriteGroupPoolCleanBlock(ui
 

	
 
/* Allocate a new SpriteGroup */
 
SpriteGroup *AllocateSpriteGroup()
 
{
 
	/* This is totally different to the other pool allocators, as we never remove an item from the pool. */
 
	if (_spritegroup_count == GetSpriteGroupPoolSize()) {
 
		if (!AddBlockToPool(&_SpriteGroup_pool)) return NULL;
 
		if (!_SpriteGroup_pool.AddBlockToPool()) return NULL;
 
	}
 

	
 
	return GetSpriteGroup(_spritegroup_count++);
 
}
 

	
 

	
 
void InitializeSpriteGroupPool()
 
{
 
	CleanPool(&_SpriteGroup_pool);
 
	_SpriteGroup_pool.CleanPool();
 

	
 
	_spritegroup_count = 0;
 
}
 

	
 
uint32 _temp_store[0x110];
 

	
src/oldpool.h
Show inline comments
 
@@ -104,30 +104,12 @@ struct OldMemoryPool : public OldMemoryP
 
		return (T*)(this->blocks[index >> this->block_size_bits] +
 
				(index & ((1 << this->block_size_bits) - 1)) * this->item_size);
 
	}
 
};
 

	
 
/**
 
 * Those are the wrappers:
 
 *   CleanPool cleans the pool up, but you can use AddBlockToPool directly again
 
 *     (no need to call CreatePool!)
 
 *   AddBlockToPool adds 1 more block to the pool. Returns false if there is no
 
 *     more room
 
 */
 
static inline void CleanPool(OldMemoryPoolBase *array) { array->CleanPool(); }
 
static inline bool AddBlockToPool(OldMemoryPoolBase *array) { return array->AddBlockToPool(); }
 

	
 
/**
 
 * Adds blocks to the pool if needed (and possible) till index fits inside the pool
 
 *
 
 * @return Returns false if adding failed
 
 */
 
static inline bool AddBlockIfNeeded(OldMemoryPoolBase *array, uint index) { return array->AddBlockIfNeeded(index); }
 

	
 

	
 
/**
 
 * Generic function to initialize a new block in a pool.
 
 * @param start_item the first item that needs to be initialized
 
 */
 
template <typename T, OldMemoryPool<T> *Tpool>
 
static void PoolNewBlock(uint start_item)
 
{
src/openttd.cpp
Show inline comments
 
@@ -299,20 +299,20 @@ static void UnInitializeGame()
 
	UnInitWindowSystem();
 

	
 
	/* Uninitialize airport state machines */
 
	UnInitializeAirports();
 

	
 
	/* Uninitialize variables that are allocated dynamically */
 
	CleanPool(&_Town_pool);
 
	CleanPool(&_Industry_pool);
 
	CleanPool(&_Station_pool);
 
	CleanPool(&_Vehicle_pool);
 
	CleanPool(&_Sign_pool);
 
	CleanPool(&_Order_pool);
 
	CleanPool(&_Group_pool);
 
	CleanPool(&_CargoPacket_pool);
 
	_Town_pool.CleanPool();
 
	_Industry_pool.CleanPool();
 
	_Station_pool.CleanPool();
 
	_Vehicle_pool.CleanPool();
 
	_Sign_pool.CleanPool();
 
	_Order_pool.CleanPool();
 
	_Group_pool.CleanPool();
 
	_CargoPacket_pool.CleanPool();
 

	
 
	free((void*)_town_sort);
 
	free((void*)_industry_sort);
 

	
 
	free(_config_file);
 
}
src/order_cmd.cpp
Show inline comments
 
@@ -1266,14 +1266,14 @@ bool CheckForValidOrders(const Vehicle* 
 

	
 
	return false;
 
}
 

	
 
void InitializeOrders()
 
{
 
	CleanPool(&_Order_pool);
 
	AddBlockToPool(&_Order_pool);
 
	_Order_pool.CleanPool();
 
	_Order_pool.AddBlockToPool();
 

	
 
	_backup_orders_tile = 0;
 
}
 

	
 
static const SaveLoad _order_desc[] = {
 
	SLE_VAR(Order, type,  SLE_UINT8),
src/saveload.cpp
Show inline comments
 
@@ -1119,31 +1119,31 @@ STATIC_OLD_POOL(Savegame, byte, 17, 500,
 
static ThreadedSave _ts;
 

	
 
static bool InitMem()
 
{
 
	_ts.count = 0;
 

	
 
	CleanPool(&_Savegame_pool);
 
	AddBlockToPool(&_Savegame_pool);
 
	_Savegame_pool.CleanPool();
 
	_Savegame_pool.AddBlockToPool();
 

	
 
	/* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */
 
	_sl.bufsize = GetSavegamePoolSize();
 
	_sl.buf = GetSavegame(_ts.count);
 
	return true;
 
}
 

	
 
static void UnInitMem()
 
{
 
	CleanPool(&_Savegame_pool);
 
	_Savegame_pool.CleanPool();
 
}
 

	
 
static void WriteMem(uint size)
 
{
 
	_ts.count += size;
 
	/* Allocate new block and new buffer-pointer */
 
	AddBlockIfNeeded(&_Savegame_pool, _ts.count);
 
	_Savegame_pool.AddBlockIfNeeded(_ts.count);
 
	_sl.buf = GetSavegame(_ts.count);
 
}
 

	
 
/********************************************
 
 ********** START OF ZLIB CODE **************
 
 ********************************************/
 
@@ -1340,56 +1340,56 @@ static void *IntToReference(uint index, 
 
		return NULL;
 

	
 
	index--; // correct for the NULL index
 

	
 
	switch (rt) {
 
		case REF_ORDER: {
 
			if (!AddBlockIfNeeded(&_Order_pool, index))
 
			if (!_Order_pool.AddBlockIfNeeded(index))
 
				error("Orders: failed loading savegame: too many orders");
 
			return GetOrder(index);
 
		}
 
		case REF_VEHICLE: {
 
			if (!AddBlockIfNeeded(&_Vehicle_pool, index))
 
			if (!_Vehicle_pool.AddBlockIfNeeded(index))
 
				error("Vehicles: failed loading savegame: too many vehicles");
 
			return GetVehicle(index);
 
		}
 
		case REF_STATION: {
 
			if (!AddBlockIfNeeded(&_Station_pool, index))
 
			if (!_Station_pool.AddBlockIfNeeded(index))
 
				error("Stations: failed loading savegame: too many stations");
 
			return GetStation(index);
 
		}
 
		case REF_TOWN: {
 
			if (!AddBlockIfNeeded(&_Town_pool, index))
 
			if (!_Town_pool.AddBlockIfNeeded(index))
 
				error("Towns: failed loading savegame: too many towns");
 
			return GetTown(index);
 
		}
 
		case REF_ROADSTOPS: {
 
			if (!AddBlockIfNeeded(&_RoadStop_pool, index))
 
			if (!_RoadStop_pool.AddBlockIfNeeded(index))
 
				error("RoadStops: failed loading savegame: too many RoadStops");
 
			return GetRoadStop(index);
 
		}
 
		case REF_ENGINE_RENEWS: {
 
			if (!AddBlockIfNeeded(&_EngineRenew_pool, index))
 
			if (!_EngineRenew_pool.AddBlockIfNeeded(index))
 
				error("EngineRenews: failed loading savegame: too many EngineRenews");
 
			return GetEngineRenew(index);
 
		}
 
		case REF_CARGO_PACKET: {
 
			if (!AddBlockIfNeeded(&_CargoPacket_pool, index))
 
			if (!_CargoPacket_pool.AddBlockIfNeeded(index))
 
				error("CargoPackets: failed loading savegame: too many Cargo packets");
 
			return GetCargoPacket(index);
 
		}
 

	
 
		case REF_VEHICLE_OLD: {
 
			/* Old vehicles were saved differently:
 
			 * invalid vehicle was 0xFFFF,
 
			 * and the index was not - 1.. correct for this */
 
			index++;
 
			if (index == INVALID_VEHICLE)
 
				return NULL;
 

	
 
			if (!AddBlockIfNeeded(&_Vehicle_pool, index))
 
			if (!_Vehicle_pool.AddBlockIfNeeded(index))
 
				error("Vehicles: failed loading savegame: too many vehicles");
 
			return GetVehicle(index);
 
		}
 
		default: NOT_REACHED();
 
	}
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -2289,14 +2289,14 @@ void TownsMonthlyLoop()
 

	
 
void InitializeTowns()
 
{
 
	Subsidy *s;
 

	
 
	/* Clean the town pool and create 1 block in it */
 
	CleanPool(&_Town_pool);
 
	AddBlockToPool(&_Town_pool);
 
	_Town_pool.CleanPool();
 
	_Town_pool.AddBlockToPool();
 

	
 
	memset(_subsidies, 0, sizeof(_subsidies));
 
	for (s=_subsidies; s != endof(_subsidies); s++)
 
		s->cargo_type = CT_INVALID;
 

	
 
	_cur_town_ctr = 0;
0 comments (0 inline, 0 general)