(svn r6976) Use the pool macros for the Depot pool
This commit is contained in:
		
							
								
								
									
										20
									
								
								depot.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								depot.c
									
									
									
									
									
								
							@@ -10,11 +10,6 @@
 | 
				
			|||||||
#include "saveload.h"
 | 
					#include "saveload.h"
 | 
				
			||||||
#include "order.h"
 | 
					#include "order.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum {
 | 
					 | 
				
			||||||
	/* Max depots: 64000 (8 * 8000) */
 | 
					 | 
				
			||||||
	DEPOT_POOL_BLOCK_SIZE_BITS = 3,       /* In bits, so (1 << 3) == 8 */
 | 
					 | 
				
			||||||
	DEPOT_POOL_MAX_BLOCKS      = 8000,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Called if a new block is added to the depot-pool
 | 
					 * Called if a new block is added to the depot-pool
 | 
				
			||||||
@@ -25,11 +20,10 @@ static void DepotPoolNewBlock(uint start_item)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 | 
						/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 | 
				
			||||||
	 * TODO - This is just a temporary stage, this will be removed. */
 | 
						 * TODO - This is just a temporary stage, this will be removed. */
 | 
				
			||||||
	for (d = GetDepot(start_item); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) d->index = start_item++;
 | 
						for (d = GetDepot(start_item); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) d->index = start_item++;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Initialize the town-pool */
 | 
					DEFINE_POOL(Depot, Depot, DepotPoolNewBlock, NULL)
 | 
				
			||||||
MemoryPool _depot_pool = { "Depots", DEPOT_POOL_MAX_BLOCKS, DEPOT_POOL_BLOCK_SIZE_BITS, sizeof(Depot), &DepotPoolNewBlock, NULL, 0, 0, NULL };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -57,7 +51,7 @@ Depot *AllocateDepot(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 | 
						/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
 | 
				
			||||||
	 * TODO - This is just a temporary stage, this will be removed. */
 | 
						 * TODO - This is just a temporary stage, this will be removed. */
 | 
				
			||||||
	for (d = GetDepot(0); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) {
 | 
						for (d = GetDepot(0); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) {
 | 
				
			||||||
		if (!IsValidDepot(d)) {
 | 
							if (!IsValidDepot(d)) {
 | 
				
			||||||
			DepotID index = d->index;
 | 
								DepotID index = d->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -69,7 +63,7 @@ Depot *AllocateDepot(void)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Check if we can add a block to the pool */
 | 
						/* Check if we can add a block to the pool */
 | 
				
			||||||
	if (AddBlockToPool(&_depot_pool)) return AllocateDepot();
 | 
						if (AddBlockToPool(&_Depot_pool)) return AllocateDepot();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -91,8 +85,8 @@ void DestroyDepot(Depot *depot)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void InitializeDepots(void)
 | 
					void InitializeDepots(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	CleanPool(&_depot_pool);
 | 
						CleanPool(&_Depot_pool);
 | 
				
			||||||
	AddBlockToPool(&_depot_pool);
 | 
						AddBlockToPool(&_Depot_pool);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -120,7 +114,7 @@ static void Load_DEPT(void)
 | 
				
			|||||||
	while ((index = SlIterateArray()) != -1) {
 | 
						while ((index = SlIterateArray()) != -1) {
 | 
				
			||||||
		Depot *depot;
 | 
							Depot *depot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!AddBlockIfNeeded(&_depot_pool, index))
 | 
							if (!AddBlockIfNeeded(&_Depot_pool, index))
 | 
				
			||||||
			error("Depots: failed loading savegame: too many depots");
 | 
								error("Depots: failed loading savegame: too many depots");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		depot = GetDepot(index);
 | 
							depot = GetDepot(index);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								depot.h
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								depot.h
									
									
									
									
									
								
							@@ -17,23 +17,7 @@ struct Depot {
 | 
				
			|||||||
	DepotID index;
 | 
						DepotID index;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern MemoryPool _depot_pool;
 | 
					DECLARE_POOL(Depot, Depot, 3, 8000);
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Get the pointer to the depot with index 'index'
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static inline Depot *GetDepot(DepotID index)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	return (Depot*)GetItemFromPool(&_depot_pool, index);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Get the current size of the DepotPool
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static inline uint16 GetDepotPoolSize(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	return _depot_pool.total_items;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Check if a depot really exists.
 | 
					 * Check if a depot really exists.
 | 
				
			||||||
@@ -58,7 +42,7 @@ static inline void DeleteDepot(Depot *depot)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ShowDepotWindow(TileIndex tile, byte type);
 | 
					void ShowDepotWindow(TileIndex tile, byte type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) if (IsValidDepot(d))
 | 
					#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (IsValidDepot(d))
 | 
				
			||||||
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
 | 
					#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MIN_SERVINT_PERCENT  5
 | 
					#define MIN_SERVINT_PERCENT  5
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -521,7 +521,7 @@ static const OldChunks depot_chunk[] = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static bool LoadOldDepot(LoadgameState *ls, int num)
 | 
					static bool LoadOldDepot(LoadgameState *ls, int num)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!AddBlockIfNeeded(&_depot_pool, num))
 | 
						if (!AddBlockIfNeeded(&_Depot_pool, num))
 | 
				
			||||||
		error("Depots: failed loading savegame: too many depots");
 | 
							error("Depots: failed loading savegame: too many depots");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!LoadChunk(ls, GetDepot(num), depot_chunk)) return false;
 | 
						if (!LoadChunk(ls, GetDepot(num), depot_chunk)) return false;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user