changeset 4983:cf9a208e892e draft

(svn r6986) Use the pool macros for the Town pool
author tron <tron@openttd.org>
date Sat, 28 Oct 2006 11:55:29 +0000
parents 15151db90095
children b4542d8d8ea7
files oldloader.c openttd.c saveload.c town.h town_cmd.c
diffstat 5 files changed, 12 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/oldloader.c
+++ b/oldloader.c
@@ -483,7 +483,7 @@
 };
 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);
--- a/openttd.c
+++ b/openttd.c
@@ -254,7 +254,7 @@
 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);
--- a/saveload.c
+++ b/saveload.c
@@ -1258,7 +1258,7 @@
 			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);
 		}
--- a/town.h
+++ b/town.h
@@ -152,7 +152,7 @@
 
 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 @@
 	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 @@
 	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;
--- 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 @@
 
 	/* 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 @@
 
 	/* 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 @@
 	}
 
 	/* 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 @@
 	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 @@
 	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);