changeset 4984:b4542d8d8ea7 draft

(svn r6987) Use the pool macros for the Waypoint pool
author tron <tron@openttd.org>
date Sat, 28 Oct 2006 11:59:10 +0000
parents cf9a208e892e
children 556debce632a
files waypoint.c waypoint.h
diffstat 2 files changed, 10 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/waypoint.c
+++ b/waypoint.c
@@ -21,11 +21,7 @@
 #include "date.h"
 
 enum {
-	/* Max waypoints: 64000 (8 * 8000) */
-	WAYPOINT_POOL_BLOCK_SIZE_BITS = 3,       /* In bits, so (1 << 3) == 8 */
-	WAYPOINT_POOL_MAX_BLOCKS      = 8000,
-
-	MAX_WAYPOINTS_PER_TOWN        = 64,
+	MAX_WAYPOINTS_PER_TOWN = 64,
 };
 
 /**
@@ -37,11 +33,10 @@
 
 	/* 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 (wp = GetWaypoint(start_item); wp != NULL; wp = (wp->index + 1 < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1) : NULL) wp->index = start_item++;
+	for (wp = GetWaypoint(start_item); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) wp->index = start_item++;
 }
 
-/* Initialize the town-pool */
-MemoryPool _waypoint_pool = { "Waypoints", WAYPOINT_POOL_MAX_BLOCKS, WAYPOINT_POOL_BLOCK_SIZE_BITS, sizeof(Waypoint), &WaypointPoolNewBlock, NULL, 0, 0, NULL };
+DEFINE_POOL(Waypoint, Waypoint, WaypointPoolNewBlock, NULL)
 
 /* Create a new waypoint */
 static Waypoint* AllocateWaypoint(void)
@@ -50,7 +45,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 (wp = GetWaypoint(0); wp != NULL; wp = (wp->index + 1 < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1) : NULL) {
+	for (wp = GetWaypoint(0); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) {
 		if (!IsValidWaypoint(wp)) {
 			uint index = wp->index;
 
@@ -62,7 +57,7 @@
 	}
 
 	/* Check if we can add a block to the pool */
-	if (AddBlockToPool(&_waypoint_pool)) return AllocateWaypoint();
+	if (AddBlockToPool(&_Waypoint_pool)) return AllocateWaypoint();
 
 	return NULL;
 }
@@ -392,8 +387,8 @@
 
 void InitializeWaypoints(void)
 {
-	CleanPool(&_waypoint_pool);
-	AddBlockToPool(&_waypoint_pool);
+	CleanPool(&_Waypoint_pool);
+	AddBlockToPool(&_Waypoint_pool);
 }
 
 static const SaveLoad _waypoint_desc[] = {
@@ -429,7 +424,7 @@
 	while ((index = SlIterateArray()) != -1) {
 		Waypoint *wp;
 
-		if (!AddBlockIfNeeded(&_waypoint_pool, index))
+		if (!AddBlockIfNeeded(&_Waypoint_pool, index))
 			error("Waypoints: failed loading savegame: too many waypoints");
 
 		wp = GetWaypoint(index);
--- a/waypoint.h
+++ b/waypoint.h
@@ -24,23 +24,7 @@
 	byte deleted;      ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
 };
 
-extern MemoryPool _waypoint_pool;
-
-/**
- * Get the pointer to the waypoint with index 'index'
- */
-static inline Waypoint *GetWaypoint(WaypointID index)
-{
-	return (Waypoint*)GetItemFromPool(&_waypoint_pool, index);
-}
-
-/**
- * Get the current size of the WaypointPool
- */
-static inline uint16 GetWaypointPoolSize(void)
-{
-	return _waypoint_pool.total_items;
-}
+DECLARE_POOL(Waypoint, Waypoint, 3, 8000)
 
 /**
  * Check if a Waypoint really exists.
@@ -63,7 +47,7 @@
 	wp->xy = 0;
 }
 
-#define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = GetWaypoint(start); wp != NULL; wp = (wp->index + 1 < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1) : NULL) if (IsValidWaypoint(wp))
+#define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = GetWaypoint(start); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) if (IsValidWaypoint(wp))
 #define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0)