summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-10-28 11:55:29 +0000
committertron <tron@openttd.org>2006-10-28 11:55:29 +0000
commite397b721cda24507068a2028db58f28d7198fce9 (patch)
tree0353b720b14d64966c30ec3e7f905a9eecfa4aca
parent02ae75b380ee26b7c12837b28f753894522fb0a6 (diff)
downloadopenttd-e397b721cda24507068a2028db58f28d7198fce9.tar.xz
(svn r6986) Use the pool macros for the Town pool
-rw-r--r--oldloader.c2
-rw-r--r--openttd.c2
-rw-r--r--saveload.c2
-rw-r--r--town.h20
-rw-r--r--town_cmd.c20
5 files changed, 12 insertions, 34 deletions
diff --git a/oldloader.c b/oldloader.c
index 4bc40c2f0..ea447290d 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -483,7 +483,7 @@ static const OldChunks town_chunk[] = {
};
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");
return LoadChunk(ls, GetTown(num), town_chunk);
diff --git a/openttd.c b/openttd.c
index ef9e3a95b..6750c509b 100644
--- a/openttd.c
+++ b/openttd.c
@@ -254,7 +254,7 @@ static void InitializeDynamicVariables(void)
static void UnInitializeDynamicVariables(void)
{
/* Dynamic stuff needs to be free'd somewhere... */
- CleanPool(&_town_pool);
+ CleanPool(&_Town_pool);
CleanPool(&_Industry_pool);
CleanPool(&_Station_pool);
CleanPool(&_Vehicle_pool);
diff --git a/saveload.c b/saveload.c
index aeb8c5256..56de2a9be 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1258,7 +1258,7 @@ static void *IntToReference(uint index, SLRefType rt)
return GetStation(index);
}
case REF_TOWN: {
- if (!AddBlockIfNeeded(&_town_pool, index))
+ if (!AddBlockIfNeeded(&_Town_pool, index))
error("Towns: failed loading savegame: too many towns");
return GetTown(index);
}
diff --git a/town.h b/town.h
index 1e0c0b1bc..73155c855 100644
--- a/town.h
+++ b/town.h
@@ -152,7 +152,7 @@ bool CheckforTownRating(uint32 flags, Town *t, byte type);
VARDEF const Town** _town_sort;
-extern MemoryPool _town_pool;
+DECLARE_POOL(Town, Town, 3, 8000)
/**
* Check if a Town really exists.
@@ -162,22 +162,6 @@ static inline bool IsValidTown(const Town* town)
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;
static inline TownID GetTownArraySize(void)
@@ -225,7 +209,7 @@ static inline void DeleteTown(Town *t)
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)
VARDEF bool _town_sort_dirty;
diff --git a/town_cmd.c b/town_cmd.c
index 5ca064f9c..40cd13613 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -30,12 +30,6 @@
#include "table/town_land.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
*/
@@ -45,11 +39,11 @@ static void TownPoolNewBlock(uint start_item)
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* 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 */
-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)
{
@@ -985,7 +979,7 @@ static Town *AllocateTown(void)
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* 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)) {
TownID index = t->index;
@@ -999,7 +993,7 @@ static Town *AllocateTown(void)
}
/* Check if we can add a block to the pool */
- if (AddBlockToPool(&_town_pool))
+ if (AddBlockToPool(&_Town_pool))
return AllocateTown();
return NULL;
@@ -1830,8 +1824,8 @@ void InitializeTowns(void)
Subsidy *s;
/* Clean the town pool and create 1 block in it */
- CleanPool(&_town_pool);
- AddBlockToPool(&_town_pool);
+ CleanPool(&_Town_pool);
+ AddBlockToPool(&_Town_pool);
memset(_subsidies, 0, sizeof(_subsidies));
for (s=_subsidies; s != endof(_subsidies); s++)
@@ -1943,7 +1937,7 @@ static void Load_TOWN(void)
while ((index = SlIterateArray()) != -1) {
Town *t;
- if (!AddBlockIfNeeded(&_town_pool, index))
+ if (!AddBlockIfNeeded(&_Town_pool, index))
error("Towns: failed loading savegame: too many towns");
t = GetTown(index);