mirror of https://github.com/OpenTTD/OpenTTD
(svn r6979) Use the pool macros for the Industry pool
parent
a97f75e439
commit
4cb479e083
20
industry.h
20
industry.h
|
@ -80,7 +80,7 @@ typedef struct IndustrySpec {
|
||||||
|
|
||||||
const IndustrySpec *GetIndustrySpec(IndustryType thistype);
|
const IndustrySpec *GetIndustrySpec(IndustryType thistype);
|
||||||
|
|
||||||
extern MemoryPool _industry_pool;
|
DECLARE_POOL(Industry, Industry, 3, 8000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an Industry really exists.
|
* Check if an Industry really exists.
|
||||||
|
@ -90,22 +90,6 @@ static inline bool IsValidIndustry(const Industry *industry)
|
||||||
return industry->xy != 0;
|
return industry->xy != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pointer to the industry with index 'index'
|
|
||||||
*/
|
|
||||||
static inline Industry *GetIndustry(uint index)
|
|
||||||
{
|
|
||||||
return (Industry*)GetItemFromPool(&_industry_pool, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current size of the IndustryPool
|
|
||||||
*/
|
|
||||||
static inline uint16 GetIndustryPoolSize(void)
|
|
||||||
{
|
|
||||||
return _industry_pool.total_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
VARDEF int _total_industries;
|
VARDEF int _total_industries;
|
||||||
|
|
||||||
static inline IndustryID GetIndustryArraySize(void)
|
static inline IndustryID GetIndustryArraySize(void)
|
||||||
|
@ -150,7 +134,7 @@ static inline void DeleteIndustry(Industry *i)
|
||||||
i->xy = 0;
|
i->xy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) if (IsValidIndustry(i))
|
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
|
||||||
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
|
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
|
||||||
|
|
||||||
VARDEF const Industry** _industry_sort;
|
VARDEF const Industry** _industry_sort;
|
||||||
|
|
|
@ -32,12 +32,6 @@ void DeleteOilRig(TileIndex tile);
|
||||||
static byte _industry_sound_ctr;
|
static byte _industry_sound_ctr;
|
||||||
static TileIndex _industry_sound_tile;
|
static TileIndex _industry_sound_tile;
|
||||||
|
|
||||||
enum {
|
|
||||||
/* Max industries: 64000 (8 * 8000) */
|
|
||||||
INDUSTRY_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */
|
|
||||||
INDUSTRY_POOL_MAX_BLOCKS = 8000,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called if a new block is added to the industry-pool
|
* Called if a new block is added to the industry-pool
|
||||||
*/
|
*/
|
||||||
|
@ -47,11 +41,10 @@ static void IndustryPoolNewBlock(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 (i = GetIndustry(start_item); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) i->index = start_item++;
|
for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) i->index = start_item++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the industry-pool */
|
DEFINE_POOL(Industry, Industry, IndustryPoolNewBlock, NULL)
|
||||||
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, NULL, 0, 0, NULL };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the type for this industry. Although it is accessed by a tile,
|
* Retrieve the type for this industry. Although it is accessed by a tile,
|
||||||
|
@ -1369,7 +1362,7 @@ static Industry *AllocateIndustry(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 (i = GetIndustry(0); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) {
|
for (i = GetIndustry(0); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) {
|
||||||
IndustryID index = i->index;
|
IndustryID index = i->index;
|
||||||
|
|
||||||
if (IsValidIndustry(i)) continue;
|
if (IsValidIndustry(i)) continue;
|
||||||
|
@ -1383,7 +1376,7 @@ static Industry *AllocateIndustry(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we can add a block to the pool */
|
/* Check if we can add a block to the pool */
|
||||||
return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL;
|
return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner)
|
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner)
|
||||||
|
@ -1848,8 +1841,8 @@ void IndustryMonthlyLoop(void)
|
||||||
|
|
||||||
void InitializeIndustries(void)
|
void InitializeIndustries(void)
|
||||||
{
|
{
|
||||||
CleanPool(&_industry_pool);
|
CleanPool(&_Industry_pool);
|
||||||
AddBlockToPool(&_industry_pool);
|
AddBlockToPool(&_Industry_pool);
|
||||||
|
|
||||||
_total_industries = 0;
|
_total_industries = 0;
|
||||||
_industry_sort_dirty = true;
|
_industry_sort_dirty = true;
|
||||||
|
@ -1924,7 +1917,7 @@ static void Load_INDY(void)
|
||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
Industry *i;
|
Industry *i;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_industry_pool, index))
|
if (!AddBlockIfNeeded(&_Industry_pool, index))
|
||||||
error("Industries: failed loading savegame: too many industries");
|
error("Industries: failed loading savegame: too many industries");
|
||||||
|
|
||||||
i = GetIndustry(index);
|
i = GetIndustry(index);
|
||||||
|
|
|
@ -709,7 +709,7 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
|
||||||
{
|
{
|
||||||
Industry *i;
|
Industry *i;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_industry_pool, num))
|
if (!AddBlockIfNeeded(&_Industry_pool, num))
|
||||||
error("Industries: failed loading savegame: too many industries");
|
error("Industries: failed loading savegame: too many industries");
|
||||||
|
|
||||||
i = GetIndustry(num);
|
i = GetIndustry(num);
|
||||||
|
|
|
@ -255,7 +255,7 @@ static void UnInitializeDynamicVariables(void)
|
||||||
{
|
{
|
||||||
/* Dynamic stuff needs to be free'd somewhere... */
|
/* Dynamic stuff needs to be free'd somewhere... */
|
||||||
CleanPool(&_town_pool);
|
CleanPool(&_town_pool);
|
||||||
CleanPool(&_industry_pool);
|
CleanPool(&_Industry_pool);
|
||||||
CleanPool(&_station_pool);
|
CleanPool(&_station_pool);
|
||||||
CleanPool(&_Vehicle_pool);
|
CleanPool(&_Vehicle_pool);
|
||||||
CleanPool(&_sign_pool);
|
CleanPool(&_sign_pool);
|
||||||
|
|
Loading…
Reference in New Issue