(svn r6983) Use the pool macros for the Station pool
authortron
Sat, 28 Oct 2006 11:48:21 +0000
changeset 4980 1e1cb22b3d27
parent 4979 a85ffde44778
child 4981 44eeee2407f4
(svn r6983) Use the pool macros for the Station pool
oldloader.c
openttd.c
saveload.c
station.h
station_cmd.c
--- a/oldloader.c	Sat Oct 28 11:43:56 2006 +0000
+++ b/oldloader.c	Sat Oct 28 11:48:21 2006 +0000
@@ -635,7 +635,7 @@
 {
 	Station *st;
 
-	if (!AddBlockIfNeeded(&_station_pool, num))
+	if (!AddBlockIfNeeded(&_Station_pool, num))
 		error("Stations: failed loading savegame: too many stations");
 
 	st = GetStation(num);
--- a/openttd.c	Sat Oct 28 11:43:56 2006 +0000
+++ b/openttd.c	Sat Oct 28 11:48:21 2006 +0000
@@ -256,7 +256,7 @@
 	/* Dynamic stuff needs to be free'd somewhere... */
 	CleanPool(&_town_pool);
 	CleanPool(&_Industry_pool);
-	CleanPool(&_station_pool);
+	CleanPool(&_Station_pool);
 	CleanPool(&_Vehicle_pool);
 	CleanPool(&_Sign_pool);
 	CleanPool(&_Order_pool);
--- a/saveload.c	Sat Oct 28 11:43:56 2006 +0000
+++ b/saveload.c	Sat Oct 28 11:48:21 2006 +0000
@@ -1253,7 +1253,7 @@
 			return GetVehicle(index);
 		}
 		case REF_STATION: {
-			if (!AddBlockIfNeeded(&_station_pool, index))
+			if (!AddBlockIfNeeded(&_Station_pool, index))
 				error("Stations: failed loading savegame: too many stations");
 			return GetStation(index);
 		}
--- a/station.h	Sat Oct 28 11:43:56 2006 +0000
+++ b/station.h	Sat Oct 28 11:48:21 2006 +0000
@@ -142,23 +142,7 @@
 void RebuildStationLists(void);
 void ResortStationLists(void);
 
-extern MemoryPool _station_pool;
-
-/**
- * Get the pointer to the station with index 'index'
- */
-static inline Station *GetStation(StationID index)
-{
-	return (Station*)GetItemFromPool(&_station_pool, index);
-}
-
-/**
- * Get the current size of the StationPool
- */
-static inline uint16 GetStationPoolSize(void)
-{
-	return _station_pool.total_items;
-}
+DECLARE_POOL(Station, Station, 6, 1000)
 
 static inline StationID GetStationArraySize(void)
 {
@@ -191,7 +175,7 @@
 	st->xy = 0;
 }
 
-#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) if (IsValidStation(st))
+#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (IsValidStation(st))
 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
 
 
--- a/station_cmd.c	Sat Oct 28 11:43:56 2006 +0000
+++ b/station_cmd.c	Sat Oct 28 11:48:21 2006 +0000
@@ -34,10 +34,6 @@
 #include "date.h"
 
 enum {
-	/* Max stations: 64000 (64 * 1000) */
-	STATION_POOL_BLOCK_SIZE_BITS = 6,       /* In bits, so (1 << 6) == 64 */
-	STATION_POOL_MAX_BLOCKS      = 1000,
-
 	/* Max roadstops: 64000 (32 * 2000) */
 	ROADSTOP_POOL_BLOCK_SIZE_BITS = 5,       /* In bits, so (1 << 5) == 32 */
 	ROADSTOP_POOL_MAX_BLOCKS      = 2000,
@@ -52,7 +48,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 (st = GetStation(start_item); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) st->index = start_item++;
+	for (st = GetStation(start_item); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) st->index = start_item++;
 }
 
 static void StationPoolCleanBlock(uint start_item, uint end_item)
@@ -78,8 +74,7 @@
 	for (rs = GetRoadStop(start_item); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) rs->index = start_item++;
 }
 
-/* Initialize the station-pool and roadstop-pool */
-MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, &StationPoolCleanBlock, 0, 0, NULL };
+DEFINE_POOL(Station, Station, StationPoolNewBlock, StationPoolCleanBlock)
 MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, NULL, 0, 0, NULL };
 
 
@@ -282,7 +277,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 (st = GetStation(0); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) {
+	for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) {
 		if (!IsValidStation(st)) {
 			StationID index = st->index;
 
@@ -294,7 +289,7 @@
 	}
 
 	/* Check if we can add a block to the pool */
-	if (AddBlockToPool(&_station_pool)) return AllocateStation();
+	if (AddBlockToPool(&_Station_pool)) return AllocateStation();
 
 	_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
 	return NULL;
@@ -2880,8 +2875,8 @@
 void InitializeStations(void)
 {
 	/* Clean the station pool and create 1 block in it */
-	CleanPool(&_station_pool);
-	AddBlockToPool(&_station_pool);
+	CleanPool(&_Station_pool);
+	AddBlockToPool(&_Station_pool);
 
 	/* Clean the roadstop pool and create 1 block in it */
 	CleanPool(&_roadstop_pool);
@@ -3061,7 +3056,7 @@
 	while ((index = SlIterateArray()) != -1) {
 		Station *st;
 
-		if (!AddBlockIfNeeded(&_station_pool, index))
+		if (!AddBlockIfNeeded(&_Station_pool, index))
 			error("Stations: failed loading savegame: too many stations");
 
 		st = GetStation(index);