mirror of https://github.com/OpenTTD/OpenTTD
(svn r6987) Use the pool macros for the Waypoint pool
parent
e397b721cd
commit
97cc0fcdd4
21
waypoint.c
21
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);
|
||||
|
|
20
waypoint.h
20
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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue