summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-10-28 11:59:10 +0000
committertron <tron@openttd.org>2006-10-28 11:59:10 +0000
commit97cc0fcdd48431707e28e677c43f856e9f2caae2 (patch)
treeda124f7555cdb90b1b0ed0f0796b95df3e49750f
parente397b721cda24507068a2028db58f28d7198fce9 (diff)
downloadopenttd-97cc0fcdd48431707e28e677c43f856e9f2caae2.tar.xz
(svn r6987) Use the pool macros for the Waypoint pool
-rw-r--r--waypoint.c21
-rw-r--r--waypoint.h20
2 files changed, 10 insertions, 31 deletions
diff --git a/waypoint.c b/waypoint.c
index 7a995e359..cb3195e5f 100644
--- 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 @@ static void WaypointPoolNewBlock(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 (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 @@ static Waypoint* AllocateWaypoint(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 (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 @@ static Waypoint* AllocateWaypoint(void)
}
/* 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 FixOldWaypoints(void)
void InitializeWaypoints(void)
{
- CleanPool(&_waypoint_pool);
- AddBlockToPool(&_waypoint_pool);
+ CleanPool(&_Waypoint_pool);
+ AddBlockToPool(&_Waypoint_pool);
}
static const SaveLoad _waypoint_desc[] = {
@@ -429,7 +424,7 @@ static void Load_WAYP(void)
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);
diff --git a/waypoint.h b/waypoint.h
index da3106656..59ffa84ad 100644
--- a/waypoint.h
+++ b/waypoint.h
@@ -24,23 +24,7 @@ struct Waypoint {
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 @@ static inline void DeleteWaypoint(Waypoint *wp)
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)