mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r6986) Use the pool macros for the Town pool
This commit is contained in:
parent
02ae75b380
commit
e397b721cd
|
@ -483,7 +483,7 @@ static const OldChunks town_chunk[] = {
|
||||||
};
|
};
|
||||||
static bool LoadOldTown(LoadgameState *ls, int num)
|
static bool LoadOldTown(LoadgameState *ls, int num)
|
||||||
{
|
{
|
||||||
if (!AddBlockIfNeeded(&_town_pool, num))
|
if (!AddBlockIfNeeded(&_Town_pool, num))
|
||||||
error("Towns: failed loading savegame: too many towns");
|
error("Towns: failed loading savegame: too many towns");
|
||||||
|
|
||||||
return LoadChunk(ls, GetTown(num), town_chunk);
|
return LoadChunk(ls, GetTown(num), town_chunk);
|
||||||
|
|
|
@ -254,7 +254,7 @@ static void InitializeDynamicVariables(void)
|
||||||
static void UnInitializeDynamicVariables(void)
|
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);
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ static void *IntToReference(uint index, SLRefType rt)
|
||||||
return GetStation(index);
|
return GetStation(index);
|
||||||
}
|
}
|
||||||
case REF_TOWN: {
|
case REF_TOWN: {
|
||||||
if (!AddBlockIfNeeded(&_town_pool, index))
|
if (!AddBlockIfNeeded(&_Town_pool, index))
|
||||||
error("Towns: failed loading savegame: too many towns");
|
error("Towns: failed loading savegame: too many towns");
|
||||||
return GetTown(index);
|
return GetTown(index);
|
||||||
}
|
}
|
||||||
|
|
20
town.h
20
town.h
|
@ -152,7 +152,7 @@ bool CheckforTownRating(uint32 flags, Town *t, byte type);
|
||||||
|
|
||||||
VARDEF const Town** _town_sort;
|
VARDEF const Town** _town_sort;
|
||||||
|
|
||||||
extern MemoryPool _town_pool;
|
DECLARE_POOL(Town, Town, 3, 8000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a Town really exists.
|
* Check if a Town really exists.
|
||||||
|
@ -162,22 +162,6 @@ static inline bool IsValidTown(const Town* town)
|
||||||
return town->xy != 0;
|
return town->xy != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pointer to the town with index 'index'
|
|
||||||
*/
|
|
||||||
static inline Town *GetTown(uint index)
|
|
||||||
{
|
|
||||||
return (Town*)GetItemFromPool(&_town_pool, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current size of the TownPool
|
|
||||||
*/
|
|
||||||
static inline uint16 GetTownPoolSize(void)
|
|
||||||
{
|
|
||||||
return _town_pool.total_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
VARDEF uint _total_towns;
|
VARDEF uint _total_towns;
|
||||||
|
|
||||||
static inline TownID GetTownArraySize(void)
|
static inline TownID GetTownArraySize(void)
|
||||||
|
@ -225,7 +209,7 @@ static inline void DeleteTown(Town *t)
|
||||||
t->xy = 0;
|
t->xy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL) if (IsValidTown(t))
|
#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (IsValidTown(t))
|
||||||
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
|
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
|
||||||
|
|
||||||
VARDEF bool _town_sort_dirty;
|
VARDEF bool _town_sort_dirty;
|
||||||
|
|
20
town_cmd.c
20
town_cmd.c
|
@ -30,12 +30,6 @@
|
||||||
#include "table/town_land.h"
|
#include "table/town_land.h"
|
||||||
#include "genworld.h"
|
#include "genworld.h"
|
||||||
|
|
||||||
enum {
|
|
||||||
/* Max towns: 64000 (8 * 8000) */
|
|
||||||
TOWN_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */
|
|
||||||
TOWN_POOL_MAX_BLOCKS = 8000,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called if a new block is added to the town-pool
|
* Called if a new block is added to the town-pool
|
||||||
*/
|
*/
|
||||||
|
@ -45,11 +39,11 @@ static void TownPoolNewBlock(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 (t = GetTown(start_item); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL) t->index = start_item++;
|
for (t = GetTown(start_item); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) t->index = start_item++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the town-pool */
|
/* Initialize the town-pool */
|
||||||
MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, NULL, 0, 0, NULL };
|
DEFINE_POOL(Town, Town, TownPoolNewBlock, NULL)
|
||||||
|
|
||||||
void DestroyTown(Town *t)
|
void DestroyTown(Town *t)
|
||||||
{
|
{
|
||||||
|
@ -985,7 +979,7 @@ static Town *AllocateTown(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 (t = GetTown(0); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL) {
|
for (t = GetTown(0); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) {
|
||||||
if (!IsValidTown(t)) {
|
if (!IsValidTown(t)) {
|
||||||
TownID index = t->index;
|
TownID index = t->index;
|
||||||
|
|
||||||
|
@ -999,7 +993,7 @@ static Town *AllocateTown(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we can add a block to the pool */
|
/* Check if we can add a block to the pool */
|
||||||
if (AddBlockToPool(&_town_pool))
|
if (AddBlockToPool(&_Town_pool))
|
||||||
return AllocateTown();
|
return AllocateTown();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1830,8 +1824,8 @@ void InitializeTowns(void)
|
||||||
Subsidy *s;
|
Subsidy *s;
|
||||||
|
|
||||||
/* Clean the town pool and create 1 block in it */
|
/* Clean the town pool and create 1 block in it */
|
||||||
CleanPool(&_town_pool);
|
CleanPool(&_Town_pool);
|
||||||
AddBlockToPool(&_town_pool);
|
AddBlockToPool(&_Town_pool);
|
||||||
|
|
||||||
memset(_subsidies, 0, sizeof(_subsidies));
|
memset(_subsidies, 0, sizeof(_subsidies));
|
||||||
for (s=_subsidies; s != endof(_subsidies); s++)
|
for (s=_subsidies; s != endof(_subsidies); s++)
|
||||||
|
@ -1943,7 +1937,7 @@ static void Load_TOWN(void)
|
||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
Town *t;
|
Town *t;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_town_pool, index))
|
if (!AddBlockIfNeeded(&_Town_pool, index))
|
||||||
error("Towns: failed loading savegame: too many towns");
|
error("Towns: failed loading savegame: too many towns");
|
||||||
|
|
||||||
t = GetTown(index);
|
t = GetTown(index);
|
||||||
|
|
Loading…
Reference in New Issue