mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
(svn r6982) Use the pool macros for the Sign pool
This commit is contained in:
parent
18e56bea7f
commit
470a054c06
@ -1245,7 +1245,7 @@ static const OldChunks sign_chunk[] = {
|
|||||||
|
|
||||||
static bool LoadOldSign(LoadgameState *ls, int num)
|
static bool LoadOldSign(LoadgameState *ls, int num)
|
||||||
{
|
{
|
||||||
if (!AddBlockIfNeeded(&_sign_pool, num))
|
if (!AddBlockIfNeeded(&_Sign_pool, num))
|
||||||
error("Signs: failed loading savegame: too many signs");
|
error("Signs: failed loading savegame: too many signs");
|
||||||
|
|
||||||
return LoadChunk(ls, GetSign(num), sign_chunk);
|
return LoadChunk(ls, GetSign(num), sign_chunk);
|
||||||
|
@ -258,7 +258,7 @@ static void UnInitializeDynamicVariables(void)
|
|||||||
CleanPool(&_Industry_pool);
|
CleanPool(&_Industry_pool);
|
||||||
CleanPool(&_station_pool);
|
CleanPool(&_station_pool);
|
||||||
CleanPool(&_Vehicle_pool);
|
CleanPool(&_Vehicle_pool);
|
||||||
CleanPool(&_sign_pool);
|
CleanPool(&_Sign_pool);
|
||||||
CleanPool(&_Order_pool);
|
CleanPool(&_Order_pool);
|
||||||
|
|
||||||
free((void*)_town_sort);
|
free((void*)_town_sort);
|
||||||
|
20
signs.c
20
signs.c
@ -12,12 +12,6 @@
|
|||||||
|
|
||||||
static Sign *_new_sign;
|
static Sign *_new_sign;
|
||||||
|
|
||||||
enum {
|
|
||||||
/* Max signs: 64000 (4 * 16000) */
|
|
||||||
SIGN_POOL_BLOCK_SIZE_BITS = 2, /* In bits, so (1 << 2) == 4 */
|
|
||||||
SIGN_POOL_MAX_BLOCKS = 16000,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called if a new block is added to the sign-pool
|
* Called if a new block is added to the sign-pool
|
||||||
*/
|
*/
|
||||||
@ -27,11 +21,11 @@ static void SignPoolNewBlock(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 (si = GetSign(start_item); si != NULL; si = (si->index + 1 < GetSignPoolSize()) ? GetSign(si->index + 1) : NULL) si->index = start_item++;
|
for (si = GetSign(start_item); si != NULL; si = (si->index + 1U < GetSignPoolSize()) ? GetSign(si->index + 1U) : NULL) si->index = start_item++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the sign-pool */
|
/* Initialize the sign-pool */
|
||||||
MemoryPool _sign_pool = { "Signs", SIGN_POOL_MAX_BLOCKS, SIGN_POOL_BLOCK_SIZE_BITS, sizeof(Sign), &SignPoolNewBlock, NULL, 0, 0, NULL };
|
DEFINE_POOL(Sign, Sign, SignPoolNewBlock, NULL)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -85,7 +79,7 @@ static Sign *AllocateSign(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 (si = GetSign(0); si != NULL; si = (si->index + 1 < GetSignPoolSize()) ? GetSign(si->index + 1) : NULL) {
|
for (si = GetSign(0); si != NULL; si = (si->index + 1U < GetSignPoolSize()) ? GetSign(si->index + 1U) : NULL) {
|
||||||
if (!IsValidSign(si)) {
|
if (!IsValidSign(si)) {
|
||||||
uint index = si->index;
|
uint index = si->index;
|
||||||
|
|
||||||
@ -97,7 +91,7 @@ static Sign *AllocateSign(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we can add a block to the pool */
|
/* Check if we can add a block to the pool */
|
||||||
if (AddBlockToPool(&_sign_pool))
|
if (AddBlockToPool(&_Sign_pool))
|
||||||
return AllocateSign();
|
return AllocateSign();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -227,8 +221,8 @@ void PlaceProc_Sign(TileIndex tile)
|
|||||||
*/
|
*/
|
||||||
void InitializeSigns(void)
|
void InitializeSigns(void)
|
||||||
{
|
{
|
||||||
CleanPool(&_sign_pool);
|
CleanPool(&_Sign_pool);
|
||||||
AddBlockToPool(&_sign_pool);
|
AddBlockToPool(&_Sign_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const SaveLoad _sign_desc[] = {
|
static const SaveLoad _sign_desc[] = {
|
||||||
@ -268,7 +262,7 @@ static void Load_SIGN(void)
|
|||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
Sign *si;
|
Sign *si;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_sign_pool, index))
|
if (!AddBlockIfNeeded(&_Sign_pool, index))
|
||||||
error("Signs: failed loading savegame: too many signs");
|
error("Signs: failed loading savegame: too many signs");
|
||||||
|
|
||||||
si = GetSign(index);
|
si = GetSign(index);
|
||||||
|
20
signs.h
20
signs.h
@ -16,23 +16,7 @@ typedef struct Sign {
|
|||||||
SignID index;
|
SignID index;
|
||||||
} Sign;
|
} Sign;
|
||||||
|
|
||||||
extern MemoryPool _sign_pool;
|
DECLARE_POOL(Sign, Sign, 2, 16000)
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pointer to the sign with index 'index'
|
|
||||||
*/
|
|
||||||
static inline Sign *GetSign(SignID index)
|
|
||||||
{
|
|
||||||
return (Sign *)GetItemFromPool(&_sign_pool, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current size of the SignPool
|
|
||||||
*/
|
|
||||||
static inline uint16 GetSignPoolSize(void)
|
|
||||||
{
|
|
||||||
return _sign_pool.total_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline SignID GetSignArraySize(void)
|
static inline SignID GetSignArraySize(void)
|
||||||
{
|
{
|
||||||
@ -65,7 +49,7 @@ static inline void DeleteSign(Sign *si)
|
|||||||
si->str = STR_NULL;
|
si->str = STR_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1 < GetSignPoolSize()) ? GetSign(ss->index + 1) : NULL) if (IsValidSign(ss))
|
#define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1U < GetSignPoolSize()) ? GetSign(ss->index + 1U) : NULL) if (IsValidSign(ss))
|
||||||
#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
|
#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
|
||||||
|
|
||||||
VARDEF bool _sign_sort_dirty;
|
VARDEF bool _sign_sort_dirty;
|
||||||
|
Loading…
Reference in New Issue
Block a user